You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ra...@apache.org on 2002/03/31 18:52:44 UTC
cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui spy.html PluginPanel.java FtpTree.java FtpSpyContainerPanel.java SpyPanel.java FtpUserPanel.java FtpStatisticsPanel.java FtpRootPanel.java FtpIpPanel.java FtpFilePanel.java FtpConnectionTableModel.java FtpConnectionPanel.java FtpAdminFrame.java FtpAdmin.java FtpAboutPanel.java about.html
rana_b 02/03/31 08:52:44
Modified: ftpserver/src/java/org/apache/avalon/ftpserver/gui
SpyPanel.java FtpUserPanel.java
FtpStatisticsPanel.java FtpRootPanel.java
FtpIpPanel.java FtpFilePanel.java
FtpConnectionTableModel.java
FtpConnectionPanel.java FtpAdminFrame.java
FtpAdmin.java FtpAboutPanel.java about.html
Added: ftpserver/src/java/org/apache/avalon/ftpserver/gui spy.html
PluginPanel.java FtpTree.java
FtpSpyContainerPanel.java
Log:
structure changed - using plugin panels to add panels easier
Revision Changes Path
1.2 +20 -5 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/SpyPanel.java
Index: SpyPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/SpyPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SpyPanel.java 6 Mar 2002 13:53:20 -0000 1.1
+++ SpyPanel.java 31 Mar 2002 16:52:43 -0000 1.2
@@ -41,7 +41,7 @@
mCommonHandler = commonHandler;
initComponents();
- mSpyAdapter = new SpyConnectionAdapter(mCommonHandler.getConnectionService(), mUser.getSessionId(), this);
+ mSpyAdapter = new SpyConnectionAdapter(commonHandler.getConnectionService(), mUser.getSessionId(), this);
}
/**
@@ -64,14 +64,28 @@
return mUser;
}
+ /**
+ * Get connection session id.
+ */
+ public String getSessionId() {
+ return mUser.getSessionId();
+ }
+
/**
- * Write message
+ * Write server response.
*/
- public void write(String msg) {
+ public void response(String msg) {
mLogTxt.append(msg);
}
/**
+ * Write user request.
+ */
+ public void request(String msg) {
+ mLogTxt.append(msg);
+ }
+
+ /**
* Clear log messages
*/
public void clearLog() {
@@ -81,7 +95,7 @@
/**
* Close pane
*/
- public void closePane() {
+ public void close() {
mSpyAdapter.close();
mLogTxt.setText("");
}
@@ -99,4 +113,5 @@
}
}
-}
\ No newline at end of file
+}
+
1.11 +23 -38 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java
Index: FtpUserPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpUserPanel.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FtpUserPanel.java 6 Mar 2002 13:53:20 -0000 1.10
+++ FtpUserPanel.java 31 Mar 2002 16:52:43 -0000 1.11
@@ -33,7 +33,7 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpUserPanel extends JPanel
+class FtpUserPanel extends PluginPanel
implements ActionListener {
private final static Random PASS_GEN = new Random(System.currentTimeMillis());
@@ -75,17 +75,13 @@
private JComboBox mjUploadLst;
private JComboBox mjDownloadLst;
- private FtpUserPanel mSelf;
-
- private CommonHandler mCommonHandler;
-
/**
* Creates new panel.
*/
- public FtpUserPanel(CommonHandler commonHandler) {
- mCommonHandler = commonHandler;
- mUserManager = mCommonHandler.getUserManager();
- initComponents ();
+ public FtpUserPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
+ mUserManager = commonHandler.getUserManager();
+ initComponents();
refresh();
}
@@ -386,7 +382,7 @@
// check user name field
String userName = mjNameTxt.getText().trim();
if(userName.equals("")) {
- GuiUtils.showErrorMessage(mCommonHandler.getTopComponent(), "Please enter an user name");
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Please enter an user name");
return;
}
@@ -405,7 +401,7 @@
}
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -420,7 +416,7 @@
}
String userName = selVal.toString();
- boolean bConf = GuiUtils.getConfirmation(mCommonHandler.getTopComponent(), "Do you really want to delete user " + userName + "?");
+ boolean bConf = GuiUtils.getConfirmation(getCommonHandler().getTopComponent(), "Do you really want to delete user " + userName + "?");
if(!bConf) {
return;
}
@@ -429,7 +425,7 @@
refresh();
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -445,7 +441,7 @@
}
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -464,7 +460,7 @@
}
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -510,7 +506,7 @@
}
}
String password = sb.toString();
- GuiUtils.showInformationMessage(mSelf, "Generated password: " + password);
+ GuiUtils.showInformationMessage(getCommonHandler().getTopComponent(), "Generated password: " + password);
mjPasswordTxt.setText(password);
mjRetypePasswordTxt.setText(password);
mjPasswordChkBox.setSelected(true);
@@ -531,13 +527,13 @@
// new user
if( bNewUser && (!bPassSet) && (!usr.getIsAnonymous()) ) {
- GuiUtils.showErrorMessage(mSelf, "New user - password required");
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "New user - password required");
return false;
}
// password set
if( bPassSet && (!password.equals(repassword)) && (!usr.getIsAnonymous()) ) {
- GuiUtils.showErrorMessage(mSelf, "Password entries are not equal");
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Password entries are not equal");
return false;
}
@@ -551,7 +547,7 @@
return true;
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
return false;
}
@@ -567,7 +563,7 @@
rate = Integer.parseInt(selObj.toString());
}
catch(NumberFormatException ex) {
- GuiUtils.showErrorMessage(mSelf, ex.getMessage());
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), ex.getMessage());
}
}
@@ -585,7 +581,7 @@
sec = Integer.parseInt(selObj.toString());
}
catch(NumberFormatException ex) {
- GuiUtils.showErrorMessage(mSelf, ex.getMessage());
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), ex.getMessage());
}
}
@@ -596,17 +592,11 @@
* Set byte transfer rate combo.
*/
private void setByteRateCombo(JComboBox combo, int rate) {
- int index = 0;
- if(rate != 0) {
- Integer currRate = new Integer(rate);
- for(int i=1; i<BYTE_RATES.length; i++) {
- if(BYTE_RATES[i].equals(currRate)) {
- index = i;
- break;
- }
- }
+ Object selItem = new Integer(rate);
+ if (rate == 0) {
+ selItem = BYTE_RATES[0];
}
- combo.setSelectedIndex(index);
+ combo.setSelectedItem(selItem);
}
/**
@@ -619,10 +609,5 @@
}
mjIdleLst.setSelectedItem(selItem);
}
-
- /**
- * Close all resources.
- */
- public void close() {
- }
-}
\ No newline at end of file
+
+}
1.9 +23 -22 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java
Index: FtpStatisticsPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpStatisticsPanel.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FtpStatisticsPanel.java 6 Mar 2002 13:53:20 -0000 1.8
+++ FtpStatisticsPanel.java 31 Mar 2002 16:52:43 -0000 1.9
@@ -27,9 +27,8 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpStatisticsPanel extends JPanel
- implements FtpStatisticsListener,
- FtpFileListener {
+class FtpStatisticsPanel extends PluginPanel
+ implements FtpStatisticsListener, FtpFileListener {
private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
@@ -54,7 +53,6 @@
private FtpFileTableModel mDownloadModel;
private FtpFileTableModel mDeleteModel;
- private CommonHandler mCommonHandler;
private FtpStatisticsInterface mStat;
private FtpFileListenerAdapter mFileListener;
@@ -63,20 +61,24 @@
/**
* Creates new panel to display ftp global statistics.
*/
- public FtpStatisticsPanel(CommonHandler commonHandler) throws RemoteException {
- mCommonHandler = commonHandler;
- mStat = mCommonHandler.getStatistics();
+ public FtpStatisticsPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
+ mStat = commonHandler.getStatistics();
mUploadModel = new FtpFileTableModel();
mDownloadModel = new FtpFileTableModel();
mDeleteModel = new FtpFileTableModel();
initComponents();
- mFileListener = new FtpFileListenerAdapter(mStat, this);
- mListener = new FtpStatisticsListenerAdapter(mStat, this);
-
- reload();
- mjStartTimeTxt.setText(DATE_FMT.format(mStat.getStartTime()));
+ try {
+ mFileListener = new FtpFileListenerAdapter(mStat, this);
+ mListener = new FtpStatisticsListenerAdapter(mStat, this);
+ reload();
+ mjStartTimeTxt.setText(DATE_FMT.format(mStat.getStartTime()));
+ }
+ catch(Exception ex) {
+ commonHandler.handleException(ex);
+ }
}
/**
@@ -402,7 +404,6 @@
return mDeleteModel;
}
-
/**
* Upload notification.
*/
@@ -412,7 +413,7 @@
mjUploadBytesTxt.setText(String.valueOf(mStat.getFileUploadSize()));
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -425,7 +426,7 @@
mjDownloadBytesTxt.setText(String.valueOf(mStat.getFileDownloadSize()));
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -438,7 +439,7 @@
mjDeleteNbrTxt.setText(String.valueOf(mStat.getFileDeleteNbr()));
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -453,7 +454,7 @@
mjTotalAnonLoginNbrTxt.setText(String.valueOf(mStat.getTotalAnonLoginNbr()));
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -473,7 +474,7 @@
mjTotalConNbrTxt.setText(String.valueOf(mStat.getTotalConnectionNbr()));
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -481,7 +482,7 @@
* Notify file upload
*/
public void notifyUpload(final String fl, final String sessId) {
- FtpUser user = mCommonHandler.getUser(sessId);
+ FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mUploadModel.newEntry(fl, user);
}
@@ -491,7 +492,7 @@
* Notify file download
*/
public void notifyDownload(final String fl, final String sessId) {
- FtpUser user = mCommonHandler.getUser(sessId);
+ FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mDownloadModel.newEntry(fl, user);
}
@@ -501,7 +502,7 @@
* Notify file delete
*/
public void notifyDelete(final String fl, final String sessId) {
- FtpUser user = mCommonHandler.getUser(sessId);
+ FtpUser user = getCommonHandler().getUser(sessId);
if (user != null) {
mDeleteModel.newEntry(fl, user);
}
@@ -528,4 +529,4 @@
mFileListener.close();
}
-}
\ No newline at end of file
+}
1.9 +13 -100 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpRootPanel.java
Index: FtpRootPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpRootPanel.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- FtpRootPanel.java 8 Mar 2002 06:27:30 -0000 1.8
+++ FtpRootPanel.java 31 Mar 2002 16:52:43 -0000 1.9
@@ -18,32 +18,25 @@
* FTP user interface root panel. We can view comfig parameters
* using this panel.
*
- * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
+ * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
-class FtpRootPanel extends JPanel {
+class FtpRootPanel extends PluginPanel {
private JTextField mjHostTxt = null;
- private JTable mjCfgTbl = null;
-
- private FtpUserPanel mUserPane = null;
- private FtpConnectionPanel mConnectionPane = null;
- private FtpIpPanel mIpPane = null;
- private FtpStatisticsPanel mStatPane = null;
- private FtpFilePanel mUploadPane = null;
- private FtpFilePanel mDownloadPane = null;
- private FtpFilePanel mDeletePane = null;
- private FtpAboutPanel mAboutPanel = null;
-
- private CommonHandler mCommonHandler = null;
-
+ private JTable mjCfgTbl = null;
/**
* Creates new panel for root.
*/
- public FtpRootPanel(CommonHandler commonHandler) throws RemoteException {
- mCommonHandler = commonHandler;
- initComponents ();
+ public FtpRootPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
+ try {
+ initComponents ();
+ }
+ catch(Exception ex) {
+ commonHandler.handleException(ex);
+ }
}
/**
@@ -70,7 +63,7 @@
mjHostTxt = new JTextField();
mjHostTxt.setColumns(15);
mjHostTxt.setEditable(false);
- mjHostTxt.setText(mCommonHandler.getConfig().getAddressString());
+ mjHostTxt.setText(getCommonHandler().getConfig().getAddressString());
gc = new GridBagConstraints();
gc.gridx = 1;
gc.gridy = 0;
@@ -91,7 +84,7 @@
// bottom panel - display config parameters
- ConfigTableModel cfgModel = new ConfigTableModel(mCommonHandler);
+ ConfigTableModel cfgModel = new ConfigTableModel(getCommonHandler());
mjCfgTbl = new JTable(cfgModel);
mjCfgTbl.setPreferredScrollableViewportSize(new Dimension(420, 200));
mjCfgTbl.setColumnSelectionAllowed(false);
@@ -100,86 +93,6 @@
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
add(bottomPane, BorderLayout.CENTER);
-
- // create other panels
- mUserPane = new FtpUserPanel(mCommonHandler);
- mConnectionPane = new FtpConnectionPanel(mCommonHandler);
- mIpPane = new FtpIpPanel(mCommonHandler);
- mStatPane = new FtpStatisticsPanel(mCommonHandler);
- mUploadPane = new FtpFilePanel(mStatPane.getUploadModel(), "Uploaded Files");
- mDownloadPane = new FtpFilePanel(mStatPane.getDownloadModel(), "Downloaded Files");
- mDeletePane = new FtpFilePanel(mStatPane.getDeleteModel(), "Deleted Files");
- mAboutPanel = new FtpAboutPanel();
- }
-
- /**
- * Get user panel.
- */
- public JPanel getUserPanel() {
- return mUserPane;
- }
-
- /**
- * Get login panel.
- */
- public JPanel getConnectionPanel() {
- return mConnectionPane;
- }
-
- /**
- * Get IP panel.
- */
- public JPanel getIpPanel() {
- return mIpPane;
- }
-
- /**
- * Get statistics panel
- */
- public JPanel getStatisticsPanel() {
- return mStatPane;
- }
-
- /**
- * Get uploaded file panel
- */
- public JPanel getUploadPanel() {
- return mUploadPane;
- }
-
- /**
- * Get downloaded file panel
- */
- public JPanel getDownloadPanel() {
- return mDownloadPane;
- }
-
- /**
- * Get deleted file panel
- */
- public JPanel getDeletePanel() {
- return mDeletePane;
- }
-
- /**
- * Get ftp server about panel.
- */
- public JPanel getAboutPanel() {
- return mAboutPanel;
}
-
- /**
- * Close the resources.
- */
- public void close() {
- mStatPane.close();
- mConnectionPane.close();
- mUserPane.close();
- mIpPane.close();
- mUploadPane.close();
- mDownloadPane.close();
- mDeletePane.close();
- mAboutPanel.close();
- }
}
1.8 +8 -15 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpIpPanel.java
Index: FtpIpPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpIpPanel.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- FtpIpPanel.java 6 Mar 2002 13:53:20 -0000 1.7
+++ FtpIpPanel.java 31 Mar 2002 16:52:43 -0000 1.8
@@ -22,19 +22,17 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpIpPanel extends JPanel {
+class FtpIpPanel extends PluginPanel {
private JTextArea mjIpTxt;
- private IpRestrictorInterface mRestrictor;
- private CommonHandler mCommonHandler;
- private FtpIpPanel mSelf;
+ private IpRestrictorInterface mRestrictor;
/**
* Instantiate IP restrictor panel
*/
- public FtpIpPanel(CommonHandler commonHandler) {
- mCommonHandler = commonHandler;
- mRestrictor = mCommonHandler.getIpRestrictor();
+ public FtpIpPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
+ mRestrictor = commonHandler.getIpRestrictor();
initComponents();
refresh();
}
@@ -63,7 +61,7 @@
JButton jSaveBtn = new JButton("Save");
btnPane.add(jSaveBtn);
- JButton jResetBtn = new JButton("Reset");
+ JButton jResetBtn = new JButton("Reload");
btnPane.add(jResetBtn);
add(btnPane, BorderLayout.SOUTH);
@@ -96,7 +94,7 @@
mRestrictor.save();
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
}
@@ -114,13 +112,8 @@
}
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
- /**
- * Close resource
- */
- public void close() {
- }
}
1.2 +7 -6 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpFilePanel.java
Index: FtpFilePanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpFilePanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpFilePanel.java 6 Mar 2002 13:53:20 -0000 1.1
+++ FtpFilePanel.java 31 Mar 2002 16:52:43 -0000 1.2
@@ -15,20 +15,21 @@
/**
- * This panel displays all the logged in users.
+ * This panel displays all file related activities.
+ *
+ * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
-class FtpFilePanel extends JPanel {
+class FtpFilePanel extends PluginPanel {
private FtpFileTableModel mModel;
- private FtpFilePanel mSelf;
private String mstHeader;
/**
* Instantiate login panel.
*/
- public FtpFilePanel(FtpFileTableModel model, String header) {
- mSelf = this;
+ public FtpFilePanel(CommonHandler commonHandler, JTree tree, FtpFileTableModel model, String header) {
+ super(commonHandler, tree);
mModel = model;
mstHeader = header;
initComponents();
@@ -84,4 +85,4 @@
mModel.close();
}
-}
\ No newline at end of file
+}
1.5 +31 -26 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java
Index: FtpConnectionTableModel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionTableModel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FtpConnectionTableModel.java 6 Mar 2002 13:53:20 -0000 1.4
+++ FtpConnectionTableModel.java 31 Mar 2002 16:52:43 -0000 1.5
@@ -27,7 +27,7 @@
/**
* This table model tracks currently logged in users.
*
- * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
+ * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
class FtpConnectionTableModel extends AbstractTableModel
@@ -35,12 +35,11 @@
private final static SimpleDateFormat DATE_FMT = new SimpleDateFormat("MM/dd HH:mm:ss");
- private final static String[] COL_NAMES = {"Name",
+ private final static String[] COL_NAMES = {"User",
"Login Time",
"Last Access Time",
"Client"};
-
- private Vector mUserList;
+ private List mConnectedUserList;
private ConnectionServiceInterface mConService;
private CommonHandler mCommonHandler;
@@ -50,12 +49,17 @@
/**
* Constructor - initialize user list
*/
- public FtpConnectionTableModel(CommonHandler commonHandler) throws RemoteException {
+ public FtpConnectionTableModel(CommonHandler commonHandler) {
mCommonHandler = commonHandler;
mConService = mCommonHandler.getConnectionService();
- mUserList = new Vector();
- mObserver = new FtpConnectionObserverAdapter(mConService, this);
- reload();
+ mConnectedUserList = new Vector();
+ try {
+ mObserver = new FtpConnectionObserverAdapter(mConService, this);
+ reload();
+ }
+ catch(Exception ex) {
+ commonHandler.handleException(ex);
+ }
}
/**
@@ -63,9 +67,9 @@
*/
public FtpUser getUser(int index) {
FtpUser user = null;
- synchronized(mUserList) {
- if ( (index >= 0) && (index < mUserList.size()) ) {
- user = (FtpUser)mUserList.get(index);
+ synchronized(mConnectedUserList) {
+ if ( (index >= 0) && (index < mConnectedUserList.size()) ) {
+ user = (FtpUser)mConnectedUserList.get(index);
}
}
return user;
@@ -97,7 +101,7 @@
* Get row count.
*/
public int getRowCount() {
- return mUserList.size();
+ return mConnectedUserList.size();
}
/**
@@ -168,9 +172,9 @@
}
int sz = -1;
- synchronized(mUserList) {
- mUserList.add(thisUser);
- sz = mUserList.size();
+ synchronized(mConnectedUserList) {
+ mConnectedUserList.add(thisUser);
+ sz = mConnectedUserList.size();
}
if (sz != -1) {
@@ -188,10 +192,10 @@
}
int index = -1;
- synchronized(mUserList) {
- index = mUserList.indexOf(user);
+ synchronized(mConnectedUserList) {
+ index = mConnectedUserList.indexOf(user);
if (index != -1) {
- mUserList.remove(index);
+ mConnectedUserList.remove(index);
}
}
@@ -209,10 +213,10 @@
}
int index = -1;
- synchronized(mUserList) {
- index = mUserList.indexOf(user);
+ synchronized(mConnectedUserList) {
+ index = mConnectedUserList.indexOf(user);
if (index != -1) {
- mUserList.set(index, user);
+ mConnectedUserList.set(index, user);
}
}
@@ -226,9 +230,9 @@
* Reload table model
*/
public void reload() throws RemoteException {
- synchronized(mUserList) {
- mUserList.clear();
- mUserList.addAll(mConService.getAllUsers());
+ synchronized(mConnectedUserList) {
+ mConnectedUserList.clear();
+ mConnectedUserList.addAll(mConService.getAllUsers());
}
fireTableDataChanged();
}
@@ -239,7 +243,8 @@
*/
public void close() {
mObserver.close();
- mUserList.clear();
+ mConnectedUserList.clear();
}
-}
\ No newline at end of file
+}
+
1.5 +25 -23 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionPanel.java
Index: FtpConnectionPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpConnectionPanel.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- FtpConnectionPanel.java 6 Mar 2002 13:53:20 -0000 1.4
+++ FtpConnectionPanel.java 31 Mar 2002 16:52:43 -0000 1.5
@@ -12,6 +12,7 @@
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
+import javax.swing.tree.TreePath;
import org.apache.avalon.ftpserver.FtpUser;
@@ -21,24 +22,19 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpConnectionPanel extends JPanel {
+class FtpConnectionPanel extends PluginPanel {
private JTable mjConnectionTable;
- private FtpConnectionPanel mSelf;
-
- private CommonHandler mCommonHandler;
private FtpConnectionTableModel mModel;
- private FtpSpyFrame mSpyFrame;
+
/**
* Instantiate login panel.
*/
- public FtpConnectionPanel(CommonHandler commonHandler) throws RemoteException {
- mSelf = this;
- mCommonHandler = commonHandler;
- mModel = new FtpConnectionTableModel(mCommonHandler);
+ public FtpConnectionPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
+ mModel = new FtpConnectionTableModel(commonHandler);
initComponents();
- mSpyFrame = new FtpSpyFrame(commonHandler);
}
/**
@@ -99,11 +95,11 @@
private void closeConnection() {
int indices[] = mjConnectionTable.getSelectedRows();
if(indices.length == 0) {
- GuiUtils.showErrorMessage(mSelf, "Please select connection(s).");
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Please select connection(s).");
return;
}
- boolean response = GuiUtils.getConfirmation(mSelf, "Do you really want to close the selected connection(s)?");
+ boolean response = GuiUtils.getConfirmation(getCommonHandler().getTopComponent(), "Do you really want to close the selected connection(s)?");
if(!response) {
return;
}
@@ -112,12 +108,12 @@
for(int i=indices.length; --i>=0; ) {
FtpUser user = mModel.getUser(indices[i]);
if(user != null) {
- mCommonHandler.getConnectionService().closeConnection(user.getSessionId());
+ getCommonHandler().getConnectionService().closeConnection(user.getSessionId());
}
}
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -127,33 +123,41 @@
private void spyUser() {
int indices[] = mjConnectionTable.getSelectedRows();
if(indices.length == 0) {
- GuiUtils.showErrorMessage(mSelf, "Please select connection(s).");
+ GuiUtils.showErrorMessage(getCommonHandler().getTopComponent(), "Please select connection(s).");
return;
}
+ // monitor all the selected users
try {
for(int i=indices.length; --i>=0; ) {
FtpUser thisUser = mModel.getUser(indices[i]);
if (thisUser != null) {
- mSpyFrame.monitorConnection(thisUser);
+ FtpSpyContainerPanel spyPanel = (FtpSpyContainerPanel)((FtpTree)getTree()).getPluginPanel("Spy");
+ spyPanel.monitorConnection(thisUser);
}
}
- mSpyFrame.setVisible(true);
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
+
+ // select tree spy node
+ Object[] spyPath = new Object[] {
+ getTree().getModel().getRoot(), "Spy"
+ };
+ getTree().setSelectionPath(new TreePath(spyPath));
+
}
/**
- * Reload connection table
+ * Refresh window.
*/
private void reload() {
try {
mModel.reload();
}
catch(Exception ex) {
- mCommonHandler.handleException(ex);
+ getCommonHandler().handleException(ex);
}
}
@@ -162,8 +166,6 @@
*/
public void close() {
mModel.close();
- mSpyFrame.close();
- mSpyFrame.dispose();
}
-}
\ No newline at end of file
+}
1.11 +11 -55 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java
Index: FtpAdminFrame.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdminFrame.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- FtpAdminFrame.java 6 Mar 2002 13:53:20 -0000 1.10
+++ FtpAdminFrame.java 31 Mar 2002 16:52:43 -0000 1.11
@@ -16,7 +16,6 @@
import javax.swing.tree.*;
import org.apache.avalon.ftpserver.remote.interfaces.RemoteHandlerInterface;
-import org.apache.avalon.ftpserver.FtpException;
/**
@@ -31,17 +30,15 @@
private JTabbedPane mjTabPane;
- private JTree mjFtpTree = null;
+ private FtpTree mjFtpTree = null;
private JPanel mjFtpPane = null;
- private FtpRootPanel mRootPane = null;
private CommonHandler mCommonHandler = null;
-
/**
* Creates new form MyServerFrame
*/
- public FtpAdminFrame(CommonHandler commonHandler) throws RemoteException, FtpException {
+ public FtpAdminFrame(CommonHandler commonHandler) throws RemoteException {
mCommonHandler = commonHandler;
initComponents();
}
@@ -58,7 +55,8 @@
jSplitPane.setDividerSize(2);
// left pane
- mjFtpTree = new JTree(new FtpTreeModel());
+ mjFtpTree = new FtpTree(mCommonHandler);
+ mjFtpTree.addTreeSelectionListener(this);
JScrollPane custPane = new JScrollPane(mjFtpTree,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
@@ -68,20 +66,8 @@
mjFtpPane = new JPanel();
jSplitPane.setRightComponent(mjFtpPane);
- mRootPane = new FtpRootPanel(mCommonHandler);
-
- mjFtpPane.add(mRootPane);
-
- mjFtpTree.addTreeSelectionListener(this);
- mjFtpTree.setSelectionPath(new TreePath(RemoteHandlerInterface.DISPLAY_NAME));
- mjFtpTree.putClientProperty("JTree.lineStyle", "Angled");
-
- DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
- renderer.setLeafIcon(null);
- renderer.setOpenIcon(null);
- renderer.setClosedIcon(null);
- mjFtpTree.setCellRenderer(renderer);
-
+ mjFtpPane.add(mjFtpTree.getRootPanel());
+
jSplitPane.setDividerLocation(100);
mjTabPane.addTab(RemoteHandlerInterface.DISPLAY_NAME, jSplitPane);
@@ -102,12 +88,12 @@
protected void processWindowEvent(WindowEvent e) {
int id = e.getID();
if (id == WindowEvent.WINDOW_CLOSING) {
- if ( !GuiUtils.getConfirmation(this, "Do you really want to exit?") ) {
+ if ( !GuiUtils.getConfirmation(mCommonHandler.getTopComponent(), "Do you really want to exit?") ) {
return;
}
- super.processWindowEvent(e);
mCommonHandler.terminate();
- } else {
+ }
+ else {
super.processWindowEvent(e);
}
}
@@ -116,37 +102,7 @@
* Handle tree selection
*/
public void valueChanged(TreeSelectionEvent e) {
- Object node = e.getPath().getLastPathComponent();
- TreeModel model = mjFtpTree.getModel();
- JPanel dispPane = null;
- if(model.getRoot().equals(node)) {
- dispPane = mRootPane;
- }
- else if(node.equals(FtpTreeModel.CHILDREN[0])) {
- dispPane = mRootPane.getUserPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[1])) {
- dispPane = mRootPane.getConnectionPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[2])) {
- dispPane = mRootPane.getIpPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[3])) {
- dispPane = mRootPane.getUploadPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[4])) {
- dispPane = mRootPane.getDownloadPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[5])) {
- dispPane = mRootPane.getDeletePanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[6])) {
- dispPane = mRootPane.getStatisticsPanel();
- }
- else if(node.equals(FtpTreeModel.CHILDREN[7])) {
- dispPane = mRootPane.getAboutPanel();
- }
-
+ JPanel dispPane = mjFtpTree.getSelectedPanel();
if(dispPane != null) {
GuiUtils.showNewPanel(mjFtpPane, dispPane);
}
@@ -157,7 +113,7 @@
*/
public void close() {
setVisible(false);
- mRootPane.close();
+ mjFtpTree.close();
dispose();
}
1.10 +1 -1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdmin.java
Index: FtpAdmin.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAdmin.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- FtpAdmin.java 6 Mar 2002 13:53:20 -0000 1.9
+++ FtpAdmin.java 31 Mar 2002 16:52:43 -0000 1.10
@@ -199,7 +199,6 @@
protected void processWindowEvent(WindowEvent e) {
int id = e.getID();
if (id == WindowEvent.WINDOW_CLOSING) {
- super.processWindowEvent(e);
terminate();
}
else {
@@ -251,6 +250,7 @@
* Handle exception
*/
public void handleException(Exception ex) {
+ //ex.printStackTrace();
GuiUtils.showErrorMessage(getTopComponent(), ex.getMessage());
if (ex instanceof java.rmi.RemoteException) {
logout();
1.2 +5 -8 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAboutPanel.java
Index: FtpAboutPanel.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpAboutPanel.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- FtpAboutPanel.java 6 Mar 2002 13:53:20 -0000 1.1
+++ FtpAboutPanel.java 31 Mar 2002 16:52:43 -0000 1.2
@@ -15,6 +15,7 @@
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import javax.swing.JTree;
import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JEditorPane;
@@ -32,7 +33,7 @@
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
-class FtpAboutPanel extends JPanel implements HyperlinkListener {
+class FtpAboutPanel extends PluginPanel implements HyperlinkListener {
public final static String ABOUT_PAGE = "org/apache/avalon/ftpserver/gui/about.html";
private JEditorPane mjEditorPane = null;
@@ -40,7 +41,8 @@
/**
* Constructor.
*/
- public FtpAboutPanel() {
+ public FtpAboutPanel(CommonHandler commonHandler, JTree tree) {
+ super(commonHandler, tree);
initComponents();
}
@@ -100,10 +102,10 @@
private void goHome() {
InputStream is = null;
try {
+ mjEditorPane.setContentType("text/html");
is = getClass().getClassLoader().getResourceAsStream(ABOUT_PAGE);
if (is != null) {
mjEditorPane.read(is, null);
-
}
}
catch(IOException ex) {
@@ -113,9 +115,4 @@
}
}
- /**
- * Close panel - does nothing
- */
- public void close() {
- }
}
1.2 +1 -0 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/about.html
Index: about.html
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/about.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- about.html 6 Mar 2002 13:53:20 -0000 1.1
+++ about.html 31 Mar 2002 16:52:43 -0000 1.2
@@ -29,6 +29,7 @@
<li><font face="Arial">You can encrypt the password in property file based user manager by specifying user manager encrypt key. The encryption algorithm is MD5.</font></li>
<li><font face="Arial">Database based user manager will try to create the user table FTP_USER if not found. You can create it manually by executing apps/ftp/conf/ftp-db.sql file. I have tested it using MySQL and Oracle database.</font></li>
<li><font face="Arial">If you want to use LDAP to store and authenticate user, you need to change the LDAP schema and the config file. The schema file is ftp-db.ldif. I have tested it using Netscape LDAP (version 4.1).</font></li>
+ <li><font face="Arial">Supports SITE commands. Use <code>SITE HELP</code> to get the available commands.</font></li>
<li><font face="Arial">You can start remote admin GUI by executing <code>java -jar ftp-admin.jar</code>.</font></li>
<li><font face="Arial">Tested with different FTP clients like
<a href="http://www.microsoft.com/windows/ie/">Internet Explorer</a>,
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/spy.html
Index: spy.html
===================================================================
<html><head><title></title></head>
<body bgcolor="#FFFFFF">
<br><br><br><br>
<center><font face="verdana, arial, helvetica" size="4" color="#0000FF"><b>Please, select a connection.</b></font></center>
</body>
</html>
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/PluginPanel.java
Index: PluginPanel.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 org.apache.avalon.ftpserver.gui;
import javax.swing.JTree;
import javax.swing.JPanel;
/**
* All ftp panels implement this interface.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
*/
public
class PluginPanel extends JPanel {
private JTree mTree;
private CommonHandler mCommonHandler;
/**
* Constructor - set the ftp tree object.
*/
public PluginPanel(CommonHandler commonHandler, JTree tree) {
mCommonHandler = commonHandler;
mTree = tree;
}
/**
* Get ftp tree object.
*/
public JTree getTree() {
return mTree;
}
/**
* Get common handler object
*/
public CommonHandler getCommonHandler() {
return mCommonHandler;
}
/**
* Close resources - dummy implementation
*/
public void close() {
}
}
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpTree.java
Index: FtpTree.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 org.apache.avalon.ftpserver.gui;
import java.util.Vector;
import javax.swing.JTree;
import javax.swing.JPanel;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeModel;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.event.TreeModelListener;
import org.apache.avalon.ftpserver.remote.interfaces.RemoteHandlerInterface;
/**
* This is FTP user interface tree structure.
* It looks like:
* <pre>
* FTP
* |
* +-- User (User management)
* |
* +-- Ip (IP restrictions)
* |
* +-- Connection (Connection monitor)
* |
* +-- Spy (Spy user activities)
* |
* +-- Statistics (Global statistics)
* |
* +-- Upload (File upload statistics)
* |
* +-- Download (File download statistics)
* |
* +-- Delete (File deletion statistics)
* |
* +-- About (Ftp server summary)
* </pre>
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpTree extends JTree implements TreeModel {
public final static String[] CHILDREN = {
"User",
"IP",
"Connection",
"Spy",
"Statistics",
"Upload",
"Download",
"Delete",
"About"
};
private Vector mListenrList;
private FtpRootPanel mRootPanel;
private PluginPanel[] mPluginPanels;
private CommonHandler mCommonHandler;
/**
* create this tree model
*/
public FtpTree(CommonHandler commonHandler) {
mCommonHandler = commonHandler;
mListenrList = new Vector();
setModel(this);
setSelectionPath(new TreePath(RemoteHandlerInterface.DISPLAY_NAME));
putClientProperty("JTree.lineStyle", "Angled");
DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
renderer.setLeafIcon(null);
renderer.setOpenIcon(null);
renderer.setClosedIcon(null);
setCellRenderer(renderer);
initPlugins();
mRootPanel = new FtpRootPanel(mCommonHandler, this);
}
/**
* Initialize all plugin panels
*/
private void initPlugins() {
mPluginPanels = new PluginPanel[CHILDREN.length];
mPluginPanels[0] = new FtpUserPanel(mCommonHandler, this);
mPluginPanels[1] = new FtpIpPanel(mCommonHandler, this);
mPluginPanels[2] = new FtpConnectionPanel(mCommonHandler, this);
mPluginPanels[3] = new FtpSpyContainerPanel(mCommonHandler, this);
mPluginPanels[4] = new FtpStatisticsPanel(mCommonHandler, this);
mPluginPanels[5] = new FtpFilePanel(mCommonHandler, this, ((FtpStatisticsPanel)mPluginPanels[4]).getUploadModel(), "Uploaded Files");
mPluginPanels[6] = new FtpFilePanel(mCommonHandler, this, ((FtpStatisticsPanel)mPluginPanels[4]).getDownloadModel(), "Downloaded Files");
mPluginPanels[7] = new FtpFilePanel(mCommonHandler, this, ((FtpStatisticsPanel)mPluginPanels[4]).getDeleteModel(), "Deleted Files");
mPluginPanels[8] = new FtpAboutPanel(mCommonHandler, this);
}
/**
* get root object
*/
public Object getRoot() {
return RemoteHandlerInterface.DISPLAY_NAME;
}
/**
* get child object
*/
public Object getChild(Object parent, int index) {
return CHILDREN[index];
}
/**
* get child count
*/
public int getChildCount(Object parent) {
if(parent.equals(RemoteHandlerInterface.DISPLAY_NAME)) {
return CHILDREN.length;
}
return 0;
}
/**
* is a leaf or node
*/
public boolean isLeaf(Object node) {
return !node.equals(RemoteHandlerInterface.DISPLAY_NAME);
}
/**
* get child index
*/
public int getIndexOfChild(Object parent, Object child) {
int childIdx = -1;
for(int i=CHILDREN.length; --i>=0; ) {
if(CHILDREN[i].equals(child)) {
childIdx = i;
break;
}
}
return childIdx;
}
/**
* Object changed. In our case it is not possible - so igmore it.
*/
public void valueForPathChanged(TreePath path, Object newValue) {
}
/**
* add a listener
*/
public void addTreeModelListener(TreeModelListener l) {
mListenrList.add(l);
}
/**
* remove a listener
*/
public void removeTreeModelListener(TreeModelListener l) {
mListenrList.remove(l);
}
/**
* Get root panel.
*/
public FtpRootPanel getRootPanel() {
return mRootPanel;
}
/**
* Get plugin panel.
*/
public PluginPanel getPluginPanel(String panelName) {
PluginPanel panel = null;
for(int i=CHILDREN.length; --i>=0; ) {
if (CHILDREN[i].equals(panelName)) {
panel = mPluginPanels[i];
break;
}
}
return panel;
}
/**
* Get the selected panel.
*/
public JPanel getSelectedPanel() {
Object node = getSelectionPath().getLastPathComponent();
JPanel dispPane = null;
if(getRoot().equals(node)) {
dispPane = mRootPanel;
}
else {
dispPane = getPluginPanel(node.toString());
if ( dispPane == null ) {
dispPane = mRootPanel;
}
}
return dispPane;
}
/**
* Close all panels
*/
public void close() {
if (mRootPanel != null) {
mRootPanel.close();
}
for(int i=mPluginPanels.length; --i>=0; ) {
PluginPanel panel = mPluginPanels[i];
if (panel != null) {
panel.close();
}
}
}
}
1.1 jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/gui/FtpSpyContainerPanel.java
Index: FtpSpyContainerPanel.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 org.apache.avalon.ftpserver.gui;
import java.io.InputStream;
import java.io.IOException;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import org.apache.avalon.ftpserver.FtpUser;
import org.apache.avalon.ftpserver.util.IoUtils;
/**
* This panel holds all connection spy panels.
*
* @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
*/
public
class FtpSpyContainerPanel extends PluginPanel {
public final static String SPY_PAGE = "org/apache/avalon/ftpserver/gui/spy.html";
private JTabbedPane mjTabbedPane = null;
private JButton mjClearButton = null;
private JButton mjCloseButton = null;
private JButton mjDisconnectButton = null;
private JScrollPane mjAboutPane = null;
/**
* Constructor - create empty tabbed frame
*/
public FtpSpyContainerPanel(CommonHandler commonHandler, JTree tree) {
super(commonHandler, tree);
initComponents();
}
/**
* Initialize all components
*/
private void initComponents() {
setLayout(new BorderLayout());
mjTabbedPane = new JTabbedPane();
mjTabbedPane.setPreferredSize(new Dimension(470, 340));
add(mjTabbedPane, BorderLayout.CENTER);
JPanel bottomPane = new JPanel();
bottomPane.setLayout(new FlowLayout(FlowLayout.CENTER));
mjClearButton = new JButton("Clear");
bottomPane.add(mjClearButton);
mjClearButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
clearLog();
}
});
mjCloseButton = new JButton("Close");
bottomPane.add(mjCloseButton);
mjCloseButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
closePane();
}
});
mjDisconnectButton = new JButton("Disconnect");
bottomPane.add(mjDisconnectButton);
mjDisconnectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
disconnectUser();
}
});
add(bottomPane, BorderLayout.SOUTH);
// initialize component to be displayed if
// there is no currently monitored connection
JEditorPane editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html");
InputStream is = null;
try {
is = getClass().getClassLoader().getResourceAsStream(SPY_PAGE);
if (is != null) {
editorPane.read(is, null);
}
}
catch(IOException ex) {
}
finally {
IoUtils.close(is);
}
mjAboutPane = new JScrollPane(editorPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
mjTabbedPane.addTab("Spy", mjAboutPane);
}
/**
* Clear user log
*/
private void clearLog() {
Component selComp = mjTabbedPane.getSelectedComponent();
if ( (selComp != null) && (selComp != mjAboutPane) ) {
((SpyPanel)selComp).clearLog();
}
}
/**
* Close connection spy panel.
*/
private void closePane() {
Component selComp = mjTabbedPane.getSelectedComponent();
if ( (selComp != null) && (selComp != mjAboutPane) ) {
((SpyPanel)selComp).close();
mjTabbedPane.remove(selComp);
if (mjTabbedPane.getTabCount() == 0) {
mjTabbedPane.addTab("Spy", mjAboutPane);
}
}
}
/**
* Disconnected user connection
*/
private void disconnectUser() {
Component selComp = mjTabbedPane.getSelectedComponent();
if ( (selComp != null) && (selComp != mjAboutPane) ) {
boolean bConf = GuiUtils.getConfirmation(getCommonHandler().getTopComponent(), "Do you want to close the connection?");
if(bConf) {
((SpyPanel)selComp).disconnect();
}
}
}
/**
* Monitor connection
*/
public void monitorConnection(FtpUser user) {
String userName = getName(user);
String userSession = user.getSessionId();
// don't add another tab if already being monitored
int tabCount = mjTabbedPane.getTabCount();
for(int i=tabCount; --i>=0; ) {
Component selComp = mjTabbedPane.getComponentAt(i);
if ( (selComp != null) && (selComp != mjAboutPane) ) {
String tabUserSessionId = ((SpyPanel)selComp).getSessionId();
if (tabUserSessionId.equals(userSession)) {
mjTabbedPane.setTitleAt(i, userName);
mjTabbedPane.setSelectedIndex(i);
return;
}
}
}
// add new tab
try {
SpyPanel spyPane = new SpyPanel(getCommonHandler(), user);
mjTabbedPane.remove(mjAboutPane);
mjTabbedPane.add(userName, spyPane);
mjTabbedPane.setSelectedComponent(spyPane);
}
catch(Exception ex) {
getCommonHandler().handleException(ex);
}
}
/**
* Get name
*/
private String getName(FtpUser user) {
String name = "";
if (user != null) {
name = user.getName();
if (name == null) {
name = "UNKNOWN";
}
}
return name;
}
/**
* Stop all spying
*/
public void close() {
int tabCount = mjTabbedPane.getTabCount();
for(int i=tabCount; --i>=0; ) {
Component selComp = mjTabbedPane.getComponentAt(i);
if ( (selComp != null) && (selComp != mjAboutPane) ) {
((SpyPanel)selComp).close();
}
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>