svn-gvsig-desktop / tags / v10_RC2c / libraries / libCorePlugin / src / com / iver / core / preferences / general / FolderingPage.java @ 8745
History | View | Annotate | Download (9.12 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: FolderingPage.java 8745 2006-11-14 13:14:23Z $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.5 2006-09-21 07:52:02 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.6 2006/09/13 16:21:00 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.5 2006/09/12 12:09:51 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.4 2006/09/12 11:49:04 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.3 2006/09/12 10:11:25 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
*
|
65 |
*/
|
66 |
package com.iver.core.preferences.general; |
67 |
|
68 |
import java.awt.event.ActionEvent; |
69 |
import java.awt.event.ActionListener; |
70 |
import java.io.File; |
71 |
import java.util.prefs.Preferences; |
72 |
|
73 |
import javax.swing.ImageIcon; |
74 |
import javax.swing.JFileChooser; |
75 |
import javax.swing.JLabel; |
76 |
import javax.swing.JPanel; |
77 |
import javax.swing.JTextField; |
78 |
import javax.swing.filechooser.FileFilter; |
79 |
|
80 |
import org.gvsig.gui.beans.swing.JButton; |
81 |
|
82 |
import com.iver.andami.PluginServices; |
83 |
import com.iver.andami.preferences.AbstractPreferencePage; |
84 |
import com.iver.andami.preferences.StoreException; |
85 |
import com.iver.utiles.XMLEntity; |
86 |
/**
|
87 |
*
|
88 |
* In the FolderingPage the user sets which folder paths should be used by
|
89 |
* default.
|
90 |
*
|
91 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
92 |
*
|
93 |
*/
|
94 |
public class FolderingPage extends AbstractPreferencePage{ |
95 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
96 |
|
97 |
private static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
98 |
private static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
99 |
private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
100 |
private JTextField txtProjectsFolder; |
101 |
private JTextField txtDataFolder; |
102 |
private JTextField txtTemplatesFolder; |
103 |
private JButton btnSelectProjectsFolder; |
104 |
private JButton btnSelectDataFolder; |
105 |
private JButton btnSelectTemplatesFolder; |
106 |
private ImageIcon icon; |
107 |
private ActionListener btnFileChooserAction; |
108 |
|
109 |
public FolderingPage() {
|
110 |
super();
|
111 |
setParentID(GeneralPage.id); |
112 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/folder.png")); |
113 |
|
114 |
btnFileChooserAction = new ActionListener() { |
115 |
public void actionPerformed(ActionEvent e) { |
116 |
String path;
|
117 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
118 |
path = txtProjectsFolder.getText(); |
119 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
120 |
path = txtDataFolder.getText(); |
121 |
} else {
|
122 |
path = txtTemplatesFolder.getText(); |
123 |
} |
124 |
|
125 |
// The file filter for the JFileChooser
|
126 |
FileFilter def = new FileFilter(){ |
127 |
public boolean accept(File f) { |
128 |
return (f.isDirectory());
|
129 |
} |
130 |
|
131 |
public String getDescription() { |
132 |
return null; |
133 |
} |
134 |
}; |
135 |
|
136 |
File file = new File(path); |
137 |
JFileChooser fc = new JFileChooser(path); |
138 |
|
139 |
|
140 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
141 |
fc.setMultiSelectionEnabled(false);
|
142 |
fc.setAcceptAllFileFilterUsed(false);
|
143 |
fc.addChoosableFileFilter(def); |
144 |
int result = fc.showOpenDialog(FolderingPage.this);
|
145 |
|
146 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
147 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
148 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
149 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
150 |
txtDataFolder.setText(file.getAbsolutePath()); |
151 |
} else {
|
152 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
}; |
158 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
159 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
160 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
161 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
162 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
163 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
164 |
|
165 |
|
166 |
JLabel lblProjectsFolder = new JLabel("<html><b>" + |
167 |
PluginServices. |
168 |
getText(this, "options.foldering.projects_folder") + |
169 |
"</b></html>");
|
170 |
addComponent(lblProjectsFolder); |
171 |
addComponent(txtProjectsFolder = new JTextField(40), btnSelectProjectsFolder); |
172 |
addComponent(new JLabel(" ")); |
173 |
|
174 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
175 |
PluginServices. |
176 |
getText(this, "options.foldering.data_folder") + |
177 |
"</b></html>");
|
178 |
addComponent(lblDataFolder); |
179 |
addComponent(txtDataFolder = new JTextField(40), btnSelectDataFolder); |
180 |
addComponent(new JLabel(" ")); |
181 |
|
182 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
183 |
PluginServices. |
184 |
getText(this, "options.foldering.template_folder") + |
185 |
"</b></html>");
|
186 |
addComponent(lblTemplatesFolder); |
187 |
addComponent(txtTemplatesFolder = new JTextField(40), btnSelectTemplatesFolder); |
188 |
addComponent(new JLabel(" ")); |
189 |
|
190 |
PluginServices ps = PluginServices.getPluginServices(this);
|
191 |
XMLEntity xml = ps.getPersistentXML(); |
192 |
|
193 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
194 |
prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
195 |
} |
196 |
|
197 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
198 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
199 |
} |
200 |
|
201 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
202 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
203 |
} |
204 |
|
205 |
} |
206 |
|
207 |
public void storeValues() throws StoreException { |
208 |
File f;
|
209 |
String path, propertyName;
|
210 |
PluginServices ps = PluginServices.getPluginServices(this);
|
211 |
XMLEntity xml = ps.getPersistentXML(); |
212 |
|
213 |
// Projects folder
|
214 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
215 |
path = txtProjectsFolder.getText(); |
216 |
|
217 |
if (path.equals("")) { |
218 |
if (xml.contains(propertyName)) {
|
219 |
xml.remove(propertyName); |
220 |
} |
221 |
prefs.remove(propertyName); |
222 |
} else {
|
223 |
f = new File(path); |
224 |
if (f.exists()) {
|
225 |
if (xml.contains(propertyName)) {
|
226 |
xml.remove(propertyName); |
227 |
} |
228 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
229 |
prefs.put(propertyName, f.getAbsolutePath()); |
230 |
} |
231 |
} |
232 |
|
233 |
// Data folder
|
234 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
235 |
path = txtDataFolder.getText(); |
236 |
|
237 |
if (path.equals("")) { |
238 |
if (xml.contains(propertyName)) {
|
239 |
xml.remove(propertyName); |
240 |
} |
241 |
prefs.remove(propertyName); |
242 |
} else {
|
243 |
f = new File(path); |
244 |
if (f.exists()) {
|
245 |
if (xml.contains(propertyName)) {
|
246 |
xml.remove(propertyName); |
247 |
} |
248 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
249 |
prefs.put(propertyName, f.getAbsolutePath()); |
250 |
|
251 |
} |
252 |
} |
253 |
|
254 |
// Templates folder
|
255 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
256 |
path = txtTemplatesFolder.getText(); |
257 |
|
258 |
if (path.equals("")) { |
259 |
if (xml.contains(propertyName)) {
|
260 |
xml.remove(propertyName); |
261 |
} |
262 |
prefs.remove(propertyName); |
263 |
} else {
|
264 |
f = new File(path); |
265 |
if (f.exists()) {
|
266 |
if (xml.contains(propertyName)) {
|
267 |
xml.remove(propertyName); |
268 |
} |
269 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
270 |
prefs.put(propertyName, f.getAbsolutePath()); |
271 |
|
272 |
} |
273 |
} |
274 |
|
275 |
} |
276 |
|
277 |
public void setChangesApplied() { |
278 |
setChanged(false);
|
279 |
} |
280 |
|
281 |
public String getID() { |
282 |
return this.getClass().getName(); |
283 |
} |
284 |
|
285 |
public String getTitle() { |
286 |
return PluginServices.getText(this, "options.foldering.title"); |
287 |
} |
288 |
|
289 |
public JPanel getPanel() { |
290 |
return this; |
291 |
} |
292 |
|
293 |
public void initializeValues() { |
294 |
PluginServices ps = PluginServices.getPluginServices(this);
|
295 |
XMLEntity xml = ps.getPersistentXML(); |
296 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
297 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
298 |
} |
299 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
300 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
301 |
} |
302 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
303 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
304 |
} |
305 |
|
306 |
} |
307 |
|
308 |
public void initializeDefaults() { |
309 |
txtDataFolder.setText("");
|
310 |
txtTemplatesFolder.setText("");
|
311 |
} |
312 |
|
313 |
public ImageIcon getIcon() { |
314 |
return icon;
|
315 |
} |
316 |
|
317 |
public boolean isValueChanged() { |
318 |
return super.hasChanged(); |
319 |
} |
320 |
|
321 |
} |