svn-gvsig-desktop / branches / v10 / libraries / libCorePlugin / src / com / iver / core / preferences / general / FolderingPage.java @ 7267
History | View | Annotate | Download (7.03 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 7267 2006-09-14 09:48:24Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.1.2.4 2006-09-14 09:48:24 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.3 2006/09/13 16:25:43 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.1 2006/09/08 11:56:24 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.core.preferences.general; |
58 |
|
59 |
import java.awt.event.ActionEvent; |
60 |
import java.awt.event.ActionListener; |
61 |
import java.io.File; |
62 |
import java.util.prefs.Preferences; |
63 |
|
64 |
import javax.swing.ImageIcon; |
65 |
import javax.swing.JFileChooser; |
66 |
import javax.swing.JLabel; |
67 |
import javax.swing.JPanel; |
68 |
import javax.swing.JTextField; |
69 |
import javax.swing.filechooser.FileFilter; |
70 |
|
71 |
import org.gvsig.gui.beans.swing.JButton; |
72 |
|
73 |
import com.iver.andami.PluginServices; |
74 |
import com.iver.andami.preferences.AbstractPreferencePage; |
75 |
import com.iver.andami.preferences.StoreException; |
76 |
import com.iver.utiles.XMLEntity; |
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 static final String DATA_FOLDER_PROPERTY_NAME = "DataFolder"; |
89 |
private static final String TEMPLATES_FOLDER_PROPERTY_NAME = "TemplatesFolder"; |
90 |
private JTextField txtDataFolder; |
91 |
private JButton btnSelectDataFolder; |
92 |
private JTextField txtTemplatesFolder; |
93 |
private JButton btnSelectTemplatesFolder; |
94 |
private ImageIcon icon; |
95 |
private ActionListener btnFileChooserAction; |
96 |
public FolderingPage() {
|
97 |
super();
|
98 |
|
99 |
icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/folder.png")); |
100 |
|
101 |
btnFileChooserAction = new ActionListener() { |
102 |
public void actionPerformed(ActionEvent e) { |
103 |
String path;
|
104 |
if (e.getSource().equals(btnSelectDataFolder)) {
|
105 |
path = txtDataFolder.getText(); |
106 |
} else {
|
107 |
path = txtTemplatesFolder.getText(); |
108 |
} |
109 |
|
110 |
// The file filter for the JFileChooser
|
111 |
FileFilter def = new FileFilter(){ |
112 |
public boolean accept(File f) { |
113 |
return (f.isDirectory());
|
114 |
} |
115 |
|
116 |
public String getDescription() { |
117 |
return null; |
118 |
} |
119 |
}; |
120 |
|
121 |
File file = new File(path); |
122 |
JFileChooser fc;
|
123 |
if (file.exists()) {
|
124 |
fc = new JFileChooser(file); |
125 |
} else {
|
126 |
fc = new JFileChooser(); |
127 |
} |
128 |
|
129 |
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
130 |
fc.setMultiSelectionEnabled(false);
|
131 |
fc.setAcceptAllFileFilterUsed(false);
|
132 |
fc.addChoosableFileFilter(def); |
133 |
int result = fc.showOpenDialog(FolderingPage.this);
|
134 |
|
135 |
if (result == JFileChooser.APPROVE_OPTION && (file = fc.getSelectedFile()) != null) { |
136 |
if (e.getSource().equals(btnSelectDataFolder)) {
|
137 |
txtDataFolder.setText(file.getAbsolutePath()); |
138 |
} else {
|
139 |
txtTemplatesFolder.setText(file.getAbsolutePath()); |
140 |
} |
141 |
} |
142 |
} |
143 |
|
144 |
}; |
145 |
btnSelectDataFolder = new JButton(PluginServices.getText(this, "browse")); |
146 |
btnSelectDataFolder.addActionListener(btnFileChooserAction); |
147 |
btnSelectTemplatesFolder = new JButton(PluginServices.getText(this, "browse")); |
148 |
btnSelectTemplatesFolder.addActionListener(btnFileChooserAction); |
149 |
|
150 |
|
151 |
JLabel lblDataFolder = new JLabel("<html><b>" + |
152 |
PluginServices. |
153 |
getText(this, "preferences.foldering.data_folder") + |
154 |
"</b></html>");
|
155 |
addComponent(lblDataFolder); |
156 |
addComponent(txtDataFolder = new JTextField(40), btnSelectDataFolder); |
157 |
addComponent(new JLabel(" ")); |
158 |
JLabel lblTemplatesFolder = new JLabel("<html><b>" + |
159 |
PluginServices. |
160 |
getText(this, "preferences.foldering.template_folder") + |
161 |
"</b></html>");
|
162 |
addComponent(lblTemplatesFolder); |
163 |
addComponent(txtTemplatesFolder = new JTextField(40), btnSelectTemplatesFolder); |
164 |
|
165 |
PluginServices ps = PluginServices.getPluginServices(this);
|
166 |
XMLEntity xml = ps.getPersistentXML(); |
167 |
|
168 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
169 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
170 |
} |
171 |
|
172 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
173 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
174 |
} |
175 |
|
176 |
} |
177 |
|
178 |
public void storeValues() throws StoreException { |
179 |
File f;
|
180 |
PluginServices ps = PluginServices.getPluginServices(this);
|
181 |
XMLEntity xml = ps.getPersistentXML(); |
182 |
|
183 |
// Data folder
|
184 |
f = new File(txtDataFolder.getText()); |
185 |
if (f.exists()) {
|
186 |
final String propertyName = DATA_FOLDER_PROPERTY_NAME; |
187 |
if (xml.contains(propertyName)) {
|
188 |
xml.remove(propertyName); |
189 |
} |
190 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
191 |
prefs.put(DATA_FOLDER_PROPERTY_NAME, f.getAbsolutePath()); |
192 |
|
193 |
} |
194 |
|
195 |
// Data folder
|
196 |
f = new File(txtTemplatesFolder.getText()); |
197 |
if (f.exists()) {
|
198 |
final String propertyName = TEMPLATES_FOLDER_PROPERTY_NAME; |
199 |
if (xml.contains(propertyName)) {
|
200 |
xml.remove(propertyName); |
201 |
} |
202 |
xml.putProperty(propertyName, f.getAbsolutePath()); |
203 |
prefs.put(TEMPLATES_FOLDER_PROPERTY_NAME, f.getAbsolutePath()); |
204 |
|
205 |
} |
206 |
|
207 |
} |
208 |
|
209 |
public void setChangesApplied() { |
210 |
setChanged(false);
|
211 |
} |
212 |
|
213 |
public String getID() { |
214 |
return this.getClass().getName(); |
215 |
} |
216 |
|
217 |
public String getTitle() { |
218 |
return PluginServices.getText(this, "preferences.foldering.title"); |
219 |
} |
220 |
|
221 |
public JPanel getPanel() { |
222 |
return this; |
223 |
} |
224 |
|
225 |
public void initializeValues() { |
226 |
PluginServices ps = PluginServices.getPluginServices(this);
|
227 |
XMLEntity xml = ps.getPersistentXML(); |
228 |
if (xml.contains(DATA_FOLDER_PROPERTY_NAME)) {
|
229 |
txtDataFolder.setText(xml.getStringProperty(DATA_FOLDER_PROPERTY_NAME)); |
230 |
} |
231 |
if (xml.contains(TEMPLATES_FOLDER_PROPERTY_NAME)) {
|
232 |
txtTemplatesFolder.setText(xml.getStringProperty(TEMPLATES_FOLDER_PROPERTY_NAME)); |
233 |
} |
234 |
|
235 |
} |
236 |
|
237 |
public void initializeDefaults() { |
238 |
txtDataFolder.setText("");
|
239 |
txtTemplatesFolder.setText("");
|
240 |
} |
241 |
|
242 |
public ImageIcon getIcon() { |
243 |
return icon;
|
244 |
} |
245 |
|
246 |
public boolean isValueChanged() { |
247 |
return super.hasChanged(); |
248 |
} |
249 |
|
250 |
} |