?? ftpconnectionpanel.java
字號:
/*
* Copyright (C) The Apache Software Foundation. All rights reserved.
*
* This software is published under the terms of the Apache Software License
* version 1.1, a copy of which has been included with this distribution in
* the LICENSE file.
*/
package server.ftp.gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.tree.TreePath;
import gui.GuiUtils;
import server.ftp.FtpConfig;
import server.ftp.FtpUser;
/**
* This panel displays all the logged in users.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
class FtpConnectionPanel extends PluginPanel {
private JTable mjConnectionTable;
private FtpConfig mConfig;
private FtpConnectionTableModel mModel;
/**
* Instantiate login panel.
*/
public FtpConnectionPanel(FtpTree tree) {
super(tree);
mModel = new FtpConnectionTableModel();
initComponents();
}
/**
* Initialize UI components
*/
private void initComponents() {
setLayout(new BorderLayout());
mjConnectionTable = new JTable(mModel);
mjConnectionTable.setPreferredScrollableViewportSize(new Dimension(470, 320));
mjConnectionTable.setColumnSelectionAllowed(false);
JScrollPane bottomPane = new JScrollPane(mjConnectionTable,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(bottomPane, BorderLayout.CENTER);
// buttons
JPanel btnPane = new JPanel();
btnPane.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton jLogoutBtn = new JButton("Disconnect");
btnPane.add(jLogoutBtn);
JButton jSpyBtn = new JButton("Spy User");
btnPane.add(jSpyBtn);
JButton jReloadBtn = new JButton("Reload");
btnPane.add(jReloadBtn);
add(btnPane, BorderLayout.SOUTH);
// event handlers
jLogoutBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
closeConnection();
}
});
jSpyBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
spyUser();
}
});
jReloadBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
refresh(mConfig);
}
});
}
/**
* Logout this user
*/
private void closeConnection() {
int indices[] = mjConnectionTable.getSelectedRows();
if(indices.length == 0) {
GuiUtils.showErrorMessage(getTree().getRootPanel(), "Please select connection(s).");
return;
}
boolean response = GuiUtils.getConfirmation(getTree().getRootPanel(), "Do you really want to close the selected connection(s)?");
if(!response) {
return;
}
for(int i=indices.length; --i>=0; ) {
FtpUser user = mModel.getUser(indices[i]);
if(user != null) {
mConfig.getConnectionService().closeConnection(user.getSessionId());
}
}
}
/**
* Monitor the selected user.
*/
private void spyUser() {
int indices[] = mjConnectionTable.getSelectedRows();
if(indices.length == 0) {
GuiUtils.showErrorMessage(getTree().getRootPanel(), "Please select connection(s).");
return;
}
// monitor all the selected users
for(int i=indices.length; --i>=0; ) {
FtpUser thisUser = mModel.getUser(indices[i]);
if (thisUser != null) {
FtpSpyContainerPanel spyPanel = (FtpSpyContainerPanel)getTree().getPluginPanel("Spy");
spyPanel.monitorConnection(thisUser);
}
}
// select tree spy node
Object[] spyPath = new Object[] {
getTree().getRoot(), "Spy"
};
getTree().setSelectionPath(new TreePath(spyPath));
}
/**
* Refresh window.
*/
public void refresh(FtpConfig cfg) {
mConfig = cfg;
if (cfg != null) {
mModel.refresh(mConfig);
}
}
/**
* Is displayable
*/
public boolean isDisplayable() {
return mConfig != null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -