svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / FolderingPage.java @ 40558
History | View | Annotate | Download (10.9 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id: FolderingPage.java 38564 2012-07-16 11:19:13Z jjdelcerro $
|
27 |
* $Log$
|
28 |
* Revision 1.8 2007-01-26 13:35:06 jaume
|
29 |
* *** empty log message ***
|
30 |
*
|
31 |
* Revision 1.7 2006/10/02 07:12:12 jaume
|
32 |
* *** empty log message ***
|
33 |
*
|
34 |
* Revision 1.6 2006/09/13 16:21:00 jaume
|
35 |
* *** empty log message ***
|
36 |
*
|
37 |
* Revision 1.5 2006/09/12 12:09:51 jaume
|
38 |
* *** empty log message ***
|
39 |
*
|
40 |
* Revision 1.4 2006/09/12 11:49:04 jaume
|
41 |
* *** empty log message ***
|
42 |
*
|
43 |
* Revision 1.3 2006/09/12 10:11:25 jaume
|
44 |
* *** empty log message ***
|
45 |
*
|
46 |
* Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
*
|
50 |
*/
|
51 |
package org.gvsig.coreplugin.preferences.general; |
52 |
|
53 |
import java.awt.event.ActionEvent; |
54 |
import java.awt.event.ActionListener; |
55 |
import java.io.File; |
56 |
import java.util.prefs.Preferences; |
57 |
|
58 |
import javax.swing.ImageIcon; |
59 |
import javax.swing.JFileChooser; |
60 |
import javax.swing.JLabel; |
61 |
import javax.swing.JPanel; |
62 |
import javax.swing.JTextField; |
63 |
import javax.swing.filechooser.FileFilter; |
64 |
|
65 |
import org.gvsig.andami.PluginServices; |
66 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
67 |
import org.gvsig.andami.preferences.StoreException; |
68 |
import org.gvsig.gui.beans.swing.JButton; |
69 |
import org.gvsig.utils.XMLEntity; |
70 |
|
71 |
/**
|
72 |
*
|
73 |
* In the FolderingPage the user sets which folder paths should be used by
|
74 |
* default.
|
75 |
*
|
76 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
77 |
*
|
78 |
*/
|
79 |
public class FolderingPage extends AbstractPreferencePage{ |
80 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
81 |
|
82 |
private static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
83 |
private static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
84 |
private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
85 |
private static final String SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME = "SymbolLibraryFolder"; |
86 |
private JTextField txtProjectsFolder; |
87 |
private JTextField txtDataFolder; |
88 |
private JTextField txtTemplatesFolder; |
89 |
private JTextField txtSymbolLibraryFolder; |
90 |
private JButton btnSelectProjectsFolder; |
91 |
private JButton btnSelectDataFolder; |
92 |
private JButton btnSelectTemplatesFolder; |
93 |
private JButton btnSelectSymbolLibraryFolder; |
94 |
private ImageIcon icon; |
95 |
private ActionListener btnFileChooserAction; |
96 |
|
97 |
|
98 |
|
99 |
public FolderingPage() {
|
100 |
super();
|
101 |
setParentID(GeneralPage.id); |
102 |
icon = PluginServices.getIconTheme().get("edit-setup-foldering");
|
103 |
|
104 |
btnFileChooserAction = new ActionListener() { |
105 |
public void actionPerformed(ActionEvent e) { |
106 |
String path;
|
107 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
108 |
path = txtProjectsFolder.getText(); |
109 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
110 |
path = txtDataFolder.getText(); |
111 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
112 |
path = txtSymbolLibraryFolder.getText(); |
113 |
} else {
|
114 |
path = txtTemplatesFolder.getText(); |
115 |
} |
116 |
|
117 |
// The file filter for the JFileChooser
|
118 |
FileFilter def = new FileFilter(){ |
119 |
public boolean accept(File f) { |
120 |
return (f.isDirectory());
|
121 |
} |
122 |
|
123 |
public String getDescription() { |
124 |
return null; |
125 |
} |
126 |
}; |
127 |
|
128 |
File file = new File(path); |
129 |
JFileChooser fc;
|
130 |
if (file.exists()) {
|
131 |
fc = new JFileChooser(file); |
132 |
} else {
|
133 |
fc = new JFileChooser(); |
134 |
} |
135 |
|
136 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
137 |
fc.setMultiSelectionEnabled(false);
|
138 |
fc.setAcceptAllFileFilterUsed(false);
|
139 |
fc.addChoosableFileFilter(def); |
140 |
int result = fc.showOpenDialog(FolderingPage.this);
|
141 |
|
142 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
143 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
144 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
145 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
146 |
txtDataFolder.setText(file.getAbsolutePath()); |
147 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
148 |
txtSymbolLibraryFolder.setText(file.getAbsolutePath()); |
149 |
} else {
|
150 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
151 |
} |
152 |
} |
153 |
} |
154 |
|
155 |
}; |
156 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
157 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
158 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
159 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
160 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
161 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
162 |
btnSelectSymbolLibraryFolder = new JButton(PluginServices.getText(this, "browse")); |
163 |
btnSelectSymbolLibraryFolder.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(30), 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(30), 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(30), btnSelectTemplatesFolder); |
188 |
addComponent(new JLabel(" ")); |
189 |
|
190 |
JLabel lblSymbolLibraryFolder = new JLabel("<html><b>" + |
191 |
PluginServices. |
192 |
getText(this, "options.foldering.symbol_library_folder") + |
193 |
"</b></html>");
|
194 |
addComponent(lblSymbolLibraryFolder); |
195 |
addComponent(txtSymbolLibraryFolder = new JTextField(30), btnSelectSymbolLibraryFolder); |
196 |
addComponent(new JLabel(" ")); |
197 |
PluginServices ps = PluginServices.getPluginServices(this);
|
198 |
XMLEntity xml = ps.getPersistentXML(); |
199 |
|
200 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
201 |
prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
202 |
} |
203 |
|
204 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
205 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
206 |
} |
207 |
|
208 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
209 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
210 |
} |
211 |
|
212 |
if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
213 |
prefs.put(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME, xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
214 |
} |
215 |
|
216 |
} |
217 |
|
218 |
public void storeValues() throws StoreException { |
219 |
File f;
|
220 |
String path, propertyName;
|
221 |
PluginServices ps = PluginServices.getPluginServices(this);
|
222 |
XMLEntity xml = ps.getPersistentXML(); |
223 |
|
224 |
// Projects folder
|
225 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
226 |
path = txtProjectsFolder.getText(); |
227 |
|
228 |
if (path.equals("")) { |
229 |
if (xml.contains(propertyName)) {
|
230 |
xml.remove(propertyName); |
231 |
} |
232 |
prefs.remove(propertyName); |
233 |
} else {
|
234 |
f = new File(path); |
235 |
if (f.exists()) {
|
236 |
if (xml.contains(propertyName)) {
|
237 |
xml.remove(propertyName); |
238 |
} |
239 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
240 |
prefs.put(propertyName, f.getAbsolutePath()); |
241 |
} |
242 |
} |
243 |
|
244 |
// Data folder
|
245 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
246 |
path = txtDataFolder.getText(); |
247 |
|
248 |
if (path.equals("")) { |
249 |
if (xml.contains(propertyName)) {
|
250 |
xml.remove(propertyName); |
251 |
} |
252 |
prefs.remove(propertyName); |
253 |
} else {
|
254 |
f = new File(path); |
255 |
if (f.exists()) {
|
256 |
if (xml.contains(propertyName)) {
|
257 |
xml.remove(propertyName); |
258 |
} |
259 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
260 |
prefs.put(propertyName, f.getAbsolutePath()); |
261 |
|
262 |
} |
263 |
} |
264 |
|
265 |
// Templates folder
|
266 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
267 |
path = txtTemplatesFolder.getText(); |
268 |
|
269 |
if (path.equals("")) { |
270 |
if (xml.contains(propertyName)) {
|
271 |
xml.remove(propertyName); |
272 |
} |
273 |
prefs.remove(propertyName); |
274 |
} else {
|
275 |
f = new File(path); |
276 |
if (f.exists()) {
|
277 |
if (xml.contains(propertyName)) {
|
278 |
xml.remove(propertyName); |
279 |
} |
280 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
281 |
prefs.put(propertyName, f.getAbsolutePath()); |
282 |
|
283 |
} |
284 |
} |
285 |
|
286 |
// Symbol library folder
|
287 |
propertyName = SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME; |
288 |
path = txtSymbolLibraryFolder.getText(); |
289 |
|
290 |
if (path.equals("")) { |
291 |
if (xml.contains(propertyName)) {
|
292 |
xml.remove(propertyName); |
293 |
} |
294 |
prefs.remove(propertyName); |
295 |
} else {
|
296 |
f = new File(path); |
297 |
if (f.exists()) {
|
298 |
if (xml.contains(propertyName)) {
|
299 |
xml.remove(propertyName); |
300 |
} |
301 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
302 |
prefs.put(propertyName, f.getAbsolutePath()); |
303 |
} |
304 |
} |
305 |
|
306 |
} |
307 |
|
308 |
public void setChangesApplied() { |
309 |
setChanged(false);
|
310 |
} |
311 |
|
312 |
public String getID() { |
313 |
return this.getClass().getName(); |
314 |
} |
315 |
|
316 |
public String getTitle() { |
317 |
return PluginServices.getText(this, "options.foldering.title"); |
318 |
} |
319 |
|
320 |
public JPanel getPanel() { |
321 |
return this; |
322 |
} |
323 |
|
324 |
public void initializeValues() { |
325 |
PluginServices ps = PluginServices.getPluginServices(this);
|
326 |
XMLEntity xml = ps.getPersistentXML(); |
327 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
328 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
329 |
} |
330 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
331 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
332 |
} |
333 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
334 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
335 |
} |
336 |
if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
337 |
txtSymbolLibraryFolder.setText(xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
338 |
} |
339 |
} |
340 |
|
341 |
public void initializeDefaults() { |
342 |
txtProjectsFolder.setText("");
|
343 |
txtDataFolder.setText("");
|
344 |
txtTemplatesFolder.setText("");
|
345 |
txtSymbolLibraryFolder.setText("");
|
346 |
} |
347 |
|
348 |
public ImageIcon getIcon() { |
349 |
return icon;
|
350 |
} |
351 |
|
352 |
public boolean isValueChanged() { |
353 |
return super.hasChanged(); |
354 |
} |
355 |
|
356 |
} |