svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / FolderingPage.java @ 38564
History | View | Annotate | Download (11.1 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 38564 2012-07-16 11:19:13Z jjdelcerro $
|
45 |
* $Log$
|
46 |
* Revision 1.8 2007-01-26 13:35:06 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.7 2006/10/02 07:12:12 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.6 2006/09/13 16:21:00 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.5 2006/09/12 12:09:51 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.4 2006/09/12 11:49:04 jaume
|
59 |
* *** empty log message ***
|
60 |
*
|
61 |
* Revision 1.3 2006/09/12 10:11:25 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
*
|
68 |
*/
|
69 |
package org.gvsig.coreplugin.preferences.general; |
70 |
|
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 |
import org.gvsig.andami.PluginServices; |
84 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
85 |
import org.gvsig.andami.preferences.StoreException; |
86 |
import org.gvsig.gui.beans.swing.JButton; |
87 |
import org.gvsig.utils.XMLEntity; |
88 |
|
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 |
private static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
101 |
private static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
102 |
private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
103 |
private static final String SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME = "SymbolLibraryFolder"; |
104 |
private JTextField txtProjectsFolder; |
105 |
private JTextField txtDataFolder; |
106 |
private JTextField txtTemplatesFolder; |
107 |
private JTextField txtSymbolLibraryFolder; |
108 |
private JButton btnSelectProjectsFolder; |
109 |
private JButton btnSelectDataFolder; |
110 |
private JButton btnSelectTemplatesFolder; |
111 |
private JButton btnSelectSymbolLibraryFolder; |
112 |
private ImageIcon icon; |
113 |
private ActionListener btnFileChooserAction; |
114 |
|
115 |
|
116 |
|
117 |
public FolderingPage() {
|
118 |
super();
|
119 |
setParentID(GeneralPage.id); |
120 |
icon = PluginServices.getIconTheme().get("edit-setup-foldering");
|
121 |
|
122 |
btnFileChooserAction = new ActionListener() { |
123 |
public void actionPerformed(ActionEvent e) { |
124 |
String path;
|
125 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
126 |
path = txtProjectsFolder.getText(); |
127 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
128 |
path = txtDataFolder.getText(); |
129 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
130 |
path = txtSymbolLibraryFolder.getText(); |
131 |
} 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 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
162 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
163 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
164 |
txtDataFolder.setText(file.getAbsolutePath()); |
165 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
166 |
txtSymbolLibraryFolder.setText(file.getAbsolutePath()); |
167 |
} else {
|
168 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
}; |
174 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
175 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
176 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
177 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
178 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
179 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
180 |
btnSelectSymbolLibraryFolder = new JButton(PluginServices.getText(this, "browse")); |
181 |
btnSelectSymbolLibraryFolder.addActionListener(btnFileChooserAction); |
182 |
|
183 |
|
184 |
JLabel lblProjectsFolder = new JLabel("<html><b>" + |
185 |
PluginServices. |
186 |
getText(this, "options.foldering.projects_folder") + |
187 |
"</b></html>");
|
188 |
addComponent(lblProjectsFolder); |
189 |
addComponent(txtProjectsFolder = new JTextField(30), btnSelectProjectsFolder); |
190 |
addComponent(new JLabel(" ")); |
191 |
|
192 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
193 |
PluginServices. |
194 |
getText(this, "options.foldering.data_folder") + |
195 |
"</b></html>");
|
196 |
addComponent(lblDataFolder); |
197 |
addComponent(txtDataFolder = new JTextField(30), btnSelectDataFolder); |
198 |
addComponent(new JLabel(" ")); |
199 |
|
200 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
201 |
PluginServices. |
202 |
getText(this, "options.foldering.template_folder") + |
203 |
"</b></html>");
|
204 |
addComponent(lblTemplatesFolder); |
205 |
addComponent(txtTemplatesFolder = new JTextField(30), btnSelectTemplatesFolder); |
206 |
addComponent(new JLabel(" ")); |
207 |
|
208 |
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 |
PluginServices ps = PluginServices.getPluginServices(this);
|
216 |
XMLEntity xml = ps.getPersistentXML(); |
217 |
|
218 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
219 |
prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
220 |
} |
221 |
|
222 |
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 |
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 |
} |
235 |
|
236 |
public void storeValues() throws StoreException { |
237 |
File f;
|
238 |
String path, propertyName;
|
239 |
PluginServices ps = PluginServices.getPluginServices(this);
|
240 |
XMLEntity xml = ps.getPersistentXML(); |
241 |
|
242 |
// Projects folder
|
243 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
244 |
path = txtProjectsFolder.getText(); |
245 |
|
246 |
if (path.equals("")) { |
247 |
if (xml.contains(propertyName)) {
|
248 |
xml.remove(propertyName); |
249 |
} |
250 |
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 |
} |
261 |
|
262 |
// Data folder
|
263 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
264 |
path = txtDataFolder.getText(); |
265 |
|
266 |
if (path.equals("")) { |
267 |
if (xml.contains(propertyName)) {
|
268 |
xml.remove(propertyName); |
269 |
} |
270 |
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 |
|
280 |
} |
281 |
} |
282 |
|
283 |
// Templates folder
|
284 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
285 |
path = txtTemplatesFolder.getText(); |
286 |
|
287 |
if (path.equals("")) { |
288 |
if (xml.contains(propertyName)) {
|
289 |
xml.remove(propertyName); |
290 |
} |
291 |
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 |
|
301 |
} |
302 |
} |
303 |
|
304 |
// 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 |
} |
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 |
return PluginServices.getText(this, "options.foldering.title"); |
336 |
} |
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 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
346 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
347 |
} |
348 |
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 |
if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
355 |
txtSymbolLibraryFolder.setText(xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
356 |
} |
357 |
} |
358 |
|
359 |
public void initializeDefaults() { |
360 |
txtProjectsFolder.setText("");
|
361 |
txtDataFolder.setText("");
|
362 |
txtTemplatesFolder.setText("");
|
363 |
txtSymbolLibraryFolder.setText("");
|
364 |
} |
365 |
|
366 |
public ImageIcon getIcon() { |
367 |
return icon;
|
368 |
} |
369 |
|
370 |
public boolean isValueChanged() { |
371 |
return super.hasChanged(); |
372 |
} |
373 |
|
374 |
} |