741 |
10 Oct 06 |
olle |
1 |
/* |
1652 |
22 May 07 |
gregory |
$Id$ |
741 |
10 Oct 06 |
olle |
3 |
|
1916 |
31 Aug 07 |
jari |
Copyright (C) 2006 Olle Mansson |
1916 |
31 Aug 07 |
jari |
Copyright (C) 2007 Gregory Vincic |
741 |
10 Oct 06 |
olle |
6 |
|
1652 |
22 May 07 |
gregory |
This file is part of Proteios. |
1652 |
22 May 07 |
gregory |
Available at http://www.proteios.org/ |
741 |
10 Oct 06 |
olle |
9 |
|
1652 |
22 May 07 |
gregory |
Proteios is free software; you can redistribute it and/or modify it |
1652 |
22 May 07 |
gregory |
under the terms of the GNU General Public License as published by |
1652 |
22 May 07 |
gregory |
the Free Software Foundation; either version 2 of the License, or |
1652 |
22 May 07 |
gregory |
(at your option) any later version. |
741 |
10 Oct 06 |
olle |
14 |
|
1652 |
22 May 07 |
gregory |
Proteios is distributed in the hope that it will be useful, but |
1652 |
22 May 07 |
gregory |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1652 |
22 May 07 |
gregory |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1652 |
22 May 07 |
gregory |
General Public License for more details. |
741 |
10 Oct 06 |
olle |
19 |
|
1652 |
22 May 07 |
gregory |
You should have received a copy of the GNU General Public License |
1652 |
22 May 07 |
gregory |
along with this program; if not, write to the Free Software |
1652 |
22 May 07 |
gregory |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
1652 |
22 May 07 |
gregory |
02111-1307, USA. |
1652 |
22 May 07 |
gregory |
24 |
*/ |
741 |
10 Oct 06 |
olle |
25 |
|
741 |
10 Oct 06 |
olle |
// Xerver Free Web Server |
741 |
10 Oct 06 |
olle |
// Copyright (C) 2002-2005 Omid Rouhani |
741 |
10 Oct 06 |
olle |
28 |
// |
741 |
10 Oct 06 |
olle |
29 |
// |
741 |
10 Oct 06 |
olle |
// This program is free software; you can redistribute it and/or |
741 |
10 Oct 06 |
olle |
// modify it under the terms of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// as published by the Free Software Foundation; either version 2 |
741 |
10 Oct 06 |
olle |
// of the License, or (at your option) any later version. |
741 |
10 Oct 06 |
olle |
34 |
// |
741 |
10 Oct 06 |
olle |
// This program is distributed in the hope that it will be useful, |
741 |
10 Oct 06 |
olle |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
741 |
10 Oct 06 |
olle |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
741 |
10 Oct 06 |
olle |
// GNU General Public License for more details. |
741 |
10 Oct 06 |
olle |
39 |
// |
741 |
10 Oct 06 |
olle |
// You should have received a copy of the GNU General Public License |
741 |
10 Oct 06 |
olle |
// along with this program; if not, write to the Free Software |
741 |
10 Oct 06 |
olle |
// 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 |
// ## YOU CAN CONTACT THE AUTHOR (OMID ROUHANI) AT: ## |
741 |
10 Oct 06 |
olle |
// ## HTTP://WWW.JAVASCRIPT.NU/XERVER/ ## |
741 |
10 Oct 06 |
olle |
48 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## IF YOUR SOFTWARE IS NOT RELEASED UNDER THE ## |
741 |
10 Oct 06 |
olle |
// ## GNU GENERAL PUBLIC LICENSE (GPL), ## |
741 |
10 Oct 06 |
olle |
// ## PLEASE DO NOT COPY ANYTHING FROM THIS SOURCE CODE!!! ## |
741 |
10 Oct 06 |
olle |
52 |
// ## ## |
741 |
10 Oct 06 |
olle |
// ## 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 |
* <B>About this class:</B> <BR> |
1652 |
22 May 07 |
gregory |
* <CODE>JFolderChooser</CODE> is used to get a JList in which the user can |
1652 |
22 May 07 |
gregory |
* choose a folder/root (drive) (see constuctor). <BR> |
1652 |
22 May 07 |
gregory |
* This can be used to decide in which drive and in which folder Xerver shall be |
1652 |
22 May 07 |
gregory |
* installed. |
1652 |
22 May 07 |
gregory |
74 |
* |
741 |
10 Oct 06 |
olle |
* @author <a href="http://www.JavaScript.nu/xerver/" TARGET="_top">Omid Rouhani</a> |
741 |
10 Oct 06 |
olle |
* @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 |
* 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 |
* 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 |
* 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 |
// 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 |
* This simply returns the object which holds in this data. As |
1652 |
22 May 07 |
gregory |
* JFolderChooser is written now this always returns a JList. However, in |
1652 |
22 May 07 |
gregory |
* case someone choose to write a subclass of JFolderChooser with for |
1652 |
22 May 07 |
gregory |
* example a JTree (instead of a JList) this method might always return an |
1652 |
22 May 07 |
gregory |
* 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 |
* 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 |
* 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 |
* 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 |
} |