incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: incubator-ftpserver/src/java/org/apache/ftpserver/gui ConnectionPanel.java DirChooser.java DirectoryPanel.java FilePanel.java FtpConnectionTableModel.java FtpDirectoryTableModel.java FtpFileTableModel.java GuiUtils.java IPRestrictorPanel.java IPRestrictorTable.java LICENSE.txt LoggerPanel.java
Date Wed, 07 Sep 2005 05:04:29 GMT
rana_b      2005/09/06 22:04:28

  Added:       src/java/org/apache/ftpserver/gui ConnectionPanel.java
                        DirChooser.java DirectoryPanel.java FilePanel.java
                        FtpConnectionTableModel.java
                        FtpDirectoryTableModel.java FtpFileTableModel.java
                        GuiUtils.java IPRestrictorPanel.java
                        IPRestrictorTable.java LICENSE.txt LoggerPanel.java
  Log:
  Refactored - removed avalon entirely
  
  Revision  Changes    Path
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/ConnectionPanel.java
  
  Index: ConnectionPanel.java
  ===================================================================
  // $Id: ConnectionPanel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.interfaces.IConnection;
  import org.apache.ftpserver.interfaces.IFtpConfig;
  
  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;
  
  /**
   * This panel shows all the connections.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class ConnectionPanel extends PluginPanel {
  
      private static final long serialVersionUID = 3774741162954995177L;
      
      private IFtpConfig m_fconfig;
      private JTable m_ConTable;   
      private FtpConnectionTableModel m_model;
      
      /**
       * Instantiate connection panel.
       */
      public ConnectionPanel(PluginPanelContainer container) {
          super(container);
          m_model = new FtpConnectionTableModel();
          initComponents();
      }
  
      
      /**
       * Initialize UI components.
       */
      private void initComponents() {
          setLayout(new BorderLayout());
          
          m_ConTable = new JTable(m_model);
          m_ConTable.setPreferredScrollableViewportSize(new Dimension(470, 320));
          m_ConTable.setColumnSelectionAllowed(false);
          JScrollPane bottomPane = new JScrollPane(m_ConTable, 
                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);                          
          add(bottomPane, BorderLayout.CENTER);
          
          
          // buttons
          JPanel btnPane = new JPanel(new FlowLayout(FlowLayout.CENTER));
          
          JButton jDisconnectBtn = new JButton("Disconnect");
          btnPane.add(jDisconnectBtn);
          
          JButton jSpyBtn = new JButton("Spy User");
          btnPane.add(jSpyBtn);
          
          JButton jReloadBtn = new JButton("Reload");
          btnPane.add(jReloadBtn);
          
          add(btnPane, BorderLayout.SOUTH);
  
          // event handlers
          jDisconnectBtn.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(m_fconfig);
               }
          });
      }
      
      
      /**
       * Close connection.
       */
      private void closeConnection() {
          int indices[] = m_ConTable.getSelectedRows();
          if(indices.length == 0) {
              GuiUtils.showErrorMessage(this, "Please select connection(s).");
              return;
          }
          
          boolean response = GuiUtils.getConfirmation(this, "Do you really want to close the selected connection(s)?");
          if(!response) {
              return;
          }
          
          for(int i=indices.length; --i>=0; ) {
              IConnection con = m_model.getConnection(indices[i]);
              if(con != null) {
                  m_fconfig.getConnectionManager().closeConnection(con);
              }
          }
      }
      
      
      /**
       * Spy user
       */
      private void spyUser() {
          int indices[] = m_ConTable.getSelectedRows();
          if(indices.length == 0) {
              GuiUtils.showErrorMessage(this, "Please select connection(s).");
              return;
          }
          
          // monitor all the selected users
          SpyPanelContainer spyContainer = (SpyPanelContainer)getContainer().getPluginPanel(PluginPanelContainer.SPY_INDEX);
          for(int i=indices.length; --i>=0; ) {   
              IConnection con = m_model.getConnection(indices[i]);
              if (con != null) {
                  spyContainer.monitorConnection(con); 
              }
          }
          
          // open the spy panel
          getContainer().setSelectedIndex(PluginPanelContainer.SPY_INDEX);
      }
      
      
      /** 
       * Refresh the ftp configuration
       */
      public void refresh(IFtpConfig ftpConfig) {
          m_fconfig = ftpConfig;
          m_model.refresh(ftpConfig);
      }
  
      
      /** 
       * This can be displayed only when the server is running.
       */
      public boolean canBeDisplayed() {
          return (m_fconfig != null);
      }
  
      
      /**
       * Get the string representation.
       */
      public String toString() {
          return "Connections";
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/DirChooser.java
  
  Index: DirChooser.java
  ===================================================================
  // $Id: DirChooser.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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.Component;
  import java.awt.Container;
  import java.awt.FlowLayout;
  import java.awt.Rectangle;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.WindowEvent;
  import java.io.File;
  import java.io.FileFilter;
  import java.util.ArrayList;
  import java.util.Arrays;
  
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JDialog;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTabbedPane;
  import javax.swing.JTextField;
  import javax.swing.JTree;
  import javax.swing.JViewport;
  import javax.swing.event.TreeExpansionEvent;
  import javax.swing.event.TreeSelectionEvent;
  import javax.swing.event.TreeSelectionListener;
  import javax.swing.event.TreeWillExpandListener;
  import javax.swing.filechooser.FileSystemView;
  import javax.swing.tree.DefaultMutableTreeNode;
  import javax.swing.tree.DefaultTreeCellRenderer;
  import javax.swing.tree.DefaultTreeModel;
  import javax.swing.tree.TreeModel;
  import javax.swing.tree.TreePath;
  
  
  /**
   * Generic directory chooser dialog panel.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class DirChooser extends JDialog implements TreeSelectionListener,
                                              TreeWillExpandListener,
                                              FileFilter {
      
      private static final long serialVersionUID = 7363990421558828943L;
  
      private final static FileSystemView FILE_VIEW = FileSystemView.getFileSystemView();
      
      private JTree m_tree;
      private JTextField m_dirText;
      private JScrollPane m_scrollPane;
      
      private JButton m_selectButton;
      private JButton m_cancelButton;
      
      private boolean m_showHidden = false; 
      private String m_selectedDir = null; 
      
      
      /**
       * Constructor - set the selected directory.
       */
      private DirChooser(Component comp, String title, File selDir) {
          super(JOptionPane.getFrameForComponent(comp), title, true);
          initComponents();
          selectDirectory(selDir);
      }
  
      /**
       * Initialize UI components
       */
      private void initComponents() {
          
          Container container = getContentPane();
          container.setLayout(new BorderLayout());
          
          // add the tabbed pane
          JTabbedPane tabPane = new JTabbedPane();
          container.add(tabPane, BorderLayout.CENTER);
          
          // top pane
          JPanel topPanel = new JPanel(new BorderLayout());
          tabPane.add("Directory", topPanel);
          
          // file tree
          m_tree = new JTree();
          m_scrollPane = new JScrollPane(m_tree);
          topPanel.add(m_scrollPane, BorderLayout.CENTER);
          
          // directory text panel
          JPanel dirTextPanel = new JPanel(new BorderLayout());
          dirTextPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
          topPanel.add(dirTextPanel, BorderLayout.SOUTH);
          
          // directory label
          JLabel dirLab = new JLabel("Directory:  ");
          dirTextPanel.add(dirLab, BorderLayout.WEST);
          
          // directory text filed
          m_dirText = new JTextField();
          dirTextPanel.add(m_dirText, BorderLayout.CENTER);
          
          // add the bottom pane
          JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
          container.add(bottomPanel, BorderLayout.SOUTH);
          
          // select button
          m_selectButton = new JButton("Select");
          m_selectButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  m_selectedDir = m_dirText.getText();
                  DirChooser.this.dispose();
              }
          });
          bottomPanel.add(m_selectButton);
          
          // cancel button
          m_cancelButton = new JButton("Cancel");
          m_cancelButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  m_selectedDir = null;
                  DirChooser.this.dispose();
              }
          });
          bottomPanel.add(m_cancelButton);
          
          // initialize 
          populateTree();
          setSize(300, 300);
      }
      
      
      /**
       * Populate tree
       */
      private void populateTree() {
          
          // create model
          DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("My Computer");
          DefaultTreeModel model = new DefaultTreeModel(rootNode, true);
          
          // add root drives
          File rootDrives[] = File.listRoots();
          DefaultMutableTreeNode driveNodes[] = new DefaultMutableTreeNode[rootDrives.length];
          for(int i=0; i<rootDrives.length; ++i) {
              driveNodes[i] = new DefaultMutableTreeNode(rootDrives[i]);
              rootNode.add(driveNodes[i]);
          }
          
          m_tree.setModel(model);
          m_tree.setRootVisible(false);
          m_tree.setExpandsSelectedPaths(true);
          m_tree.addTreeWillExpandListener(this);
          m_tree.setCellRenderer(new DirTreeCellRenderer());
          m_tree.addTreeSelectionListener(this);
      }
      
      
      /**
       * Select directory.
       */
      public void selectDirectory(File dir) {
          
          // error check
          if(dir == null) {
              return;
          }
          if(!dir.exists()) {
              return;
          }
          
          // resolve the path name
          try {
              dir = dir.getCanonicalFile();
          }
          catch(Exception ex) {
             return;
          }
          
          if(!dir.isDirectory()) {
              dir = dir.getParentFile();
              if(dir == null) {
                  return;
              }
          }
          
          ArrayList dirs = new ArrayList();
          while(true) {
              dirs.add(dir);
              if(FILE_VIEW.isRoot(dir)) {
                  break;
              }
              
              File parent = dir.getParentFile();
              if(parent == null) {
                  break;
              }
              if(!parent.exists()) {
                  return;
              }
              dir = parent;
          }
          
          JViewport viewPort = m_scrollPane.getViewport();
          TreeModel model = m_tree.getModel();
          DefaultMutableTreeNode node = (DefaultMutableTreeNode)model.getRoot();
          for(int i=dirs.size(); --i>=0; ) {
              File currDir = (File)dirs.get(i);
              m_tree.expandPath(new TreePath(node.getPath()));
              int count = node.getChildCount();
              int j;
              for(j=0; j<count; ++j) {
                  DefaultMutableTreeNode currNode = (DefaultMutableTreeNode)node.getChildAt(j);
                  if(currNode.getUserObject().equals(currDir)) {
                      node = currNode;
                      TreePath currPath = new TreePath(currNode.getPath());
                      m_tree.setSelectionPath(currPath);
                      Rectangle rect = m_tree.getPathBounds(currPath);
                      if(rect != null) {
                          viewPort.setViewPosition(rect.getLocation());
                      }
                      break;
                  }
              }
              if(j == count) {
                  break;
              }
          }
      }
      
      
      /**
       * Handle dialog closing event.
       */ 
      protected void processWindowEvent(WindowEvent e) {
          int id = e.getID();
          if (id == WindowEvent.WINDOW_CLOSING) {
              m_selectedDir = null;
              dispose();
          } 
          else {
              super.processWindowEvent(e);
          }
      }
      
      
      /**
       * Show dialog
       */
      public static String showDialog(Component parent, String title, File initFile) {
          DirChooser chooser = new DirChooser(parent, title, initFile);
          chooser.setLocationRelativeTo(parent);
          
          chooser.setVisible(true);
          return chooser.m_selectedDir;
      }
      
      
      ////////////////////////////////////////////////////////////////////////////
      /////////////////// Tree selection listener implementation /////////////////
      /**
       * Write the dir selection in the text field.
       */
      public void valueChanged(TreeSelectionEvent e) {
          TreePath path = e.getPath(); 
          if(path != null) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
              File dir = (File)node.getUserObject();
              m_dirText.setText(dir.getAbsolutePath());
          }
      } 
  
      
      /////////////////////////////////////////////////////////////////////////
      /////////////// Tree Will Expand Listener implementation ////////////////
      public void treeWillCollapse(TreeExpansionEvent e) {
      }
      
      
      public void treeWillExpand(TreeExpansionEvent e) {
          
          // get the tree path which will be expanded
          TreePath path = e.getPath();
          if(path == null) {
              return;
          }
          
          // get the directory at the node
          DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent();
          File selDir = (File)node.getUserObject();
          
          // remove old entries
          if(node.getChildCount() > 0) {
              node.removeAllChildren();
          }
          
          // get all the subdirectories
          File childDirs[] = selDir.listFiles(this);
          if(childDirs == null) {
              return;
          }
          
          // add the subdirectories
          Arrays.sort(childDirs);
          for(int i = 0; i < childDirs.length; i++) {
              if(childDirs[i].isHidden()) {
                  if(m_showHidden) {
                      node.add(new DefaultMutableTreeNode(childDirs[i]));
                  }
              }
              else {
                  node.add(new DefaultMutableTreeNode(childDirs[i]));
              }
          }
      }
      
  
      ///////////////////////////////////////////////////////////////////////////
      ////////////////////// File filter implementation /////////////////////////
      public boolean accept(File pathname) {
          return pathname.isDirectory();
      }
      
      
      /////////////////////////////////////////////////////////////////////////////
      /////////////////////////// Tree Renderer Component /////////////////////////
      static class DirTreeCellRenderer extends DefaultTreeCellRenderer {
          
          private static final long serialVersionUID = -200713666464104466L;
  
          public Component getTreeCellRendererComponent(JTree tree, 
                                                        Object value, 
                                                        boolean selected, 
                                                        boolean expanded, 
                                                        boolean leaf, 
                                                        int row, 
                                                        boolean hasFocus) {
              
              DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
              File dir = (File)node.getUserObject();
              
              String name = dir.getName().trim();
              if( (name == null) || name.equals("")) {
                  name = dir.getAbsolutePath();
              }
              return super.getTreeCellRendererComponent(tree, name, selected, expanded, leaf, row, hasFocus);
          } 
  
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/DirectoryPanel.java
  
  Index: DirectoryPanel.java
  ===================================================================
  // $Id: DirectoryPanel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.ftplet.FileObject;
  import org.apache.ftpserver.ftplet.User;
  import org.apache.ftpserver.interfaces.IConnection;
  import org.apache.ftpserver.interfaces.IFtpConfig;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JComponent;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTabbedPane;
  import javax.swing.JTable;
  
  /**
   * This panel monitor all user directory create and remove activities.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class DirectoryPanel extends PluginPanel {
      
      private static final long serialVersionUID = 2890691567985219146L;
  
      private final static String HEADERS[] = {
              "Created",
              "Removed"
      };
      
      private IFtpConfig        m_fconfig;
      private FtpDirectoryTableModel[] m_models;
      
      
      /**
       * Instantiate directory panel.
       */
      public DirectoryPanel(PluginPanelContainer container) {
          super(container);
          initComponents();
      }
       
      
      /**
       * Initialize UI components
       */
      private void initComponents() {
          setLayout(new BorderLayout());
          JTabbedPane tabPane = new JTabbedPane();
          add(tabPane, BorderLayout.CENTER);
          
          m_models = new FtpDirectoryTableModel[2];
          for(int i=0; i<m_models.length; ++i) {
              m_models[i] = new FtpDirectoryTableModel();
              tabPane.addTab(HEADERS[i], createTabComponent(i));
          }
      }
       
      /**
       * Create tab component.
       */
      private JComponent createTabComponent(final int index) {        
          
          JPanel panel = new JPanel(new BorderLayout()); 
          
          JTable dirTable = new JTable(m_models[index]);
          dirTable.setPreferredScrollableViewportSize(new Dimension(470, 300));
          dirTable.setColumnSelectionAllowed(false);
          JScrollPane scrollPane = new JScrollPane(dirTable, 
                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);                          
          panel.add(scrollPane, BorderLayout.CENTER);
          
          
          // button
          JPanel bottomPanel = new JPanel();
          JButton jResetBtn = new JButton("Clear");
          bottomPanel.add(jResetBtn);
          panel.add(bottomPanel, BorderLayout.SOUTH);
          
          // event handler
          jResetBtn.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                  m_models[index].clear();
               }
          });
          return panel;
      }
      
      
      /**
       * Make directory notification.
       */
      public void notifyMkdir(IConnection con, FileObject file) {
          User user = con.getRequest().getUser();
          m_models[0].newEntry(file.getFullName(), user);
      }
      
      
      /**
       * Remove directory notification.
       */
      public void notifyRmdir(IConnection con, FileObject file) {
          User user = con.getRequest().getUser();
          m_models[1].newEntry(file.getFullName(), user);
      }
      
      
      /**
       * Refresh the panel - set the ftp config.
       */
      public void refresh(IFtpConfig config) {
          m_fconfig = config;
          m_models[0].clear();
          m_models[1].clear();
      }
      
      
      /**
       * Can this panel be displayed.
       */
      public boolean canBeDisplayed() {
          return (m_fconfig != null);
      }
   
      
      /**
       * String representation.
       */
      public String toString() {
          return "Directory";
      }   
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/FilePanel.java
  
  Index: FilePanel.java
  ===================================================================
  // $Id: FilePanel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.ftplet.FileObject;
  import org.apache.ftpserver.ftplet.User;
  import org.apache.ftpserver.interfaces.IConnection;
  import org.apache.ftpserver.interfaces.IFtpConfig;
  
  import java.awt.BorderLayout;
  import java.awt.Dimension;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.JButton;
  import javax.swing.JComponent;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTabbedPane;
  import javax.swing.JTable;
  
  /**
   * This panel displays all user file upload, download and remove activities.
   *
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
   */
  public 
  class FilePanel extends PluginPanel {
          
      private static final long serialVersionUID = 3172324853152800934L;
  
      private final static String HEADERS[] = {
              "Uploaded",
              "Downloaded",
              "Deleted"
      };
      
      private IFtpConfig        m_fconfig;
      private FtpFileTableModel[] m_models;
      
      
      /**
       * Instantiate file panel.
       */
      public FilePanel(PluginPanelContainer container) {
          super(container);
          initComponents();
      }
       
      /**
       * Initialize UI components
       */
      private void initComponents() {
          
          setLayout(new BorderLayout());
          
          
          JTabbedPane tabPane = new JTabbedPane();
          add(tabPane, BorderLayout.CENTER);
          
          m_models = new FtpFileTableModel[3];
          for(int i=0; i<m_models.length; ++i) {
              m_models[i] = new FtpFileTableModel();
              tabPane.addTab(HEADERS[i], createTabComponent(i));
          }
      }
       
      /**
       * Create tab component.
       */
      private JComponent createTabComponent(final int index) {        
          
          JPanel panel = new JPanel(new BorderLayout()); 
          
          JTable fileTable = new JTable(m_models[index]);
          fileTable.setPreferredScrollableViewportSize(new Dimension(470, 300));
          fileTable.setColumnSelectionAllowed(false);
          JScrollPane scrollPane = new JScrollPane(fileTable, 
                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);                          
          panel.add(scrollPane, BorderLayout.CENTER);
          
          
          // button
          JPanel bottomPanel = new JPanel();
          JButton jResetBtn = new JButton("Clear");
          bottomPanel.add(jResetBtn);
          panel.add(bottomPanel, BorderLayout.SOUTH);
          
          // event handler
          jResetBtn.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent evt) {
                  m_models[index].clear();
               }
          });
          return panel;
      }
      
      /**
       * File upload notification.
       */
      public void notifyUpload(IConnection con, FileObject file, long sz) {
          User user = con.getRequest().getUser();
          m_models[0].newEntry(file.getFullName(), user);
      }
      
      /**
       * File download notification.
       */
      public void notifyDownload(IConnection con, FileObject file, long sz) {
          User user = con.getRequest().getUser();
          m_models[1].newEntry(file.getFullName(), user);
      }
      
      /**
       * File delete notification.
       */
      public void notifyDelete(IConnection con, FileObject file) {
          User user = con.getRequest().getUser();
          m_models[2].newEntry(file.getFullName(), user);
      }
      
      
      /**
       * Refresh the panel - set the ftp config.
       */
      public void refresh(IFtpConfig config) {
          m_fconfig = config;
      }
      
      
      /**
       * Can this panel be displayed.
       */
      public boolean canBeDisplayed() {
          return (m_fconfig != null);
      }
   
      
      /**
       * String representation.
       */
      public String toString() {
          return "File";
      }
  }
  
  
  
  1.4       +139 -162  incubator-ftpserver/src/java/org/apache/ftpserver/gui/FtpConnectionTableModel.java
  
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/FtpDirectoryTableModel.java
  
  Index: FtpDirectoryTableModel.java
  ===================================================================
  // $Id: FtpDirectoryTableModel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.ftplet.User;
  import org.apache.ftpserver.util.DateUtils;
  
  import java.util.Vector;
  
  import javax.swing.table.AbstractTableModel;
  
  /**
   * This table model tracks user file related activities.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>.
   */
  public
  class FtpDirectoryTableModel extends AbstractTableModel {
      
      private static final long serialVersionUID = 2468107659374857692L;
      
      private final static int MAX_SIZE = 1000;
      private final static String[] COL_NAMES = {"Directory", 
                                                 "User", 
                                                 "Time"};    
  
      private Vector m_entries = new Vector();
      
           
      /**
       * Get column class - always string
       */
      public Class getColumnClass(int index) {
          return String.class;
      }
      
      /**
       * Get column count.
       */
      public int getColumnCount() {
          return COL_NAMES.length;
      }
      
      /**
       * Get column name.
       */
      public String getColumnName(int index) {
          return COL_NAMES[index];
      } 
      
      /**
       * Get row count.
       */
      public int getRowCount() {
          return m_entries.size();
      }
      
      /**
       * Is cell editable - currently false.
       */
      public boolean isCellEditable(int row, int col) {
          return true;
      }
      
     /**
      * Set value at - dummy method
      */
     public void setValueAt(Object val, int row, int col) {
     }
     
     /**
       * Get value at.
       */
      public Object getValueAt(int row, int col) {
          
          String retVal = "";
          TableEntry entry = null;
          try {
              entry = (TableEntry)m_entries.get(row);
          }
          catch(Exception ex) {
          }
          if (entry == null) {
              return retVal;
          }
          
          switch(col) {
              case 0:
                  retVal = entry.dirName;
                  break;
              
              case 1:
                  retVal = entry.userName;
                  break;
              
              case 2:
                  retVal = entry.date;
                  break;  
          }
          return retVal;
      }
    
     /**
      * Find column index.
      */
     public int findColumn(String columnName) {
          int index = -1;
          for(int i=COL_NAMES.length; --i>=0; ) {
              if (COL_NAMES[i].equals(columnName)) {
                  index = i;
                  break;
              }
          }
          return index;
     }
      
      /**
       * Add a new user
       */
      public void newEntry(String file, User user) {
          TableEntry entry = new TableEntry();
          entry.dirName = file;
          entry.userName = user.getName();
          entry.date = DateUtils.getISO8601Date(System.currentTimeMillis());
          
          int sz = m_entries.size();
          if ( (MAX_SIZE > 0) && (sz >= MAX_SIZE) ) {
              clear();
              sz = 0;
          }
          
          synchronized(m_entries) {
              m_entries.add(entry);
              ++sz;
          }
          fireTableRowsInserted(sz, sz);
      }  
      
      /**
       * Remove all entries
       */
      public void clear() {
          m_entries.clear();
          fireTableDataChanged();
      }
      
      //////////////////////////////////////////////////////////
      ///////////////////////list entry  ///////////////////////
      public class TableEntry {
          String dirName;
          String userName;
          String date;
      }
      
  }    
  
  
  
  1.4       +51 -61    incubator-ftpserver/src/java/org/apache/ftpserver/gui/FtpFileTableModel.java
  
  
  
  
  1.4       +31 -151   incubator-ftpserver/src/java/org/apache/ftpserver/gui/GuiUtils.java
  
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/IPRestrictorPanel.java
  
  Index: IPRestrictorPanel.java
  ===================================================================
  // $Id: IPRestrictorPanel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.interfaces.IFtpConfig;
  import org.apache.ftpserver.interfaces.IIpRestrictor;
  
  import java.awt.BorderLayout;
  import java.awt.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.BorderFactory;
  import javax.swing.JButton;
  import javax.swing.JPanel;
  
  /**
   * IP restrictor panel.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class IPRestrictorPanel extends PluginPanel {
  
      private static final long serialVersionUID = -1871174667851171193L;
      
      private IFtpConfig m_fconfig;
      private IPRestrictorTable m_table;
      
      /**
       * Default constructor.
       */
      public IPRestrictorPanel(PluginPanelContainer container) {
          super(container);
          initComponents();
      }
      
      /**
       * Initialize UI components
       */
      private void initComponents() {
          setLayout(new BorderLayout());
          
          m_table = new IPRestrictorTable();
          add(m_table, BorderLayout.CENTER);
          
          JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
          buttonPanel.setBorder(BorderFactory.createEtchedBorder());
          add(buttonPanel, BorderLayout.SOUTH);
          
          JButton saveBtn = new JButton("Save");
          saveBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  saveData();
              }
          });
          
          buttonPanel.add(saveBtn);
          
          JButton reloadBtn = new JButton("Reload");
          reloadBtn.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  reloadData();
              }
          });
          buttonPanel.add(reloadBtn);
      }
  
      /**
       * Save data.
       */
      private void saveData() {
          try {
              IIpRestrictor restrictor = m_fconfig.getIpRestrictor();
              restrictor.setPermissions(m_table.getData());
          }
          catch(Exception ex) {
              GuiUtils.showErrorMessage(this, "Cannot save IP entries.");
          }
      }
  
      /**
       * Reload data.
       */
      private void reloadData() {
          try {
              Object[][] perms = null;
              if(m_fconfig != null) {
                  IIpRestrictor restrictor = m_fconfig.getIpRestrictor();
                  perms = restrictor.getPermissions();
              }
              m_table.setData(perms);
          }
          catch(Exception ex) {
              GuiUtils.showErrorMessage(this, "Cannot load IP entries.");
          }
      }
  
      /**
       * Refresh - set the ftp config.
       */
      public void refresh(IFtpConfig ftpConfig) {
          m_fconfig = ftpConfig;
          reloadData();
      }
      
      /**
       * This panel can be displayed only when server is
       * running ie. ftp config is not null.
       */
      public boolean canBeDisplayed() {
          return (m_fconfig != null);
      }
      
      /**
       * Get the string representation.
       */
      public String toString() {
          return "IP Restrictor";
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/IPRestrictorTable.java
  
  Index: IPRestrictorTable.java
  ===================================================================
  // $Id: IPRestrictorTable.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.Vector;
  
  import javax.swing.JButton;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.ListSelectionModel;
  import javax.swing.event.EventListenerList;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  import javax.swing.event.TableModelEvent;
  import javax.swing.event.TableModelListener;
  import javax.swing.table.TableCellEditor;
  import javax.swing.table.TableModel;
  
  /**
   * IP restrictor table.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class IPRestrictorTable extends JPanel implements TableModel, ListSelectionListener {
  
      private static final long serialVersionUID = -7517200112683933776L;
  
      private final static String HEADER[] = {
              "IP Pattern",
              "Permission"
      };
      
      private Vector m_entries = new Vector();
      private EventListenerList m_modelListeners  = new EventListenerList();
      
      private JTable m_table;
      private JButton m_addButton;
      private JButton m_insertButton;
      private JButton m_removeButton;
      private JButton m_moveUpButton;
      private JButton m_moveDownButton;
      
      /**
       * Default constructor
       */
      public IPRestrictorTable() {
          initComponents();
      }
      
      /**
       * Initialize UI components.
       */
      private void initComponents() {
          
          setLayout(new BorderLayout());
          
          m_table = new JTable(this);
          m_table.setColumnSelectionAllowed(false);
          m_table.setRowSelectionAllowed(true);
          m_table.setRowHeight(20);
          m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
          m_table.getSelectionModel().addListSelectionListener(this);
          m_table.getColumnModel().getSelectionModel().addListSelectionListener(this);
          
          JScrollPane scrollPane = new JScrollPane(m_table);
          add(scrollPane, BorderLayout.CENTER);
          
          JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
          add(buttonPanel, BorderLayout.SOUTH);
          
          m_addButton = new JButton("Add");
          m_addButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  addRow();
              }
          });
          buttonPanel.add(m_addButton);
          
          m_insertButton = new JButton("Insert");
          m_insertButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  insertRow();
              }
          });
          buttonPanel.add(m_insertButton);
          
          m_removeButton = new JButton("Remove");
          m_removeButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  removeRow();
              }
          });
          buttonPanel.add(m_removeButton);
          
          m_moveUpButton = new JButton("Move Up");
          m_moveUpButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  moveUpRow();
              }
          });
          buttonPanel.add(m_moveUpButton);
          
          m_moveDownButton = new JButton("Move Down");
          m_moveDownButton.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  moveDownRow();
              }
          });
          buttonPanel.add(m_moveDownButton);
          setButtonStatus();
      }
      
      /**
       * Set button enable/disable status
       */
      private void setButtonStatus() {
          m_addButton.setEnabled(canBeAdded());
          m_insertButton.setEnabled(canBeInserted());
          m_removeButton.setEnabled(canBeRemoved());
          m_moveUpButton.setEnabled(canBeMovedUp());
          m_moveDownButton.setEnabled(canBeMovedDown());
      }
      
      /**
       * Can a new row be added?
       */
      private boolean canBeAdded() {
          return true;
      }
      
      /**
       * Can a row be inserted?
       */
      private boolean canBeInserted() {
          return true;
      }
      
      /**
       * Can a row be removed?
       */
      private boolean canBeRemoved() {
          
          // no data - nothing to be removed
          if( (m_entries == null) || (m_entries.size() == 0) ) {
              return false;
          }
          
          // no row selection - nothing to be removed
          int selRow = m_table.getSelectedRow();
          return (selRow >= 0);
      }
      
      /**
       * Can the selected row be moved up?
       */
      private boolean canBeMovedUp() {
          
          // no data - nothing to move up
          if( (m_entries == null) || (m_entries.size() == 0) ) {
              return false;
          }
          
          // no selection or the first row has been selected
          int selRow = m_table.getSelectedRow();
          return (selRow > 0);
      }
      
      /**
       * Can the selected row be moved down?
       */
      private boolean canBeMovedDown() {
          
          // no data - nothing to move down
          if( (m_entries == null) || (m_entries.size() == 0) ) {
              return false;
          }
          
          // no selection - nothing to move down
          int selRow = m_table.getSelectedRow();
          if(selRow == -1) {
              return false;
          }
          
          // last row cannot be moved down
          return ( selRow != (m_entries.size()-1) );
      }
      
      /**
       * Add a new row.
       */
      public void addRow() {
          
          // new row cannot be added
          if(!canBeAdded()) {
              return;
          }
          
          // save the changed data if any 
          stopCellEditing();
          
          // get row data and add
          Entry entry = new Entry();
          m_entries.add(entry);
          
          // notify listeners and select the newly added row
          int lastRow = m_entries.size() - 1;
          fireTableChanged( new TableModelEvent(this, lastRow, lastRow,
                TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT) );
          m_table.setRowSelectionInterval(lastRow, lastRow);
      }
      
      
      /**
       * Inser a new row entry an the selected (or last position)
       */
      public void insertRow() {
          
          // new row cannot be inserted
          if(!canBeInserted()) {
              return;
          }
          
          // save the changed data if any 
          stopCellEditing(); 
          
          // get the selected row 
          int selRow = m_table.getSelectedRow();
          if(selRow == -1) {
              selRow = m_entries.size() - 1;
          }
          if(selRow == -1) {
              selRow = 0;
          }
          
          // get row data and add
          Entry entry = new Entry();
          m_entries.add(selRow, entry);
          
          // notify listeners
          fireTableChanged( new TableModelEvent(this, selRow, selRow,
                  TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT) );
          m_table.setRowSelectionInterval(selRow, selRow);
      }
      
      /**
       * Delete the selected (or the last) row
       */
      public void removeRow() {
          
          // row cannot be removed
          if(!canBeRemoved()) {
              return;
          }
          
          // save the changed data if any 
          stopCellEditing();
          
          // get current selection
          int selRow = m_table.getSelectedRow();
          if(selRow == -1) {
              selRow = m_entries.size() - 1;
          }
          
          // remove row
          m_entries.remove(selRow);
          fireTableChanged( new TableModelEvent(this, selRow, selRow,
               TableModelEvent.ALL_COLUMNS, TableModelEvent.DELETE) );
          
          // select another row
          if(m_entries.isEmpty()) {
              setButtonStatus();
          }
          else {
              if(selRow == m_entries.size()) {
                  --selRow;
              }
              m_table.setRowSelectionInterval(selRow, selRow);
          }
      }
      
      /**
       * Move up a row.
       */
      public void moveUpRow() {
          
          // row cannot be moved up
          if(!canBeMovedUp()) {
              return;
          }
          
          // save the changed data if any 
          stopCellEditing();
          
          // change the entry positions
          int selRow = m_table.getSelectedRow();
          Entry ent1 = (Entry)m_entries.get(selRow);
          Entry ent2 = (Entry)m_entries.get(selRow - 1);
          
          m_entries.set(selRow, ent2);
          m_entries.set(selRow - 1, ent1);
          
          // notify listeners and update the table selection
          fireTableChanged( new TableModelEvent(this, selRow - 1, selRow,
                TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE) );
          m_table.setRowSelectionInterval(selRow - 1, selRow - 1);
      }
      
      /**
       * Move down a row.
       */
      public void moveDownRow() {
          
          // row cannot be moved down
          if(!canBeMovedDown()) {
              return;
          }
          
          // save the changed data if any 
          stopCellEditing();
          
          // change the entry positions
          int selRow = m_table.getSelectedRow();
          Entry ent1 = (Entry)m_entries.get(selRow);
          Entry ent2 = (Entry)m_entries.get(selRow + 1);
          
          m_entries.set(selRow, ent2);
          m_entries.set(selRow + 1, ent1);
          
          // notify listeners and update the table selection
          fireTableChanged( new TableModelEvent(this, selRow, selRow + 1,
                TableModelEvent.ALL_COLUMNS, TableModelEvent.UPDATE) );
          m_table.setRowSelectionInterval(selRow + 1, selRow + 1);
      }
      
      /**
       * Get data.
       */
      public Object[][] getData() {
          stopCellEditing();
          Object[][] retVal = new Object[m_entries.size()][2];
          for(int i=0; i<m_entries.size(); ++i) {
              Entry entry = (Entry)m_entries.get(i);
              retVal[i][0] = entry.m_pattern;
              retVal[i][1] = entry.m_allow;
          }
          return retVal;
      }
      
      /**
       * Set data.
       */
      public void setData(Object[][] objs) {
          cancelCellEditing();
          m_entries.clear();
          if(objs != null) {
              for(int i=0; i<objs.length; ++i) {
                  Entry entry = new Entry();
                  entry.m_pattern = (String)objs[i][0];
                  entry.m_allow = (Boolean)objs[i][1];
                  m_entries.add(entry);
              }
          }
          fireTableChanged( new TableModelEvent(this) );
          if(m_entries.isEmpty()) {
              setButtonStatus();
          }
          else {
              m_table.setRowSelectionInterval(0, 0);
          }
      }  
      
      /**
       * Cancel editing
       */
      public void cancelCellEditing() {
          if(m_table.isEditing()) {
              int row = m_table.getEditingRow();
              int col = m_table.getEditingColumn();
              if( (row != -1) && (col != -1) ) {
                  TableCellEditor editor = m_table.getCellEditor();
                  editor.cancelCellEditing();
              }
          }
      }
      
      /**
       * Stop editing
       */
      public void stopCellEditing() {
          if(m_table.isEditing()) {
              int row = m_table.getEditingRow();
              int col = m_table.getEditingColumn();
              if( (row != -1) && (col != -1) ) {
                  TableCellEditor editor = m_table.getCellEditor();
                  editor.stopCellEditing();
              }
          }
      }
  
      /**
       * If row selection changed - fire button status.
       */
      public void valueChanged(ListSelectionEvent e) {
          setButtonStatus();
      }
      
      ///////////////////////////////////////////////////////////////////////
      ///////////////////// Table Model Implementation //////////////////////
      /**
       * Add new listener.
       */
      public void addTableModelListener(TableModelListener l) {
          m_modelListeners.add(TableModelListener.class, l);
      }
      
      /**
       * Get column class.
       */
      public Class getColumnClass(int colIdx) {
          Class type = null;
          if(colIdx == 0) {
              type = String.class;
          }
          else {
              type = Boolean.class;
          }
          return type;
      }
      
      /**
       * Get column count.      
       */
      public int getColumnCount() {
          return HEADER.length;
      }
       
      /**
       * Get header name.
       */
      public String getColumnName(int col) {
          return HEADER[col];
      }
      
      /**
       * Get row count.
       */
      public int getRowCount() {
          return m_entries.size();
      }
      
      /**
       * Get value.
       */
      public Object getValueAt(int row, int col) {
          if(m_entries == null) {
              return null;
          }
          
          Entry entry = (Entry)m_entries.get(row);
          Object retVal = null;
          if(col == 0) {
              retVal = entry.m_pattern;
          }
          else {
              retVal = entry.m_allow;
          }
          return retVal;
      }
      
      /**
       * Cells are editable.
       */
      public boolean isCellEditable(int row, int col) {
          return true;
      }
      
      /**
       * Set value.
       */
      public void setValueAt(Object val, int row, int col) {
          if(m_entries == null) {
              return;
          }
          
          Entry entry = (Entry)m_entries.get(row);
          if(col == 0) {
              entry.m_pattern = (String)val;
          }
          else {
              entry.m_allow = (Boolean)val;
          }
      }
      
      /**
       * Remove listener.
       */
      public void removeTableModelListener(TableModelListener l) {
          m_modelListeners.remove(TableModelListener.class, l);
      }
      
      /**
       * Event handler.
       */
      private void fireTableChanged(TableModelEvent e) {
          Object[] listeners = m_modelListeners.getListenerList();
          for (int i = listeners.length-2; i>=0; i-=2) {
              if (listeners[i] == TableModelListener.class) {
                  ((TableModelListener)listeners[i+1]).tableChanged(e);
              }
          }
      }
              
      ///////////////////// Inner class to hold IP and permission //////////////////
      private 
      class Entry {
          public String m_pattern = "*";
          public Boolean m_allow = Boolean.TRUE;
      }
  }
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/LICENSE.txt
  
  Index: LICENSE.txt
  ===================================================================
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
      "Apache Software Foundation"  must not be used to endorse or promote
      products derived  from this  software without  prior written
      permission. For written permission, please contact apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation. For more  information on the
   Apache Software Foundation, please see <http://www.apache.org/>.
  
  
  
  
  1.1                  incubator-ftpserver/src/java/org/apache/ftpserver/gui/LoggerPanel.java
  
  Index: LoggerPanel.java
  ===================================================================
  // $Id: LoggerPanel.java,v 1.1 2005/09/07 05:04:28 rana_b Exp $
  /*
   * 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 org.apache.ftpserver.ftplet.Configuration;
  import org.apache.ftpserver.ftplet.Logger;
  import org.apache.ftpserver.interfaces.IFtpConfig;
  import org.apache.ftpserver.logger.CompositeLogger;
  import org.apache.ftpserver.util.IoUtils;
  
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.FlowLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.awt.event.ItemEvent;
  import java.awt.event.ItemListener;
  
  import javax.swing.JButton;
  import javax.swing.JComboBox;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextPane;
  import javax.swing.SwingUtilities;
  import javax.swing.text.Document;
  import javax.swing.text.SimpleAttributeSet;
  import javax.swing.text.StyleConstants;
  
  /**
   * This logger panel writes log information.
   * 
   * @author <a href="mailto:rana_b@yahoo.com">Rana Bhattacharyya</a>
   */
  public 
  class LoggerPanel extends PluginPanel implements Logger {
      
      private static final long serialVersionUID = -5197421525973377762L;
      private static final int MAX_CHARS = 8192;
      
      public static final int LEVEL_DEBUG = 0;
      public static final int LEVEL_INFO  = 1;
      public static final int LEVEL_WARN  = 2;
      public static final int LEVEL_ERROR = 3;
      public static final int LEVEL_NONE  = 4;
  
      private final static Color COLOR_DEBUG = new Color(63, 127, 95);
      private final static Color COLOR_INFO  = new Color(0, 0, 0);
      private final static Color COLOR_WARN  = new Color(245, 150, 45);
      private final static Color COLOR_ERROR = new Color(255, 0, 0);
      
      private final static String[] COMBO_LEVEL = {
              "DEBUG", 
              "INFO", 
              "WARNING", 
              "ERROR", 
              "NONE"
      };
      private final static String[] TXT_LEVEL = {
              "DEB",
              "INF",
              "WAR",
              "ERR"
      };
      
      private int m_logLevel = LEVEL_INFO;
  
      private IFtpConfig m_ftpConfig;
      
      private JComboBox m_logCombo;
      private JTextPane m_logTxt;
      private Document m_doc;
      
      private SimpleAttributeSet m_debugAttr;
      private SimpleAttributeSet m_infoAttr;
      private SimpleAttributeSet m_warnAttr;
      private SimpleAttributeSet m_errorAttr;
  
      
      /**
       * Default constructor
       */
      public LoggerPanel(PluginPanelContainer container) {
          super(container);
          
          // create style attributes
          m_debugAttr = new SimpleAttributeSet();
          StyleConstants.setForeground(m_debugAttr, COLOR_DEBUG);
          
          m_infoAttr = new SimpleAttributeSet();
          StyleConstants.setForeground(m_infoAttr, COLOR_INFO);
          
          m_warnAttr = new SimpleAttributeSet();
          StyleConstants.setForeground(m_warnAttr, COLOR_WARN);
          
          m_errorAttr = new SimpleAttributeSet();
          StyleConstants.setForeground(m_errorAttr, COLOR_ERROR);
          
          initComponents();
      }
      
      
      /**
       * Initialize UI components.
       */
      private void initComponents() {
          
          setLayout(new BorderLayout());
          
          // add top combo panel
          JPanel topPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
          add(topPanel, BorderLayout.NORTH);
          
          JLabel comboLab = new JLabel("Log Level :: ");
          comboLab.setForeground(Color.black);
          topPanel.add(comboLab);
             
          m_logCombo = new JComboBox(COMBO_LEVEL);
          m_logCombo.setSelectedIndex(m_logLevel);
          Dimension dim = new Dimension(90, 22);
          m_logCombo.setPreferredSize(dim);
          m_logCombo.setMaximumSize(dim);
          m_logCombo.setToolTipText("Set Log Level");
          m_logCombo.addItemListener(new ItemListener() {
              public void itemStateChanged(ItemEvent evt) {
                  int selIdx = m_logCombo.getSelectedIndex();
                  m_logLevel = selIdx;
              }
          });
          topPanel.add(m_logCombo);
          
              
          // add text pane
          m_logTxt = new JTextPane();
          m_logTxt.setEditable(false);
          m_doc = m_logTxt.getDocument();
          JScrollPane scrollPane = new JScrollPane(m_logTxt, 
                                                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                                   JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
          add(scrollPane, BorderLayout.CENTER);
          
          // add clear button panel
          JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
          add(bottomPanel, BorderLayout.SOUTH);
          
          JButton clearAction = new JButton("Clear");
          clearAction.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent evt) {
                  try {
                      m_doc.remove(0, m_doc.getLength());
                  }
                  catch(Exception ex) {
                      // ex.printStackTrace();
                  }
              }
           });
          bottomPanel.add(clearAction);
      }
      
      /** 
       * Refresh the ftp configuration
       */
      public void refresh(IFtpConfig ftpConfig) {
          
          // remove it from the previous one
          if(m_ftpConfig != null) {
              CompositeLogger clogger = (CompositeLogger)m_ftpConfig.getLogger();
              if(clogger != null) {
                  clogger.removeLogger(this);
              }
          }
          
          // add this logger now
          m_ftpConfig = ftpConfig;
          if(m_ftpConfig != null) {
              CompositeLogger clogger = (CompositeLogger)m_ftpConfig.getLogger();
              clogger.addLogger(this);
          }
      }
      
      /** 
       * This can be displayed only when the server is running.
       */
      public boolean canBeDisplayed() {
          return (m_ftpConfig != null);
      }
  
      
      /**
       * Get the string representation.
       */
      public String toString() {
          return "Log";
      }
      
      
      /**
       * Get current log level
       */
      public int getLogLevel() {
          return m_logLevel;
      }
      
      
      /**
       * Set log level
       */
      public void setLogLevel(int level) {
          m_logLevel = level;
          m_logCombo.setSelectedIndex(level);
      }
      
      /**
       * Set logger - does nothing
       */
      public void setLogger(Logger logger) {
      }
      
      /**
       * Configure - does nothing.
       */
      public void configure(Configuration conf) {
      }
      
      /**
       * Dispose - does nothing
       */
      public void dispose() {
      }
      
      /**
       * Write string
       */
      private void writeString(int logLevel, String msg) {
          try {
              int docLen = m_doc.getLength();
              if(docLen > MAX_CHARS) {
                  m_doc.remove(0, docLen);
                  docLen = 0;
              }
              
              switch(logLevel) {
                  case LEVEL_DEBUG:
                      m_doc.insertString(docLen, msg, m_debugAttr);
                      break;
                      
                  case LEVEL_INFO:
                      m_doc.insertString(docLen, msg, m_infoAttr);
                      break;   
                      
                  case LEVEL_WARN:
                      m_doc.insertString(docLen, msg, m_warnAttr);
                      break;
                      
                  case LEVEL_ERROR:
                      m_doc.insertString(docLen, msg, m_errorAttr);
                      break;
              }
          }
          catch(Exception ex) {
              ex.printStackTrace();
          }        
      }
      
      /**
       * Log message
       */
      private void log(int logLevel, String msg) {
  
          // check message
          if( (msg == null) || msg.equals("") ) {
              return;
          }
          
          // write message
          writeString(logLevel, '[' + TXT_LEVEL[logLevel] + "] " + msg + '\n');
      }
      
      /**
       * Log throwable
       */
      private void log(int logLevel, String msg, Throwable th) {
          log(logLevel, msg);
          writeString(logLevel, IoUtils.getStackTrace(th));
      }
      
      /**
       * Debug message
       */
      public void debug(final String msg) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_DEBUG) {
                      log(LEVEL_DEBUG, msg);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      } 
      
      /**
       * Debug message - throwable
       */
      public void debug(final String msg, final Throwable th) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_DEBUG) {
                      log(LEVEL_DEBUG, msg, th);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
          
      /**
       * Info message
       */
      public void info(final String msg) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_INFO) {
                      log(LEVEL_INFO, msg);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
      
      /**
       * Info message - throwable
       */
      public void info(final String msg, final Throwable th) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_INFO) {
                      log(LEVEL_INFO, msg, th);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
          
      /**
       * Warning message
       */
      public void warn(final String msg) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_WARN) {
                      log(LEVEL_WARN, msg);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
      
      /**
       * Warning message - throwable
       */
      public void warn(final String msg, final Throwable th) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_WARN) {
                      log(LEVEL_WARN, msg, th);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
      
      /**
       * Write error message
       */
      public void error(final String msg) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_ERROR) {
                      log(LEVEL_ERROR, msg);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
      
      /**
       * Error message - throwable
       */
      public void error(final String msg, final Throwable th) {
          Runnable runnable = new Runnable() {
              public void run() { 
                  if(m_logLevel <= LEVEL_ERROR) {
                      log(LEVEL_ERROR, msg, th);
                  }        
              }
          };
          SwingUtilities.invokeLater(runnable);
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@incubator.apache.org
For additional commands, e-mail: cvs-help@incubator.apache.org


Mime
View raw message