client/ftpd/src/se/lu/thep/coreftpd/common/JFolderChooser.java

Code
Comments
Other
Rev Date Author Line
741 10 Oct 06 olle 1 /*
1652 22 May 07 gregory 2  $Id$
741 10 Oct 06 olle 3
1916 31 Aug 07 jari 4  Copyright (C) 2006 Olle Mansson
1916 31 Aug 07 jari 5  Copyright (C) 2007 Gregory Vincic
741 10 Oct 06 olle 6
1652 22 May 07 gregory 7  This file is part of Proteios.
1652 22 May 07 gregory 8  Available at http://www.proteios.org/
741 10 Oct 06 olle 9
1652 22 May 07 gregory 10  Proteios is free software; you can redistribute it and/or modify it
1652 22 May 07 gregory 11  under the terms of the GNU General Public License as published by
1652 22 May 07 gregory 12  the Free Software Foundation; either version 2 of the License, or
1652 22 May 07 gregory 13  (at your option) any later version.
741 10 Oct 06 olle 14
1652 22 May 07 gregory 15  Proteios is distributed in the hope that it will be useful, but
1652 22 May 07 gregory 16  WITHOUT ANY WARRANTY; without even the implied warranty of
1652 22 May 07 gregory 17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1652 22 May 07 gregory 18  General Public License for more details.
741 10 Oct 06 olle 19
1652 22 May 07 gregory 20  You should have received a copy of the GNU General Public License
1652 22 May 07 gregory 21  along with this program; if not, write to the Free Software
1652 22 May 07 gregory 22  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1652 22 May 07 gregory 23  02111-1307, USA.
1652 22 May 07 gregory 24  */
741 10 Oct 06 olle 25
741 10 Oct 06 olle 26 //  Xerver Free Web Server
741 10 Oct 06 olle 27 //  Copyright (C) 2002-2005 Omid Rouhani
741 10 Oct 06 olle 28 //
741 10 Oct 06 olle 29 //
741 10 Oct 06 olle 30 //  This program is free software; you can redistribute it and/or
741 10 Oct 06 olle 31 //  modify it under the terms of the GNU General Public License
741 10 Oct 06 olle 32 //  as published by the Free Software Foundation; either version 2
741 10 Oct 06 olle 33 //  of the License, or (at your option) any later version.
741 10 Oct 06 olle 34 //
741 10 Oct 06 olle 35 //  This program is distributed in the hope that it will be useful,
741 10 Oct 06 olle 36 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
741 10 Oct 06 olle 37 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
741 10 Oct 06 olle 38 //  GNU General Public License for more details.
741 10 Oct 06 olle 39 //
741 10 Oct 06 olle 40 //  You should have received a copy of the GNU General Public License
741 10 Oct 06 olle 41 //  along with this program; if not, write to the Free Software
741 10 Oct 06 olle 42 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
741 10 Oct 06 olle 43 //
741 10 Oct 06 olle 44 //
741 10 Oct 06 olle 45 //  #############################################################
741 10 Oct 06 olle 46 //  ##  YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT:          ##
741 10 Oct 06 olle 47 //  ##  HTTP://WWW.JAVASCRIPT.NU/XERVER/                       ##
741 10 Oct 06 olle 48 //  ##                                                         ##
741 10 Oct 06 olle 49 //  ##  IF YOUR SOFTWARE IS NOT RELEASED UNDER THE             ##
741 10 Oct 06 olle 50 //  ##  GNU GENERAL PUBLIC LICENSE (GPL),                      ##
741 10 Oct 06 olle 51 //  ##  PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!!   ##
741 10 Oct 06 olle 52 //  ##                                                         ##
741 10 Oct 06 olle 53 //  ##  FOR FULL LICENSE, PLEASE READ "XERVER LICENSE".        ##
741 10 Oct 06 olle 54 //  #############################################################
741 10 Oct 06 olle 55
1652 22 May 07 gregory 56 package se.lu.thep.coreftpd.common;
741 10 Oct 06 olle 57
791 23 Oct 06 olle 58 import se.lu.thep.coreftpd.webserver.MyFile;
791 23 Oct 06 olle 59 import se.lu.thep.coreftpd.webserver.PathInfo;
741 10 Oct 06 olle 60 import java.awt.Container;
741 10 Oct 06 olle 61 import java.awt.GridLayout;
741 10 Oct 06 olle 62 import javax.swing.JList;
741 10 Oct 06 olle 63 import javax.swing.JScrollPane;
741 10 Oct 06 olle 64 import javax.swing.ListSelectionModel;
741 10 Oct 06 olle 65 import javax.swing.event.ListSelectionListener;
741 10 Oct 06 olle 66
741 10 Oct 06 olle 67 /**
1652 22 May 07 gregory 68  * 
1652 22 May 07 gregory 69  * <B>About this class:</B> <BR>
1652 22 May 07 gregory 70  * <CODE>JFolderChooser</CODE> is used to get a JList in which the user can
1652 22 May 07 gregory 71  * choose a folder/root (drive) (see constuctor). <BR>
1652 22 May 07 gregory 72  * This can be used to decide in which drive and in which folder Xerver shall be
1652 22 May 07 gregory 73  * installed.
1652 22 May 07 gregory 74  * 
741 10 Oct 06 olle 75  * @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a>
741 10 Oct 06 olle 76  * @version 1.0
741 10 Oct 06 olle 77  */
1223 18 Feb 07 gregory 78 @SuppressWarnings("serial")
1652 22 May 07 gregory 79 final public class JFolderChooser extends Container {
741 10 Oct 06 olle 80   private JList theJList;
1652 22 May 07 gregory 81
741 10 Oct 06 olle 82   private JScrollPane JSP;
1652 22 May 07 gregory 83
741 10 Oct 06 olle 84   private ListSelectionListener theLSL;
1652 22 May 07 gregory 85
1652 22 May 07 gregory 86   private MyFile[] listOfFiles;
1652 22 May 07 gregory 87
741 10 Oct 06 olle 88   private String s_location;
741 10 Oct 06 olle 89
1652 22 May 07 gregory 90   /**
1652 22 May 07 gregory 91    * If argLocation==null all roots (for example c:\ and d:\) will be listed.
1652 22 May 07 gregory 92    */
1652 22 May 07 gregory 93   public JFolderChooser(String argLocation) {
1652 22 May 07 gregory 94     s_location = argLocation;
1652 22 May 07 gregory 95     setLayout(new GridLayout(1, 1));
741 10 Oct 06 olle 96     setNewPath(s_location);
741 10 Oct 06 olle 97   }
741 10 Oct 06 olle 98
1652 22 May 07 gregory 99   /**
1652 22 May 07 gregory 100    * Add a ListSelectionListener to the JList inside this JFolderChooser.
1652 22 May 07 gregory 101    */
1652 22 May 07 gregory 102   public void addListSelectionListener(ListSelectionListener argLSL) {
1652 22 May 07 gregory 103     theLSL = argLSL;
741 10 Oct 06 olle 104     theJList.addListSelectionListener(theLSL);
741 10 Oct 06 olle 105   }
741 10 Oct 06 olle 106
1652 22 May 07 gregory 107   /**
1652 22 May 07 gregory 108    * Choose which folder shall be listed.
1652 22 May 07 gregory 109    */
4415 20 Feb 13 olle 110   @SuppressWarnings("unchecked")
1652 22 May 07 gregory 111   public void setNewPath(String argLocation) {
1652 22 May 07 gregory 112     s_location = argLocation;
741 10 Oct 06 olle 113     removeAll();
1652 22 May 07 gregory 114     listOfFiles = (new PathInfo(s_location)).getAllDirsWithReadAccess();
1652 22 May 07 gregory 115     theJList = new JList(listOfFiles);
741 10 Oct 06 olle 116     theJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
1652 22 May 07 gregory 117     // theJList.addMouseListener(new myMouseListener());
1652 22 May 07 gregory 118     JSP = new JScrollPane(theJList);
741 10 Oct 06 olle 119
741 10 Oct 06 olle 120     add(JSP);
741 10 Oct 06 olle 121
1652 22 May 07 gregory 122     if (theLSL != null)
741 10 Oct 06 olle 123       theJList.addListSelectionListener(theLSL);
741 10 Oct 06 olle 124   }
741 10 Oct 06 olle 125
1652 22 May 07 gregory 126   /**
1652 22 May 07 gregory 127    * This simply returns the object which holds in this data. As
1652 22 May 07 gregory 128    * JFolderChooser is written now this always returns a JList. However, in
1652 22 May 07 gregory 129    * case someone choose to write a subclass of JFolderChooser with for
1652 22 May 07 gregory 130    * example a JTree (instead of a JList) this method might always return an
1652 22 May 07 gregory 131    * JTree.
1652 22 May 07 gregory 132    */
1652 22 May 07 gregory 133   public Object getDataContainer() {
741 10 Oct 06 olle 134     return theJList;
741 10 Oct 06 olle 135   }
741 10 Oct 06 olle 136
1652 22 May 07 gregory 137   /**
1652 22 May 07 gregory 138    * Set how many rows shall be viewable in the JList.
1652 22 May 07 gregory 139    */
1652 22 May 07 gregory 140   public void setVisibleRowCount(int nr) {
741 10 Oct 06 olle 141     theJList.setVisibleRowCount(nr);
741 10 Oct 06 olle 142   }
741 10 Oct 06 olle 143
1652 22 May 07 gregory 144   /**
1652 22 May 07 gregory 145    * Returns a MyFile for the entry at index "nr".
1652 22 May 07 gregory 146    */
1652 22 May 07 gregory 147   public MyFile getFileAtIndex(int nr) {
741 10 Oct 06 olle 148     return listOfFiles[nr];
741 10 Oct 06 olle 149   }
741 10 Oct 06 olle 150
1652 22 May 07 gregory 151   /**
1652 22 May 07 gregory 152    * Get the path for the folder/root which the user has currently choosed.
1652 22 May 07 gregory 153    */
1652 22 May 07 gregory 154   public String getPath() {
741 10 Oct 06 olle 155     return s_location;
741 10 Oct 06 olle 156   }
741 10 Oct 06 olle 157 }