root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / FolderingPage.java @ 38564
History | View | Annotate | Download (11.1 KB)
1 | 7186 | jaume | /* 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$
|
||
45 | * $Log$
|
||
46 | 9931 | jaume | * Revision 1.8 2007-01-26 13:35:06 jaume
|
47 | 7186 | jaume | * *** empty log message ***
|
48 | *
|
||
49 | 9931 | jaume | * Revision 1.7 2006/10/02 07:12:12 jaume
|
50 | * *** empty log message ***
|
||
51 | *
|
||
52 | 7709 | jaume | * Revision 1.6 2006/09/13 16:21:00 jaume
|
53 | * *** empty log message ***
|
||
54 | *
|
||
55 | 7251 | jaume | * Revision 1.5 2006/09/12 12:09:51 jaume
|
56 | * *** empty log message ***
|
||
57 | *
|
||
58 | 7214 | jaume | * Revision 1.4 2006/09/12 11:49:04 jaume
|
59 | * *** empty log message ***
|
||
60 | *
|
||
61 | 7211 | jaume | * Revision 1.3 2006/09/12 10:11:25 jaume
|
62 | * *** empty log message ***
|
||
63 | *
|
||
64 | 7186 | jaume | * Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
65 | * *** empty log message ***
|
||
66 | *
|
||
67 | *
|
||
68 | */
|
||
69 | 29630 | jpiera | package org.gvsig.coreplugin.preferences.general; |
70 | 7186 | jaume | |
71 | import java.awt.event.ActionEvent; |
||
72 | import java.awt.event.ActionListener; |
||
73 | import java.io.File; |
||
74 | import java.util.prefs.Preferences; |
||
75 | |||
76 | import javax.swing.ImageIcon; |
||
77 | import javax.swing.JFileChooser; |
||
78 | import javax.swing.JLabel; |
||
79 | import javax.swing.JPanel; |
||
80 | import javax.swing.JTextField; |
||
81 | import javax.swing.filechooser.FileFilter; |
||
82 | |||
83 | 29630 | jpiera | import org.gvsig.andami.PluginServices; |
84 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
85 | import org.gvsig.andami.preferences.StoreException; |
||
86 | 7186 | jaume | import org.gvsig.gui.beans.swing.JButton; |
87 | 29630 | jpiera | import org.gvsig.utils.XMLEntity; |
88 | 7186 | jaume | |
89 | /**
|
||
90 | *
|
||
91 | * In the FolderingPage the user sets which folder paths should be used by
|
||
92 | * default.
|
||
93 | *
|
||
94 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
95 | *
|
||
96 | */
|
||
97 | public class FolderingPage extends AbstractPreferencePage{ |
||
98 | private static Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
||
99 | |||
100 | 7211 | jaume | private static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
101 | 7186 | jaume | private static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
102 | private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
||
103 | 9931 | jaume | private static final String SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME = "SymbolLibraryFolder"; |
104 | 7211 | jaume | private JTextField txtProjectsFolder; |
105 | 7186 | jaume | private JTextField txtDataFolder; |
106 | 7211 | jaume | private JTextField txtTemplatesFolder; |
107 | 9931 | jaume | private JTextField txtSymbolLibraryFolder; |
108 | 7211 | jaume | private JButton btnSelectProjectsFolder; |
109 | 7186 | jaume | private JButton btnSelectDataFolder; |
110 | private JButton btnSelectTemplatesFolder; |
||
111 | 9931 | jaume | private JButton btnSelectSymbolLibraryFolder; |
112 | 7186 | jaume | private ImageIcon icon; |
113 | private ActionListener btnFileChooserAction; |
||
114 | 7251 | jaume | |
115 | 9931 | jaume | |
116 | |||
117 | 7186 | jaume | public FolderingPage() {
|
118 | super();
|
||
119 | 7204 | jaume | setParentID(GeneralPage.id); |
120 | 38564 | jjdelcerro | icon = PluginServices.getIconTheme().get("edit-setup-foldering");
|
121 | 7186 | jaume | |
122 | btnFileChooserAction = new ActionListener() { |
||
123 | public void actionPerformed(ActionEvent e) { |
||
124 | String path;
|
||
125 | 7211 | jaume | if (e.getSource().equals(btnSelectProjectsFolder)) {
|
126 | path = txtProjectsFolder.getText(); |
||
127 | } else if (e.getSource().equals(btnSelectDataFolder)) { |
||
128 | 7186 | jaume | path = txtDataFolder.getText(); |
129 | 9931 | jaume | } else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
130 | path = txtSymbolLibraryFolder.getText(); |
||
131 | 7186 | jaume | } else {
|
132 | path = txtTemplatesFolder.getText(); |
||
133 | } |
||
134 | |||
135 | // The file filter for the JFileChooser
|
||
136 | FileFilter def = new FileFilter(){ |
||
137 | public boolean accept(File f) { |
||
138 | return (f.isDirectory());
|
||
139 | } |
||
140 | |||
141 | public String getDescription() { |
||
142 | return null; |
||
143 | } |
||
144 | }; |
||
145 | |||
146 | File file = new File(path); |
||
147 | JFileChooser fc;
|
||
148 | if (file.exists()) {
|
||
149 | fc = new JFileChooser(file); |
||
150 | } else {
|
||
151 | fc = new JFileChooser(); |
||
152 | } |
||
153 | |||
154 | fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
||
155 | fc.setMultiSelectionEnabled(false);
|
||
156 | fc.setAcceptAllFileFilterUsed(false);
|
||
157 | fc.addChoosableFileFilter(def); |
||
158 | int result = fc.showOpenDialog(FolderingPage.this);
|
||
159 | |||
160 | if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
||
161 | 7251 | jaume | if (e.getSource().equals(btnSelectProjectsFolder)) {
|
162 | txtProjectsFolder.setText(file.getAbsolutePath()); |
||
163 | 7211 | jaume | } else if (e.getSource().equals(btnSelectDataFolder)) { |
164 | txtDataFolder.setText(file.getAbsolutePath()); |
||
165 | 35957 | jpiera | } else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
166 | txtSymbolLibraryFolder.setText(file.getAbsolutePath()); |
||
167 | 7211 | jaume | } else {
|
168 | 7186 | jaume | txtTemplatesFolder.setText(file.getAbsolutePath()); |
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | }; |
||
174 | 7251 | jaume | btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
175 | btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
||
176 | 7186 | jaume | btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
177 | btnSelectDataFolder.addActionListener(btnFileChooserAction); |
||
178 | btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
||
179 | btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
||
180 | 9931 | jaume | btnSelectSymbolLibraryFolder = new JButton(PluginServices.getText(this, "browse")); |
181 | btnSelectSymbolLibraryFolder.addActionListener(btnFileChooserAction); |
||
182 | 7186 | jaume | |
183 | |||
184 | 7211 | jaume | JLabel lblProjectsFolder = new JLabel("<html><b>" + |
185 | PluginServices. |
||
186 | getText(this, "options.foldering.projects_folder") + |
||
187 | "</b></html>");
|
||
188 | addComponent(lblProjectsFolder); |
||
189 | 7709 | jaume | addComponent(txtProjectsFolder = new JTextField(30), btnSelectProjectsFolder); |
190 | 7251 | jaume | addComponent(new JLabel(" ")); |
191 | 7211 | jaume | |
192 | 7186 | jaume | JLabel lblDataFolder = new JLabel("<html><b>" + |
193 | PluginServices. |
||
194 | 7204 | jaume | getText(this, "options.foldering.data_folder") + |
195 | 7186 | jaume | "</b></html>");
|
196 | addComponent(lblDataFolder); |
||
197 | 7709 | jaume | addComponent(txtDataFolder = new JTextField(30), btnSelectDataFolder); |
198 | 7186 | jaume | addComponent(new JLabel(" ")); |
199 | 7211 | jaume | |
200 | 7186 | jaume | JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
201 | PluginServices. |
||
202 | 7204 | jaume | getText(this, "options.foldering.template_folder") + |
203 | 7186 | jaume | "</b></html>");
|
204 | addComponent(lblTemplatesFolder); |
||
205 | 7709 | jaume | addComponent(txtTemplatesFolder = new JTextField(30), btnSelectTemplatesFolder); |
206 | 7251 | jaume | addComponent(new JLabel(" ")); |
207 | 7186 | jaume | |
208 | 9931 | jaume | JLabel lblSymbolLibraryFolder = new JLabel("<html><b>" + |
209 | PluginServices. |
||
210 | getText(this, "options.foldering.symbol_library_folder") + |
||
211 | "</b></html>");
|
||
212 | addComponent(lblSymbolLibraryFolder); |
||
213 | addComponent(txtSymbolLibraryFolder = new JTextField(30), btnSelectSymbolLibraryFolder); |
||
214 | addComponent(new JLabel(" ")); |
||
215 | 7186 | jaume | PluginServices ps = PluginServices.getPluginServices(this);
|
216 | XMLEntity xml = ps.getPersistentXML(); |
||
217 | |||
218 | 7211 | jaume | if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
219 | prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
||
220 | } |
||
221 | |||
222 | 7186 | jaume | if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
223 | prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
||
224 | } |
||
225 | |||
226 | if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
||
227 | prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
||
228 | } |
||
229 | |||
230 | 9931 | jaume | if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
231 | prefs.put(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME, xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
||
232 | } |
||
233 | |||
234 | 7186 | jaume | } |
235 | |||
236 | public void storeValues() throws StoreException { |
||
237 | File f;
|
||
238 | 7251 | jaume | String path, propertyName;
|
239 | 7186 | jaume | PluginServices ps = PluginServices.getPluginServices(this);
|
240 | XMLEntity xml = ps.getPersistentXML(); |
||
241 | |||
242 | 7251 | jaume | // Projects folder
|
243 | propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
||
244 | path = txtProjectsFolder.getText(); |
||
245 | 7211 | jaume | |
246 | 7251 | jaume | if (path.equals("")) { |
247 | 7211 | jaume | if (xml.contains(propertyName)) {
|
248 | xml.remove(propertyName); |
||
249 | } |
||
250 | 7251 | jaume | prefs.remove(propertyName); |
251 | } else {
|
||
252 | f = new File(path); |
||
253 | if (f.exists()) {
|
||
254 | if (xml.contains(propertyName)) {
|
||
255 | xml.remove(propertyName); |
||
256 | } |
||
257 | xml.putProperty(propertyName, f.getAbsolutePath()); |
||
258 | prefs.put(propertyName, f.getAbsolutePath()); |
||
259 | } |
||
260 | 7211 | jaume | } |
261 | |||
262 | 7251 | jaume | // Data folder
|
263 | propertyName = DATA_FOLDER_PROPERTY_NAME; |
||
264 | path = txtDataFolder.getText(); |
||
265 | |||
266 | if (path.equals("")) { |
||
267 | 7186 | jaume | if (xml.contains(propertyName)) {
|
268 | xml.remove(propertyName); |
||
269 | } |
||
270 | 7251 | jaume | prefs.remove(propertyName); |
271 | } else {
|
||
272 | f = new File(path); |
||
273 | if (f.exists()) {
|
||
274 | if (xml.contains(propertyName)) {
|
||
275 | xml.remove(propertyName); |
||
276 | } |
||
277 | xml.putProperty(propertyName, f.getAbsolutePath()); |
||
278 | prefs.put(propertyName, f.getAbsolutePath()); |
||
279 | 7186 | jaume | |
280 | 7251 | jaume | } |
281 | 7186 | jaume | } |
282 | |||
283 | 7251 | jaume | // Templates folder
|
284 | propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
||
285 | path = txtTemplatesFolder.getText(); |
||
286 | |||
287 | if (path.equals("")) { |
||
288 | 7186 | jaume | if (xml.contains(propertyName)) {
|
289 | xml.remove(propertyName); |
||
290 | } |
||
291 | 7251 | jaume | prefs.remove(propertyName); |
292 | } else {
|
||
293 | f = new File(path); |
||
294 | if (f.exists()) {
|
||
295 | if (xml.contains(propertyName)) {
|
||
296 | xml.remove(propertyName); |
||
297 | } |
||
298 | xml.putProperty(propertyName, f.getAbsolutePath()); |
||
299 | prefs.put(propertyName, f.getAbsolutePath()); |
||
300 | 7186 | jaume | |
301 | 7251 | jaume | } |
302 | 7186 | jaume | } |
303 | |||
304 | 9931 | jaume | // Symbol library folder
|
305 | propertyName = SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME; |
||
306 | path = txtSymbolLibraryFolder.getText(); |
||
307 | |||
308 | if (path.equals("")) { |
||
309 | if (xml.contains(propertyName)) {
|
||
310 | xml.remove(propertyName); |
||
311 | } |
||
312 | prefs.remove(propertyName); |
||
313 | } else {
|
||
314 | f = new File(path); |
||
315 | if (f.exists()) {
|
||
316 | if (xml.contains(propertyName)) {
|
||
317 | xml.remove(propertyName); |
||
318 | } |
||
319 | xml.putProperty(propertyName, f.getAbsolutePath()); |
||
320 | prefs.put(propertyName, f.getAbsolutePath()); |
||
321 | } |
||
322 | } |
||
323 | |||
324 | 7186 | jaume | } |
325 | |||
326 | public void setChangesApplied() { |
||
327 | setChanged(false);
|
||
328 | } |
||
329 | |||
330 | public String getID() { |
||
331 | return this.getClass().getName(); |
||
332 | } |
||
333 | |||
334 | public String getTitle() { |
||
335 | 7204 | jaume | return PluginServices.getText(this, "options.foldering.title"); |
336 | 7186 | jaume | } |
337 | |||
338 | public JPanel getPanel() { |
||
339 | return this; |
||
340 | } |
||
341 | |||
342 | public void initializeValues() { |
||
343 | PluginServices ps = PluginServices.getPluginServices(this);
|
||
344 | XMLEntity xml = ps.getPersistentXML(); |
||
345 | 7251 | jaume | if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
346 | txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
||
347 | } |
||
348 | 7186 | jaume | if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
349 | txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
||
350 | } |
||
351 | if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
||
352 | txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
||
353 | } |
||
354 | 9931 | jaume | if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
355 | 35957 | jpiera | txtSymbolLibraryFolder.setText(xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
356 | 9931 | jaume | } |
357 | 7186 | jaume | } |
358 | |||
359 | public void initializeDefaults() { |
||
360 | 38399 | jldominguez | txtProjectsFolder.setText("");
|
361 | 7186 | jaume | txtDataFolder.setText("");
|
362 | txtTemplatesFolder.setText("");
|
||
363 | 38399 | jldominguez | txtSymbolLibraryFolder.setText("");
|
364 | 7186 | jaume | } |
365 | |||
366 | public ImageIcon getIcon() { |
||
367 | return icon;
|
||
368 | } |
||
369 | |||
370 | public boolean isValueChanged() { |
||
371 | return super.hasChanged(); |
||
372 | } |
||
373 | |||
374 | } |