root / branches / v10 / libraries / libCorePlugin / src / com / iver / core / preferences / general / FolderingPage.java @ 7251
History | View | Annotate | Download (8.92 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 7251 2006-09-13 16:24:14Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.2 2006-09-13 16:24:14 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
*
|
53 |
*/
|
54 |
package com.iver.core.preferences.general; |
55 |
|
56 |
import java.awt.event.ActionEvent; |
57 |
import java.awt.event.ActionListener; |
58 |
import java.io.File; |
59 |
import java.util.prefs.Preferences; |
60 |
|
61 |
import javax.swing.ImageIcon; |
62 |
import javax.swing.JFileChooser; |
63 |
import javax.swing.JLabel; |
64 |
import javax.swing.JPanel; |
65 |
import javax.swing.JTextField; |
66 |
import javax.swing.filechooser.FileFilter; |
67 |
|
68 |
import org.gvsig.gui.beans.swing.JButton; |
69 |
|
70 |
import com.iver.andami.PluginServices; |
71 |
import com.iver.andami.preferences.AbstractPreferencePage; |
72 |
import com.iver.andami.preferences.StoreException; |
73 |
import com.iver.utiles.XMLEntity; |
74 |
/**
|
75 |
*
|
76 |
* In the FolderingPage the user sets which folder paths should be used by
|
77 |
* default.
|
78 |
*
|
79 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
80 |
*
|
81 |
*/
|
82 |
public class FolderingPage extends AbstractPreferencePage{ |
83 |
private static Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" ); |
84 |
|
85 |
private static final String PROJECTS_FOLDER_PROPERTY_NAME = "ProjectsFolder"; |
86 |
private static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
87 |
private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
88 |
private JTextField txtProjectsFolder; |
89 |
private JTextField txtDataFolder; |
90 |
private JTextField txtTemplatesFolder; |
91 |
private JButton btnSelectProjectsFolder; |
92 |
private JButton btnSelectDataFolder; |
93 |
private JButton btnSelectTemplatesFolder; |
94 |
private ImageIcon icon; |
95 |
private ActionListener btnFileChooserAction; |
96 |
|
97 |
public FolderingPage() {
|
98 |
super();
|
99 |
setParentID(GeneralPage.id); |
100 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/folder.png")); |
101 |
|
102 |
btnFileChooserAction = new ActionListener() { |
103 |
public void actionPerformed(ActionEvent e) { |
104 |
String path;
|
105 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
106 |
path = txtProjectsFolder.getText(); |
107 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
108 |
path = txtDataFolder.getText(); |
109 |
} else {
|
110 |
path = txtTemplatesFolder.getText(); |
111 |
} |
112 |
|
113 |
// The file filter for the JFileChooser
|
114 |
FileFilter def = new FileFilter(){ |
115 |
public boolean accept(File f) { |
116 |
return (f.isDirectory());
|
117 |
} |
118 |
|
119 |
public String getDescription() { |
120 |
return null; |
121 |
} |
122 |
}; |
123 |
|
124 |
File file = new File(path); |
125 |
JFileChooser fc;
|
126 |
if (file.exists()) {
|
127 |
fc = new JFileChooser(file); |
128 |
} else {
|
129 |
fc = new JFileChooser(); |
130 |
} |
131 |
|
132 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
133 |
fc.setMultiSelectionEnabled(false);
|
134 |
fc.setAcceptAllFileFilterUsed(false);
|
135 |
fc.addChoosableFileFilter(def); |
136 |
int result = fc.showOpenDialog(FolderingPage.this);
|
137 |
|
138 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
139 |
if (e.getSource().equals(btnSelectProjectsFolder)) {
|
140 |
txtProjectsFolder.setText(file.getAbsolutePath()); |
141 |
} else if (e.getSource().equals(btnSelectDataFolder)) { |
142 |
txtDataFolder.setText(file.getAbsolutePath()); |
143 |
} else {
|
144 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
145 |
} |
146 |
} |
147 |
} |
148 |
|
149 |
}; |
150 |
btnSelectProjectsFolder = new JButton(PluginServices.getText(this, "browse")); |
151 |
btnSelectProjectsFolder.addActionListener(btnFileChooserAction); |
152 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
153 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
154 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
155 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
156 |
|
157 |
|
158 |
JLabel lblProjectsFolder = new JLabel("<html><b>" + |
159 |
PluginServices. |
160 |
getText(this, "options.foldering.projects_folder") + |
161 |
"</b></html>");
|
162 |
addComponent(lblProjectsFolder); |
163 |
addComponent(txtProjectsFolder = new JTextField(40), btnSelectProjectsFolder); |
164 |
addComponent(new JLabel(" ")); |
165 |
|
166 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
167 |
PluginServices. |
168 |
getText(this, "options.foldering.data_folder") + |
169 |
"</b></html>");
|
170 |
addComponent(lblDataFolder); |
171 |
addComponent(txtDataFolder = new JTextField(40), btnSelectDataFolder); |
172 |
addComponent(new JLabel(" ")); |
173 |
|
174 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
175 |
PluginServices. |
176 |
getText(this, "options.foldering.template_folder") + |
177 |
"</b></html>");
|
178 |
addComponent(lblTemplatesFolder); |
179 |
addComponent(txtTemplatesFolder = new JTextField(40), btnSelectTemplatesFolder); |
180 |
addComponent(new JLabel(" ")); |
181 |
|
182 |
PluginServices ps = PluginServices.getPluginServices(this);
|
183 |
XMLEntity xml = ps.getPersistentXML(); |
184 |
|
185 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
186 |
prefs.put(PROJECTS_FOLDER_PROPERTY_NAME, xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
187 |
} |
188 |
|
189 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
190 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
191 |
} |
192 |
|
193 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
194 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
195 |
} |
196 |
|
197 |
} |
198 |
|
199 |
public void storeValues() throws StoreException { |
200 |
File f;
|
201 |
String path, propertyName;
|
202 |
PluginServices ps = PluginServices.getPluginServices(this);
|
203 |
XMLEntity xml = ps.getPersistentXML(); |
204 |
|
205 |
// Projects folder
|
206 |
propertyName = PROJECTS_FOLDER_PROPERTY_NAME; |
207 |
path = txtProjectsFolder.getText(); |
208 |
|
209 |
if (path.equals("")) { |
210 |
if (xml.contains(propertyName)) {
|
211 |
xml.remove(propertyName); |
212 |
} |
213 |
prefs.remove(propertyName); |
214 |
} else {
|
215 |
f = new File(path); |
216 |
if (f.exists()) {
|
217 |
if (xml.contains(propertyName)) {
|
218 |
xml.remove(propertyName); |
219 |
} |
220 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
221 |
prefs.put(propertyName, f.getAbsolutePath()); |
222 |
} |
223 |
} |
224 |
|
225 |
// Data folder
|
226 |
propertyName = DATA_FOLDER_PROPERTY_NAME; |
227 |
path = txtDataFolder.getText(); |
228 |
|
229 |
if (path.equals("")) { |
230 |
if (xml.contains(propertyName)) {
|
231 |
xml.remove(propertyName); |
232 |
} |
233 |
prefs.remove(propertyName); |
234 |
} else {
|
235 |
f = new File(path); |
236 |
if (f.exists()) {
|
237 |
if (xml.contains(propertyName)) {
|
238 |
xml.remove(propertyName); |
239 |
} |
240 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
241 |
prefs.put(propertyName, f.getAbsolutePath()); |
242 |
|
243 |
} |
244 |
} |
245 |
|
246 |
// Templates folder
|
247 |
propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
248 |
path = txtTemplatesFolder.getText(); |
249 |
|
250 |
if (path.equals("")) { |
251 |
if (xml.contains(propertyName)) {
|
252 |
xml.remove(propertyName); |
253 |
} |
254 |
prefs.remove(propertyName); |
255 |
} else {
|
256 |
f = new File(path); |
257 |
if (f.exists()) {
|
258 |
if (xml.contains(propertyName)) {
|
259 |
xml.remove(propertyName); |
260 |
} |
261 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
262 |
prefs.put(propertyName, f.getAbsolutePath()); |
263 |
|
264 |
} |
265 |
} |
266 |
|
267 |
} |
268 |
|
269 |
public void setChangesApplied() { |
270 |
setChanged(false);
|
271 |
} |
272 |
|
273 |
public String getID() { |
274 |
return this.getClass().getName(); |
275 |
} |
276 |
|
277 |
public String getTitle() { |
278 |
return PluginServices.getText(this, "options.foldering.title"); |
279 |
} |
280 |
|
281 |
public JPanel getPanel() { |
282 |
return this; |
283 |
} |
284 |
|
285 |
public void initializeValues() { |
286 |
PluginServices ps = PluginServices.getPluginServices(this);
|
287 |
XMLEntity xml = ps.getPersistentXML(); |
288 |
if (xml.contains(PROJECTS_FOLDER_PROPERTY_NAME)) {
|
289 |
txtProjectsFolder.setText(xml.getStringProperty(PROJECTS_FOLDER_PROPERTY_NAME)); |
290 |
} |
291 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
292 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
293 |
} |
294 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
295 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
296 |
} |
297 |
|
298 |
} |
299 |
|
300 |
public void initializeDefaults() { |
301 |
txtDataFolder.setText("");
|
302 |
txtTemplatesFolder.setText("");
|
303 |
} |
304 |
|
305 |
public ImageIcon getIcon() { |
306 |
return icon;
|
307 |
} |
308 |
|
309 |
public boolean isValueChanged() { |
310 |
return super.hasChanged(); |
311 |
} |
312 |
|
313 |
} |
314 |
|