📄 ftpuserpanel.java
字号:
package ranab.server.ftp.gui;
import java.util.Random;
import java.util.Iterator;
import java.io.File;
import java.awt.Color;
import java.awt.Insets;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import javax.swing.SwingConstants;
import ranab.io.LogFile;
import ranab.gui.GuiUtils;
import ranab.server.ftp.FtpConfig;
import ranab.server.ftp.FtpUser;
import ranab.server.ftp.usermanager.User;
/**
* Ftp server user admin panel.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpUserPanel extends PluginPanel
implements ActionListener {
private final static Random PASS_GEN = new Random(System.currentTimeMillis());
private final static Object[] BYTE_RATES = {
"No limit",
new Integer(1200),
new Integer(2400),
new Integer(4800),
new Integer(9600),
new Integer(14400),
new Integer(28800),
new Integer(57600),
new Integer(115200)
};
private final static Object[] IDLE_SECONDS = {
"No limit",
new Integer(60),
new Integer(300),
new Integer(900),
new Integer(1800),
new Integer(3600)
};
private FtpConfig mConfig;
private JComboBox mjUserLst;
private JTextField mjNameTxt;
private JPasswordField mjPasswordTxt;
private JPasswordField mjRetypePasswordTxt;
private JCheckBox mjPasswordChkBox;
private JTextField mjDirectoryTxt;
private JCheckBox mjEnabledChkBox;
private JCheckBox mjWriteChkBox;
private JComboBox mjIdleLst;
private JComboBox mjUploadLst;
private JComboBox mjDownloadLst;
/**
* Creates new panel.
*/
public FtpUserPanel(FtpTree tree) {
super(tree);
initComponents();
}
/**
* This method is called from within the constructor to
* initialize the form.
*/
private void initComponents() {
GridBagConstraints gc;
setLayout(new GridBagLayout());
int yindex = -1;
// user list
mjUserLst = new JComboBox();
mjUserLst.addActionListener(this);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 3;
gc.insets = new Insets(3, 0, 0, 3);
add(mjUserLst, gc);
// user name
JLabel jNameLab = new JLabel("Name");
jNameLab.setHorizontalAlignment(JLabel.RIGHT);
jNameLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jNameLab, gc);
mjNameTxt = new JTextField();
mjNameTxt.setColumns(12);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjNameTxt, gc);
// password
JLabel jPasswordLab = new JLabel("Password");
jPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jPasswordLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jPasswordLab, gc);
mjPasswordTxt = new JPasswordField();
mjPasswordTxt.setColumns(12);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjPasswordTxt, gc);
JButton jGeneratePassBtn = new JButton("Generate");
jGeneratePassBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
generatePassword();
}
});
gc = new GridBagConstraints();
gc.gridx = 2;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(jGeneratePassBtn, gc);
// retype password
JLabel jRetypePasswordLab = new JLabel("Retype Password");
jRetypePasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jRetypePasswordLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jRetypePasswordLab, gc);
mjRetypePasswordTxt = new JPasswordField();
mjRetypePasswordTxt.setColumns(12);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjRetypePasswordTxt, gc);
// set password
JLabel jSetPasswordLab = new JLabel("Set Password");
jSetPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
jSetPasswordLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jSetPasswordLab, gc);
mjPasswordChkBox = new JCheckBox();
mjPasswordChkBox.setHorizontalTextPosition(SwingConstants.LEFT);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjPasswordChkBox, gc);
// root directory
JLabel jDirectoryLab = new JLabel("Root Directory");
jDirectoryLab.setHorizontalAlignment(JLabel.RIGHT);
jDirectoryLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
gc.insets = new Insets(3, 0, 0, 3);
add(jDirectoryLab, gc);
mjDirectoryTxt = new JTextField();
mjDirectoryTxt.setColumns(12);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
gc.insets = new Insets(3, 0, 0, 3);
add(mjDirectoryTxt, gc);
JButton jDirectoryBtn = new JButton("Browse");
jDirectoryBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
browse(evt);
}
});
gc = new GridBagConstraints();
gc.gridx = 2;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(jDirectoryBtn, gc);
// enable/disable
JLabel jEnabledLab = new JLabel("Enabled");
jEnabledLab.setHorizontalAlignment(JLabel.RIGHT);
jEnabledLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jEnabledLab, gc);
mjEnabledChkBox = new JCheckBox();
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjEnabledChkBox, gc);
// write permission
JLabel jWritePermLab = new JLabel("Write Permission");
jWritePermLab.setHorizontalAlignment(JLabel.RIGHT);
jWritePermLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jWritePermLab, gc);
mjWriteChkBox = new JCheckBox();
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjWriteChkBox, gc);
// idle time
JLabel jIdleLab = new JLabel("Max. Idle Time (seconds)");
jIdleLab.setHorizontalAlignment(JLabel.RIGHT);
jIdleLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jIdleLab, gc);
mjIdleLst = new JComboBox(IDLE_SECONDS);
mjIdleLst.setEditable(true);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjIdleLst, gc);
// user upload limit
JLabel jUploadLab = new JLabel("Max. Upload (bytes/sec)");
jUploadLab.setHorizontalAlignment(JLabel.RIGHT);
jUploadLab.setForeground(Color.black);
gc = new GridBagConstraints();
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.EAST;
add(jUploadLab, gc);
mjUploadLst = new JComboBox(BYTE_RATES);
mjUploadLst.setEditable(true);
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.insets = new Insets(3, 0, 0, 3);
gc.anchor = GridBagConstraints.WEST;
add(mjUploadLst, gc);
// user download limit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -