gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / FolderingPage.java @ 682
History | View | Annotate | Download (11.2 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 static org.gvsig.coreplugin.PreferencesExtension.DATA_FOLDER_PROPERTY_NAME; |
69 |
import static org.gvsig.coreplugin.PreferencesExtension.PROJECTS_FOLDER_PROPERTY_NAME; |
70 |
import static org.gvsig.coreplugin.PreferencesExtension.SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME; |
71 |
import static org.gvsig.coreplugin.PreferencesExtension.TEMPLATES_FOLDER_PROPERTY_NAME; |
72 |
import org.gvsig.gui.beans.swing.JButton; |
73 |
import org.gvsig.tools.ToolsLocator; |
74 |
import org.gvsig.tools.folders.FoldersManager; |
75 |
import org.gvsig.utils.XMLEntity; |
76 |
|
77 |
/**
|
78 |
*
|
79 |
* In the FolderingPage the user sets which folder paths should be used by
|
80 |
* default.
|
81 |
*
|
82 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
83 |
*
|
84 |
*/
|
85 |
public class FolderingPage extends AbstractPreferencePage{ |
86 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
87 |
|
88 |
private JTextField txtProjectsFolder; |
89 |
private JTextField txtDataFolder; |
90 |
private JTextField txtTemplatesFolder; |
91 |
private JTextField txtSymbolLibraryFolder; |
92 |
private JButton btnSelectProjectsFolder; |
93 |
private JButton btnSelectDataFolder; |
94 |
private JButton btnSelectTemplatesFolder; |
95 |
private JButton btnSelectSymbolLibraryFolder; |
96 |
private ImageIcon icon; |
97 |
private ActionListener btnFileChooserAction; |
98 |
|
99 |
|
100 |
|
101 |
public FolderingPage() {
|
102 |
super();
|
103 |
setParentID(GeneralPage.id); |
104 |
icon = PluginServices.getIconTheme().get("edit-setup-foldering");
|
105 |
|
106 |
btnFileChooserAction = new ActionListener() { |
107 |
public void actionPerformed(ActionEvent e) { |
108 |
String path;
|
109 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
110 |
path = txtProjectsFolder.getText(); |
111 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
112 |
path = txtDataFolder.getText(); |
113 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
114 |
path = txtSymbolLibraryFolder.getText(); |
115 |
} else {
|
116 |
path = txtTemplatesFolder.getText(); |
117 |
} |
118 |
|
119 |
// The file filter for the JFileChooser
|
120 |
FileFilter def = new FileFilter(){ |
121 |
public boolean accept(File f) { |
122 |
return (f.isDirectory());
|
123 |
} |
124 |
|
125 |
public String getDescription() { |
126 |
return null; |
127 |
} |
128 |
}; |
129 |
|
130 |
File file = new File(path); |
131 |
JFileChooser fc;
|
132 |
if (file.exists()) {
|
133 |
fc = new JFileChooser(file); |
134 |
} else {
|
135 |
fc = new JFileChooser(); |
136 |
} |
137 |
|
138 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
139 |
fc.setMultiSelectionEnabled(false);
|
140 |
fc.setAcceptAllFileFilterUsed(false);
|
141 |
fc.addChoosableFileFilter(def); |
142 |
int result = fc.showOpenDialog(FolderingPage.this);
|
143 |
|
144 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
145 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
146 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
147 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
148 |
txtDataFolder.setText(file.getAbsolutePath()); |
149 |
} else if (e.getSource().equals(btnSelectSymbolLibraryFolder)) { |
150 |
txtSymbolLibraryFolder.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 |
btnSelectSymbolLibraryFolder = new JButton(PluginServices.getText(this, "browse")); |
165 |
btnSelectSymbolLibraryFolder.addActionListener(btnFileChooserAction); |
166 |
|
167 |
|
168 |
JLabel lblProjectsFolder = new JLabel("<html><b>" + |
169 |
PluginServices. |
170 |
getText(this, "options.foldering.projects_folder") + |
171 |
"</b></html>");
|
172 |
addComponent(lblProjectsFolder); |
173 |
addComponent(txtProjectsFolder = new JTextField(30), btnSelectProjectsFolder); |
174 |
addComponent(new JLabel(" ")); |
175 |
|
176 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
177 |
PluginServices. |
178 |
getText(this, "options.foldering.data_folder") + |
179 |
"</b></html>");
|
180 |
addComponent(lblDataFolder); |
181 |
addComponent(txtDataFolder = new JTextField(30), btnSelectDataFolder); |
182 |
addComponent(new JLabel(" ")); |
183 |
|
184 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
185 |
PluginServices. |
186 |
getText(this, "options.foldering.template_folder") + |
187 |
"</b></html>");
|
188 |
addComponent(lblTemplatesFolder); |
189 |
addComponent(txtTemplatesFolder = new JTextField(30), btnSelectTemplatesFolder); |
190 |
addComponent(new JLabel(" ")); |
191 |
|
192 |
JLabel lblSymbolLibraryFolder = new JLabel("<html><b>" + |
193 |
PluginServices. |
194 |
getText(this, "options.foldering.symbol_library_folder") + |
195 |
"</b></html>");
|
196 |
addComponent(lblSymbolLibraryFolder); |
197 |
addComponent(txtSymbolLibraryFolder = new JTextField(30), btnSelectSymbolLibraryFolder); |
198 |
addComponent(new JLabel(" ")); |
199 |
PluginServices ps = PluginServices.getPluginServices(this);
|
200 |
XMLEntity xml = ps.getPersistentXML(); |
201 |
|
202 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
203 |
prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
204 |
} |
205 |
|
206 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
207 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
208 |
} |
209 |
|
210 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
211 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
212 |
} |
213 |
|
214 |
if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
215 |
prefs.put(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME, xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
216 |
} |
217 |
|
218 |
} |
219 |
|
220 |
public void storeValues() throws StoreException { |
221 |
File f;
|
222 |
String path, propertyName;
|
223 |
PluginServices ps = PluginServices.getPluginServices(this);
|
224 |
XMLEntity xml = ps.getPersistentXML(); |
225 |
FoldersManager foldersManager = ToolsLocator.getFoldersManager(); |
226 |
|
227 |
// Projects folder
|
228 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
229 |
path = txtProjectsFolder.getText(); |
230 |
|
231 |
if (path.equals("")) { |
232 |
if (xml.contains(propertyName)) {
|
233 |
xml.remove(propertyName); |
234 |
} |
235 |
prefs.remove(propertyName); |
236 |
} else {
|
237 |
f = new File(path); |
238 |
if (f.exists()) {
|
239 |
if (xml.contains(propertyName)) {
|
240 |
xml.remove(propertyName); |
241 |
} |
242 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
243 |
prefs.put(propertyName, f.getAbsolutePath()); |
244 |
foldersManager.set(propertyName, f); |
245 |
} |
246 |
} |
247 |
|
248 |
// Data folder
|
249 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
250 |
path = txtDataFolder.getText(); |
251 |
|
252 |
if (path.equals("")) { |
253 |
if (xml.contains(propertyName)) {
|
254 |
xml.remove(propertyName); |
255 |
} |
256 |
prefs.remove(propertyName); |
257 |
} else {
|
258 |
f = new File(path); |
259 |
if (f.exists()) {
|
260 |
if (xml.contains(propertyName)) {
|
261 |
xml.remove(propertyName); |
262 |
} |
263 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
264 |
prefs.put(propertyName, f.getAbsolutePath()); |
265 |
foldersManager.set(propertyName, f); |
266 |
} |
267 |
} |
268 |
|
269 |
// Templates folder
|
270 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
271 |
path = txtTemplatesFolder.getText(); |
272 |
|
273 |
if (path.equals("")) { |
274 |
if (xml.contains(propertyName)) {
|
275 |
xml.remove(propertyName); |
276 |
} |
277 |
prefs.remove(propertyName); |
278 |
} else {
|
279 |
f = new File(path); |
280 |
if (f.exists()) {
|
281 |
if (xml.contains(propertyName)) {
|
282 |
xml.remove(propertyName); |
283 |
} |
284 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
285 |
prefs.put(propertyName, f.getAbsolutePath()); |
286 |
foldersManager.set(propertyName, f); |
287 |
} |
288 |
} |
289 |
|
290 |
// Symbol library folder
|
291 |
propertyName = SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME; |
292 |
path = txtSymbolLibraryFolder.getText(); |
293 |
|
294 |
if (path.equals("")) { |
295 |
if (xml.contains(propertyName)) {
|
296 |
xml.remove(propertyName); |
297 |
} |
298 |
prefs.remove(propertyName); |
299 |
} else {
|
300 |
f = new File(path); |
301 |
if (f.exists()) {
|
302 |
if (xml.contains(propertyName)) {
|
303 |
xml.remove(propertyName); |
304 |
} |
305 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
306 |
prefs.put(propertyName, f.getAbsolutePath()); |
307 |
foldersManager.set(propertyName, f); |
308 |
} |
309 |
} |
310 |
|
311 |
} |
312 |
|
313 |
public void setChangesApplied() { |
314 |
setChanged(false);
|
315 |
} |
316 |
|
317 |
public String getID() { |
318 |
return this.getClass().getName(); |
319 |
} |
320 |
|
321 |
public String getTitle() { |
322 |
return PluginServices.getText(this, "options.foldering.title"); |
323 |
} |
324 |
|
325 |
public JPanel getPanel() { |
326 |
return this; |
327 |
} |
328 |
|
329 |
public void initializeValues() { |
330 |
PluginServices ps = PluginServices.getPluginServices(this);
|
331 |
XMLEntity xml = ps.getPersistentXML(); |
332 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
333 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
334 |
} |
335 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
336 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
337 |
} |
338 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
339 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
340 |
} |
341 |
if (xml.contains(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)) {
|
342 |
txtSymbolLibraryFolder.setText(xml.getStringProperty(SYMBOL_LIBRARY_FOLDER_PROPERTY_NAME)); |
343 |
} |
344 |
} |
345 |
|
346 |
public void initializeDefaults() { |
347 |
txtProjectsFolder.setText("");
|
348 |
txtDataFolder.setText("");
|
349 |
txtTemplatesFolder.setText("");
|
350 |
txtSymbolLibraryFolder.setText("");
|
351 |
} |
352 |
|
353 |
public ImageIcon getIcon() { |
354 |
return icon;
|
355 |
} |
356 |
|
357 |
public boolean isValueChanged() { |
358 |
return super.hasChanged(); |
359 |
} |
360 |
|
361 |
} |