Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jsd/ftp/server/ftp/gui/FtpTree.java


1   /*
2    * ----------------------------------------------------------------------------
3    * JStrangeDownloader and all accompanying source code files are
4    * Copyright (C) 2002 Dusty Davidson (dustyd@iastate.edu)
5    * 
6    * This program is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU General Public License
8    * as published by the Free Software Foundation; either version 2
9    * of the License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19   * ----------------------------------------------------------------------------
20   *  
21   * Please see gpl.txt for the full text of the GNU General Public
22   * License.
23   */
24  
25  package jsd.ftp.server.ftp.gui;
26  
27  
28  import java.util.Vector;
29  import javax.swing.*;
30  import javax.swing.JTree;
31  import javax.swing.JPanel;
32  import javax.swing.tree.TreePath;
33  import javax.swing.tree.TreeModel;
34  import javax.swing.tree.DefaultTreeCellRenderer;
35  import javax.swing.event.TreeModelListener;
36  
37  import jsd.ftp.server.ftp.FtpServer; 
38  import jsd.ftp.server.ftp.FtpConfig;
39  
40  import jsd.gui.*;
41  
42  /* modification by dusty, 7/1/02 
43   * i hope to be able to add the options for strangedownloader to this,
44   * and then have the ftp options be a tree under "ftp options"
45   */
46  
47  
48  /**
49   * This is FTP user interface tree structure. Currently it is very simple.
50   * It looks like:
51   * <pre>
52   *   FTP
53   *    |
54   *    +-- User (User management)
55   *    |
56   *    +-- Ip (IP restrictions)
57   *    |
58   *    +-- Connection (Connection monitor)
59   *    |
60   *    +-- Spy (Spy user activities)
61   *    |
62   *    +-- Statistics (Global statistics)
63   *    |
64   *    +-- Upload (File upload statistics)
65   *    |
66   *    +-- Download (File download statistics)
67   *    |
68   *    +-- Delete (File deletion statistics)
69   *    |
70   *    +-- About (Ftp server summary)
71   * </pre>
72   */
73  
74  public
75  class FtpTree extends JTree implements TreeModel {
76      
77      public final static String[] CHILDREN = {
78          "User",
79          "IP",
80          "Connection",
81          "Spy",
82          "Statistics",
83          "Upload",
84          "Download",
85          "Delete",
86          "About"    
87      }; 
88      
89      public final static String[] JSDCHILDREN = {
90          "Telnet Options",
91          "FTP Server Options",
92          "Download Options",
93          FtpServer.NAME,
94          "About"    
95      }; 
96      
97      private String optionString = "JSD Options";
98      
99      private Vector mListenrList;
100     
101     private FtpRootPanel mRootPanel;
102     private OptionsRoot optionsRoot;
103     private PluginPanel[] mPluginPanels;
104     
105     private JPanel[] optionPanels;
106     
107     
108     /**
109      * create this tree model
110      */
111     public FtpTree() {
112         mListenrList = new Vector();
113         setModel(this);
114         
115         setSelectionPath(new TreePath(FtpServer.NAME));
116         putClientProperty("JTree.lineStyle", "Angled");
117         
118         DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
119         renderer.setLeafIcon(null);
120         renderer.setOpenIcon(null);
121         renderer.setClosedIcon(null);
122         setCellRenderer(renderer);
123         
124         optionsRoot = new OptionsRoot();
125         
126         mRootPanel = new FtpRootPanel(this);
127         initPlugins();
128     }
129     
130     /**
131      * Initialize all plugin panels
132      */
133     private void initPlugins() {
134         mPluginPanels = new PluginPanel[CHILDREN.length];
135         
136         mPluginPanels[0] = new FtpUserPanel(this);
137         mPluginPanels[1] = new FtpIpPanel(this);
138         mPluginPanels[2] = new FtpConnectionPanel(this);
139         mPluginPanels[3] = new FtpSpyContainerPanel(this);
140         mPluginPanels[4] = new FtpStatisticsPanel(this);
141         mPluginPanels[5] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getUploadModel(),   "Uploaded Files");
142         mPluginPanels[6] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getDownloadModel(), "Downloaded Files");
143         mPluginPanels[7] = new FtpFilePanel(this, ((FtpStatisticsPanel)mPluginPanels[4]).getDeleteModel(),   "Deleted Files");
144         mPluginPanels[8] = new FtpAboutPanel(this);
145         
146         optionPanels = new JPanel[3];
147         optionPanels[0] = new TelnetOptionsPane();       
148        
149      optionPanels[1] = new FtpOptionsPane();   
150 
151        optionPanels[2] = new DownloadsOptionsPane();   
152 
153     }
154     
155 
156     /**
157      * get root object
158      */
159     public Object getRoot() {
160 //        return FtpServer.NAME;
161         return optionString;
162     }
163 
164     /** 
165      * get child object
166      */
167     public Object getChild(Object parent, int index) {
168         if(parent.equals(FtpServer.NAME))
169         {
170           return CHILDREN[index];
171       }
172       else
173       {
174         return JSDCHILDREN[index];  
175       }
176     } 
177 
178     /**
179      * get child count
180      */
181     public int getChildCount(Object parent) {
182         if(parent.equals(FtpServer.NAME)) {
183             return CHILDREN.length;
184         }
185         else
186         {
187            return JSDCHILDREN.length;     
188         }
189        
190     }
191 
192     /**
193      * is a leaf or node
194      */
195     public boolean isLeaf(Object node) {
196        return !node.equals(FtpServer.NAME) && !node.equals(optionString);
197     }
198 
199     /**
200      * get child index
201      */
202     public int getIndexOfChild(Object parent, Object child) {
203        int childIdx = -1;
204        for(int i=0; i<CHILDREN.length; i++) {
205            if(CHILDREN[i].equals(child)) {
206                childIdx = i;
207            return childIdx;
208            }
209        }
210        childIdx = -1;
211        for(int i=0; i<JSDCHILDREN.length; i++) {
212            if(JSDCHILDREN[i].equals(child)) {
213                childIdx = i;
214            return childIdx;
215            }
216        }
217   
218      return childIdx;
219     }
220 
221     /**
222      * Object changed. In our case it is not possible - so igmore it.
223      */
224     public void valueForPathChanged(TreePath path, Object newValue) {
225     }
226 
227     /**
228      * add a listener
229      */
230     public void addTreeModelListener(TreeModelListener l) {
231         mListenrList.add(l);
232     }
233 
234     /**
235      * remove a listener
236      */
237     public void removeTreeModelListener(TreeModelListener l) {
238         mListenrList.remove(l);
239     }
240     
241     /**
242      * Refresh all panels
243      */
244     public void refresh(FtpConfig config) {
245         for(int i=0; i<mPluginPanels.length; i++) {
246             mPluginPanels[i].refresh(config);
247         }
248     }
249     
250     /**
251      * Get root panel.
252      */
253     public FtpRootPanel getRootPanel() {
254         System.out.println ("getRootPanel()");
255         return mRootPanel;
256         
257     }
258     /**
259      * Get options root panel.
260      */
261     public JPanel getOptionsRoot() {
262 //        System.out.println ("getRootPanel()");
263         return optionsRoot;
264         
265     }
266     
267     /**
268      * Get plugin panel.
269      */
270     public PluginPanel getPluginPanel(String panelName) {
271         PluginPanel panel = null;
272         for(int i=0; i<CHILDREN.length; i++) {
273             if (CHILDREN[i].equals(panelName)) {
274                 panel = mPluginPanels[i];
275                 break;
276             }
277         }
278         return panel;
279     }
280      
281      
282     /**
283      * Get the selected panel.
284      */ 
285     public JPanel getSelectedPanel() {
286         Object node = getSelectionPath().getLastPathComponent();
287         
288    
289         JPanel dispPane = null; 
290         if(node.equals("User") || node.equals("IP") || node.equals("Connection") || node.equals("Spy")
291            || node.equals("Statistics") || node.equals(FtpServer.NAME) || node.equals("Upload") || node.equals("Download") || node.equals("Delete") || node.equals("About"))
292          {
293         
294         if(getRoot().equals(node)) {
295             dispPane = mRootPanel;
296         }
297         else {
298             dispPane = getPluginPanel(node.toString());
299             if ( (dispPane == null) || (!dispPane.isDisplayable()) ) {
300                 dispPane = mRootPanel;
301 //          dispPane = optionsRoot;
302             }
303         }
304          }
305          else
306          {
307            if(node.equals("Download Options"))
308            {
309              dispPane = optionPanels[2];
310            }
311            else if(node.equals("Telnet Options"))
312            {
313              dispPane = optionPanels[0];
314            }
315            else if(node.equals("FTP Server Options"))
316            {
317              dispPane = optionPanels[1];
318            }
319            else
320            {
321              dispPane = optionsRoot;  
322            }
323          }
324         
325         return dispPane;
326     } 
327      
328 }