root / branches / v10 / libraries / libCorePlugin / src / com / iver / core / preferences / general / FolderingPage.java @ 11142
History | View | Annotate | Download (9.28 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 8765 2006-11-15 00:08:29Z jjdelcerro $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.6 2006-11-15 00:08:23 jjdelcerro
|
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 com.iver.core.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.gui.beans.swing.JButton; |
84 |
|
85 |
import com.iver.andami.PluginServices; |
86 |
import com.iver.andami.preferences.AbstractPreferencePage; |
87 |
import com.iver.andami.preferences.StoreException; |
88 |
import com.iver.utiles.XMLEntity; |
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 JTextField txtProjectsFolder; |
104 |
private JTextField txtDataFolder; |
105 |
private JTextField txtTemplatesFolder; |
106 |
private JButton btnSelectProjectsFolder; |
107 |
private JButton btnSelectDataFolder; |
108 |
private JButton btnSelectTemplatesFolder; |
109 |
private ImageIcon icon; |
110 |
private ActionListener btnFileChooserAction; |
111 |
|
112 |
public FolderingPage() {
|
113 |
super();
|
114 |
setParentID(GeneralPage.id); |
115 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/folder.png")); |
116 |
|
117 |
btnFileChooserAction = new ActionListener() { |
118 |
public void actionPerformed(ActionEvent e) { |
119 |
String path;
|
120 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
121 |
path = txtProjectsFolder.getText(); |
122 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
123 |
path = txtDataFolder.getText(); |
124 |
} else {
|
125 |
path = txtTemplatesFolder.getText(); |
126 |
} |
127 |
|
128 |
// The file filter for the JFileChooser
|
129 |
FileFilter def = new FileFilter(){ |
130 |
public boolean accept(File f) { |
131 |
return (f.isDirectory());
|
132 |
} |
133 |
|
134 |
public String getDescription() { |
135 |
return null; |
136 |
} |
137 |
}; |
138 |
|
139 |
File file = new File(path); |
140 |
JFileChooser fc;
|
141 |
if (file.exists()) {
|
142 |
fc = new JFileChooser(file); |
143 |
} else {
|
144 |
fc = new JFileChooser(); |
145 |
} |
146 |
|
147 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
148 |
fc.setMultiSelectionEnabled(false);
|
149 |
fc.setAcceptAllFileFilterUsed(false);
|
150 |
fc.addChoosableFileFilter(def); |
151 |
int result = fc.showOpenDialog(FolderingPage.this);
|
152 |
|
153 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
154 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
155 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
156 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
157 |
txtDataFolder.setText(file.getAbsolutePath()); |
158 |
} else {
|
159 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
160 |
} |
161 |
} |
162 |
} |
163 |
|
164 |
}; |
165 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
166 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
167 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
168 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
169 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
170 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
171 |
|
172 |
|
173 |
JLabel lblProjectsFolder = new JLabel("<html><b>" + |
174 |
PluginServices. |
175 |
getText(this, "options.foldering.projects_folder") + |
176 |
"</b></html>");
|
177 |
addComponent(lblProjectsFolder); |
178 |
addComponent(txtProjectsFolder = new JTextField(30), btnSelectProjectsFolder); |
179 |
addComponent(new JLabel(" ")); |
180 |
|
181 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
182 |
PluginServices. |
183 |
getText(this, "options.foldering.data_folder") + |
184 |
"</b></html>");
|
185 |
addComponent(lblDataFolder); |
186 |
addComponent(txtDataFolder = new JTextField(30), btnSelectDataFolder); |
187 |
addComponent(new JLabel(" ")); |
188 |
|
189 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
190 |
PluginServices. |
191 |
getText(this, "options.foldering.template_folder") + |
192 |
"</b></html>");
|
193 |
addComponent(lblTemplatesFolder); |
194 |
addComponent(txtTemplatesFolder = new JTextField(30), btnSelectTemplatesFolder); |
195 |
addComponent(new JLabel(" ")); |
196 |
|
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 |
} |
213 |
|
214 |
public void storeValues() throws StoreException { |
215 |
File f;
|
216 |
String path, propertyName;
|
217 |
PluginServices ps = PluginServices.getPluginServices(this);
|
218 |
XMLEntity xml = ps.getPersistentXML(); |
219 |
|
220 |
// Projects folder
|
221 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
222 |
path = txtProjectsFolder.getText(); |
223 |
|
224 |
if (path.equals("")) { |
225 |
if (xml.contains(propertyName)) {
|
226 |
xml.remove(propertyName); |
227 |
} |
228 |
prefs.remove(propertyName); |
229 |
} else {
|
230 |
f = new File(path); |
231 |
if (f.exists()) {
|
232 |
if (xml.contains(propertyName)) {
|
233 |
xml.remove(propertyName); |
234 |
} |
235 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
236 |
prefs.put(propertyName, f.getAbsolutePath()); |
237 |
} |
238 |
} |
239 |
|
240 |
// Data folder
|
241 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
242 |
path = txtDataFolder.getText(); |
243 |
|
244 |
if (path.equals("")) { |
245 |
if (xml.contains(propertyName)) {
|
246 |
xml.remove(propertyName); |
247 |
} |
248 |
prefs.remove(propertyName); |
249 |
} else {
|
250 |
f = new File(path); |
251 |
if (f.exists()) {
|
252 |
if (xml.contains(propertyName)) {
|
253 |
xml.remove(propertyName); |
254 |
} |
255 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
256 |
prefs.put(propertyName, f.getAbsolutePath()); |
257 |
|
258 |
} |
259 |
} |
260 |
|
261 |
// Templates folder
|
262 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
263 |
path = txtTemplatesFolder.getText(); |
264 |
|
265 |
if (path.equals("")) { |
266 |
if (xml.contains(propertyName)) {
|
267 |
xml.remove(propertyName); |
268 |
} |
269 |
prefs.remove(propertyName); |
270 |
} else {
|
271 |
f = new File(path); |
272 |
if (f.exists()) {
|
273 |
if (xml.contains(propertyName)) {
|
274 |
xml.remove(propertyName); |
275 |
} |
276 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
277 |
prefs.put(propertyName, f.getAbsolutePath()); |
278 |
|
279 |
} |
280 |
} |
281 |
|
282 |
} |
283 |
|
284 |
public void setChangesApplied() { |
285 |
setChanged(false);
|
286 |
} |
287 |
|
288 |
public String getID() { |
289 |
return this.getClass().getName(); |
290 |
} |
291 |
|
292 |
public String getTitle() { |
293 |
return PluginServices.getText(this, "options.foldering.title"); |
294 |
} |
295 |
|
296 |
public JPanel getPanel() { |
297 |
return this; |
298 |
} |
299 |
|
300 |
public void initializeValues() { |
301 |
PluginServices ps = PluginServices.getPluginServices(this);
|
302 |
XMLEntity xml = ps.getPersistentXML(); |
303 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
304 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
305 |
} |
306 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
307 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
308 |
} |
309 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
310 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
311 |
} |
312 |
|
313 |
} |
314 |
|
315 |
public void initializeDefaults() { |
316 |
txtDataFolder.setText("");
|
317 |
txtTemplatesFolder.setText("");
|
318 |
} |
319 |
|
320 |
public ImageIcon getIcon() { |
321 |
return icon;
|
322 |
} |
323 |
|
324 |
public boolean isValueChanged() { |
325 |
return super.hasChanged(); |
326 |
} |
327 |
|
328 |
} |