📄 usermanagerpanel.java
字号:
// $Id: UserManagerPanel.java 306698 2005-09-07 05:06:22Z rana_b $
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ftpserver.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Iterator;
import java.util.Random;
import org.apache.ftpserver.ftplet.FtpException;
import org.apache.ftpserver.ftplet.User;
import org.apache.ftpserver.ftplet.UserManager;
import org.apache.ftpserver.interfaces.IFtpConfig;
import org.apache.ftpserver.usermanager.BaseUser;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
/**
* User management panel.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class UserManagerPanel extends PluginPanel implements ActionListener {
private static final long serialVersionUID = 2496923918460548623L;
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 IFtpConfig m_fconfig;
private JComboBox m_userLst;
private JTextField m_nameTxt;
private JPasswordField m_passwordTxt;
private JPasswordField m_retypePasswordTxt;
private JCheckBox m_passwordChkBox;
private JTextField m_directoryTxt;
private JCheckBox m_enabledChkBox;
private JCheckBox m_writeChkBox;
private JComboBox m_idleLst;
private JComboBox m_uploadLst;
private JComboBox m_downloadLst;
/**
* Constructor - create all UI components.
*/
public UserManagerPanel(PluginPanelContainer container) {
super(container);
initComponents();
}
/**
* Initial all UI components.
*/
private void initComponents() {
setLayout(new BorderLayout());
JPanel topPanel = new JPanel(new GridBagLayout());
topPanel.setBorder(BorderFactory.createEtchedBorder());
GridBagConstraints gc = new GridBagConstraints();
gc.insets = new Insets(4, 0, 0, 5);
add(topPanel, BorderLayout.CENTER);
int yindex = -1;
// user list
m_userLst = new JComboBox();
m_userLst.addActionListener(this);
m_userLst.setPreferredSize(new Dimension(120, 22));
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 3;
gc.anchor = GridBagConstraints.CENTER;
topPanel.add(m_userLst, gc);
// user name
JLabel nameLab = new JLabel("Name :: ");
nameLab.setHorizontalAlignment(JLabel.RIGHT);
nameLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(nameLab, gc);
m_nameTxt = new JTextField();
m_nameTxt.setColumns(12);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_nameTxt, gc);
// password
JLabel passwordLab = new JLabel("Password :: ");
passwordLab.setHorizontalAlignment(JLabel.RIGHT);
passwordLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(passwordLab, gc);
m_passwordTxt = new JPasswordField();
m_passwordTxt.setColumns(12);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_passwordTxt, gc);
JButton generatePassBtn = new JButton("Generate");
generatePassBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
generatePassword();
}
});
generatePassBtn.setPreferredSize(new Dimension(90, 22));
gc.gridx = 2;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(generatePassBtn, gc);
// retype password
JLabel retypePasswordLab = new JLabel("Retype Password :: ");
retypePasswordLab.setHorizontalAlignment(JLabel.RIGHT);
retypePasswordLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(retypePasswordLab, gc);
m_retypePasswordTxt = new JPasswordField();
m_retypePasswordTxt.setColumns(12);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_retypePasswordTxt, gc);
// set password
JLabel setPasswordLab = new JLabel("Set Password :: ");
setPasswordLab.setHorizontalAlignment(JLabel.RIGHT);
setPasswordLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(setPasswordLab, gc);
m_passwordChkBox = new JCheckBox();
m_passwordChkBox.setHorizontalTextPosition(SwingConstants.LEFT);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_passwordChkBox, gc);
// root directory
JLabel directoryLab = new JLabel("Root Directory :: ");
directoryLab.setHorizontalAlignment(JLabel.RIGHT);
directoryLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(directoryLab, gc);
m_directoryTxt = new JTextField("./res/home");
m_directoryTxt.setColumns(12);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_directoryTxt, gc);
JButton directoryBtn = new JButton("Browse");
directoryBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
String dir = DirChooser.showDialog(UserManagerPanel.this, "Select User Home", null);
if(dir != null) {
m_directoryTxt.setText(dir);
}
}
});
directoryBtn.setPreferredSize(new Dimension(90, 22));
gc.gridx = 2;
gc.gridy = yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(directoryBtn, gc);
// enable/disable
JLabel enabledLab = new JLabel("Enabled :: ");
enabledLab.setHorizontalAlignment(JLabel.RIGHT);
enabledLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(enabledLab, gc);
m_enabledChkBox = new JCheckBox();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_enabledChkBox, gc);
// write permission
JLabel writePermLab = new JLabel("Write Permission :: ");
writePermLab.setHorizontalAlignment(JLabel.RIGHT);
writePermLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(writePermLab, gc);
m_writeChkBox = new JCheckBox();
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_writeChkBox, gc);
// idle time
JLabel idleLab = new JLabel("Max. Idle Time (seconds) :: ");
idleLab.setHorizontalAlignment(JLabel.RIGHT);
idleLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(idleLab, gc);
m_idleLst = new JComboBox(IDLE_SECONDS);
m_idleLst.setPreferredSize(new Dimension(130, 22));
m_idleLst.setEditable(true);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_idleLst, gc);
// user upload limit
JLabel uploadLab = new JLabel("Max. Upload (bytes/sec) :: ");
uploadLab.setHorizontalAlignment(JLabel.RIGHT);
uploadLab.setForeground(Color.black);
gc.gridx = 0;
gc.gridy = ++yindex;
gc.gridwidth = 1;
gc.anchor = GridBagConstraints.EAST;
topPanel.add(uploadLab, gc);
m_uploadLst = new JComboBox(BYTE_RATES);
m_uploadLst.setPreferredSize(new Dimension(130, 22));
m_uploadLst.setEditable(true);
gc.gridx = 1;
gc.gridy = yindex;
gc.gridwidth = 2;
gc.anchor = GridBagConstraints.WEST;
topPanel.add(m_uploadLst, gc);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -