gvsig-raster / org.gvsig.raster.tilecache / trunk / org.gvsig.raster.tilecache / org.gvsig.raster.tilecache.app / src / main / java / org / gvsig / raster / tilecache / app / TileCachePreferencesPanel.java @ 1137
History | View | Annotate | Download (15.7 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.raster.tilecache.app; |
23 |
|
24 |
import java.awt.Color; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridBagConstraints; |
27 |
import java.awt.GridBagLayout; |
28 |
import java.awt.Insets; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
import java.io.File; |
32 |
import java.text.NumberFormat; |
33 |
|
34 |
import javax.swing.BorderFactory; |
35 |
import javax.swing.DefaultComboBoxModel; |
36 |
import javax.swing.JButton; |
37 |
import javax.swing.JComboBox; |
38 |
import javax.swing.JFormattedTextField; |
39 |
import javax.swing.JLabel; |
40 |
import javax.swing.JTextField; |
41 |
import javax.swing.SwingConstants; |
42 |
import javax.swing.text.DefaultFormatterFactory; |
43 |
import javax.swing.text.NumberFormatter; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.preferences.DlgPreferences; |
47 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
48 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
49 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
50 |
import org.gvsig.raster.util.BasePanel; |
51 |
/**
|
52 |
* This class provides a panel for tile cache configuration
|
53 |
*
|
54 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
55 |
*/
|
56 |
public class TileCachePreferencesPanel extends BasePanel implements ActionListener { |
57 |
protected static final long serialVersionUID = 1L; |
58 |
private static int TILE_SIZE_WMS = 1024; |
59 |
private JLabel labelWarning = null; |
60 |
private JLabel labelCacheSize = null; |
61 |
private JLabel labelLevels = null; |
62 |
private JLabel labelStruct = null; |
63 |
private JLabel labelTileSize = null; |
64 |
private JLabel labelWMSTileSize = null; |
65 |
private JLabel labelPath = null; |
66 |
private JFormattedTextField textFieldCacheSize = null; |
67 |
private JFormattedTextField textFieldLevels = null; |
68 |
private JFormattedTextField textFieldTileSize = null; |
69 |
private JFormattedTextField textFieldWMSTileSize = null; |
70 |
private JTextField textFieldPath = null; |
71 |
private JComboBox comboBoxStruct = null; |
72 |
private JButton buttonRemove = null; |
73 |
|
74 |
/**
|
75 |
*Inicializa componentes gr?ficos y traduce
|
76 |
*/
|
77 |
public TileCachePreferencesPanel() {
|
78 |
init(); |
79 |
translate(); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Define todas las traducciones de PreferenceCache
|
84 |
*/
|
85 |
protected void translate() { |
86 |
setBorder(BorderFactory.createTitledBorder(getText(this, "tilecache"))); |
87 |
getLabelWarning().setText(getText(this, "preference_cache_warning")); |
88 |
getLabelCacheSize().setText(getText(this, "tamanyo_max_tilecache") + ":"); |
89 |
getLabelLevels().setText(getText(this, "res_levels") + ":"); |
90 |
getLabelTileSize().setText(getText(this, "tilesize") + ":"); |
91 |
getLabelWMSTileSize().setText("WMS/WCS " + getText(this, "tilesize") + ":"); |
92 |
getLabelStruct().setText(getText(this, "tilecache_struct") + ":"); |
93 |
getButtonRemove().setText(getText(this, "remove_cache")); |
94 |
getLabelPath().setText(getText(this, "path_tilecache")); |
95 |
} |
96 |
|
97 |
protected void init() { |
98 |
GridBagConstraints gridBagConstraints;
|
99 |
|
100 |
setLayout(new GridBagLayout()); |
101 |
|
102 |
gridBagConstraints = new GridBagConstraints(); |
103 |
gridBagConstraints.gridwidth = 2;
|
104 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
105 |
gridBagConstraints.weightx = 1.0;
|
106 |
gridBagConstraints.insets = new Insets(5, 5, 2, 5); |
107 |
add(getLabelWarning(), gridBagConstraints); |
108 |
|
109 |
gridBagConstraints = new GridBagConstraints(); |
110 |
gridBagConstraints.gridx = 0;
|
111 |
gridBagConstraints.gridy = 1;
|
112 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
113 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
114 |
add(getLabelCacheSize(), gridBagConstraints); |
115 |
|
116 |
gridBagConstraints = new GridBagConstraints(); |
117 |
gridBagConstraints.gridx = 0;
|
118 |
gridBagConstraints.gridy = 2;
|
119 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
120 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
121 |
add(getLabelLevels(), gridBagConstraints); |
122 |
|
123 |
gridBagConstraints = new GridBagConstraints(); |
124 |
gridBagConstraints.gridx = 0;
|
125 |
gridBagConstraints.gridy = 3;
|
126 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
127 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
128 |
add(getLabelTileSize(), gridBagConstraints); |
129 |
|
130 |
gridBagConstraints = new GridBagConstraints(); |
131 |
gridBagConstraints.gridx = 0;
|
132 |
gridBagConstraints.gridy = 4;
|
133 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
134 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
135 |
add(getLabelWMSTileSize(), gridBagConstraints); |
136 |
|
137 |
gridBagConstraints = new GridBagConstraints(); |
138 |
gridBagConstraints.gridx = 0;
|
139 |
gridBagConstraints.gridy = 5;
|
140 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
141 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
142 |
add(getLabelStruct(), gridBagConstraints); |
143 |
|
144 |
gridBagConstraints = new GridBagConstraints(); |
145 |
gridBagConstraints.gridx = 0;
|
146 |
gridBagConstraints.gridy = 6;
|
147 |
gridBagConstraints.gridwidth = 2;
|
148 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
149 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
150 |
add(getButtonRemove(), gridBagConstraints); |
151 |
|
152 |
gridBagConstraints = new GridBagConstraints(); |
153 |
gridBagConstraints.gridx = 0;
|
154 |
gridBagConstraints.gridy = 7;
|
155 |
gridBagConstraints.anchor = GridBagConstraints.EAST;
|
156 |
gridBagConstraints.insets = new Insets(2, 5, 2, 2); |
157 |
add(getLabelPath(), gridBagConstraints); |
158 |
|
159 |
gridBagConstraints = new GridBagConstraints(); |
160 |
gridBagConstraints.gridx = 1;
|
161 |
gridBagConstraints.gridy = 1;
|
162 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
163 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
164 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
165 |
add(getTextFieldCacheSize(), gridBagConstraints); |
166 |
|
167 |
gridBagConstraints = new GridBagConstraints(); |
168 |
gridBagConstraints.gridx = 1;
|
169 |
gridBagConstraints.gridy = 2;
|
170 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
171 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
172 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
173 |
add(getTextFieldLevels(), gridBagConstraints); |
174 |
|
175 |
gridBagConstraints = new GridBagConstraints(); |
176 |
gridBagConstraints.gridx = 1;
|
177 |
gridBagConstraints.gridy = 3;
|
178 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
179 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
180 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
181 |
add(getTextFieldTileSize(), gridBagConstraints); |
182 |
|
183 |
gridBagConstraints = new GridBagConstraints(); |
184 |
gridBagConstraints.gridx = 1;
|
185 |
gridBagConstraints.gridy = 4;
|
186 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
187 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
188 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
189 |
add(getTextFieldWMSTileSize(), gridBagConstraints); |
190 |
|
191 |
gridBagConstraints = new GridBagConstraints(); |
192 |
gridBagConstraints.gridx = 1;
|
193 |
gridBagConstraints.gridy = 5;
|
194 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
195 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
196 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
197 |
add(getComboBoxStruct(), gridBagConstraints); |
198 |
|
199 |
gridBagConstraints = new GridBagConstraints(); |
200 |
gridBagConstraints.gridx = 1;
|
201 |
gridBagConstraints.gridy = 7;
|
202 |
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
|
203 |
gridBagConstraints.anchor = GridBagConstraints.WEST;
|
204 |
gridBagConstraints.insets = new Insets(2, 2, 2, 5); |
205 |
add(getTextFieldPath(), gridBagConstraints); |
206 |
|
207 |
} |
208 |
|
209 |
private JLabel getLabelWarning() { |
210 |
if (labelWarning == null) { |
211 |
labelWarning = new JLabel(); |
212 |
labelWarning.setForeground(new Color(255, 0, 0)); |
213 |
labelWarning.setHorizontalAlignment(SwingConstants.CENTER);
|
214 |
labelWarning.setPreferredSize(new Dimension(0, 32)); |
215 |
} |
216 |
return labelWarning;
|
217 |
} |
218 |
|
219 |
private JButton getButtonRemove() { |
220 |
if(buttonRemove == null) { |
221 |
buttonRemove = new JButton(); |
222 |
buttonRemove.addActionListener(this);
|
223 |
} |
224 |
return buttonRemove;
|
225 |
} |
226 |
|
227 |
private JComboBox getComboBoxStruct() { |
228 |
if (comboBoxStruct == null) { |
229 |
comboBoxStruct = new JComboBox(); |
230 |
comboBoxStruct.setModel(new DefaultComboBoxModel(new String[] { "FLATX" })); |
231 |
} |
232 |
return comboBoxStruct;
|
233 |
} |
234 |
|
235 |
private JTextField getTextFieldPath() { |
236 |
if (textFieldPath == null) { |
237 |
textFieldPath = new JTextField(); |
238 |
} |
239 |
return textFieldPath;
|
240 |
} |
241 |
|
242 |
private JFormattedTextField getTextFieldCacheSize() { |
243 |
if (textFieldCacheSize == null) { |
244 |
NumberFormat integerFormat = NumberFormat.getNumberInstance(); |
245 |
integerFormat.setParseIntegerOnly(true);
|
246 |
textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory( |
247 |
new NumberFormatter(integerFormat), |
248 |
new NumberFormatter(integerFormat), |
249 |
new NumberFormatter(integerFormat))); |
250 |
} |
251 |
return textFieldCacheSize;
|
252 |
} |
253 |
|
254 |
private JFormattedTextField getTextFieldTileSize() { |
255 |
if (textFieldTileSize == null) { |
256 |
NumberFormat integerFormat = NumberFormat.getNumberInstance(); |
257 |
integerFormat.setParseIntegerOnly(true);
|
258 |
textFieldTileSize = new JFormattedTextField(new DefaultFormatterFactory( |
259 |
new NumberFormatter(integerFormat), |
260 |
new NumberFormatter(integerFormat), |
261 |
new NumberFormatter(integerFormat))); |
262 |
} |
263 |
return textFieldTileSize;
|
264 |
} |
265 |
|
266 |
private JFormattedTextField getTextFieldWMSTileSize() { |
267 |
if (textFieldWMSTileSize == null) { |
268 |
NumberFormat integerFormat = NumberFormat.getNumberInstance(); |
269 |
integerFormat.setParseIntegerOnly(true);
|
270 |
textFieldWMSTileSize = new JFormattedTextField(new DefaultFormatterFactory( |
271 |
new NumberFormatter(integerFormat), |
272 |
new NumberFormatter(integerFormat), |
273 |
new NumberFormatter(integerFormat))); |
274 |
} |
275 |
return textFieldWMSTileSize;
|
276 |
} |
277 |
|
278 |
private JFormattedTextField getTextFieldLevels() { |
279 |
if (textFieldLevels == null) { |
280 |
NumberFormat integerFormat = NumberFormat.getNumberInstance(); |
281 |
integerFormat.setParseIntegerOnly(true);
|
282 |
textFieldLevels = new JFormattedTextField(new DefaultFormatterFactory( |
283 |
new NumberFormatter(integerFormat), |
284 |
new NumberFormatter(integerFormat), |
285 |
new NumberFormatter(integerFormat))); |
286 |
} |
287 |
return textFieldLevels;
|
288 |
} |
289 |
|
290 |
private JLabel getLabelPath() { |
291 |
if (labelPath == null) |
292 |
labelPath = new JLabel(); |
293 |
return labelPath;
|
294 |
} |
295 |
|
296 |
private JLabel getLabelCacheSize() { |
297 |
if (labelCacheSize == null) |
298 |
labelCacheSize = new JLabel(); |
299 |
return labelCacheSize;
|
300 |
} |
301 |
|
302 |
private JLabel getLabelLevels() { |
303 |
if (labelLevels == null) |
304 |
labelLevels = new JLabel(); |
305 |
return labelLevels;
|
306 |
} |
307 |
|
308 |
private JLabel getLabelStruct() { |
309 |
if (labelStruct == null) |
310 |
labelStruct = new JLabel(); |
311 |
return labelStruct;
|
312 |
} |
313 |
|
314 |
private JLabel getLabelTileSize() { |
315 |
if (labelTileSize == null) |
316 |
labelTileSize = new JLabel(); |
317 |
return labelTileSize;
|
318 |
} |
319 |
|
320 |
private JLabel getLabelWMSTileSize() { |
321 |
if (labelWMSTileSize == null) |
322 |
labelWMSTileSize = new JLabel(); |
323 |
return labelWMSTileSize;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* Establece los valores por defecto de la Cache
|
328 |
*/
|
329 |
public void initializeDefaults() { |
330 |
getTextFieldCacheSize().setValue(Configuration.getDefaultValue("tilecache_size")); |
331 |
getTextFieldTileSize().setValue(Configuration.getDefaultValue("tilesize")); |
332 |
getTextFieldWMSTileSize().setValue(Configuration.getDefaultValue("tilesizewms")); |
333 |
getTextFieldLevels().setValue(Configuration.getDefaultValue("tile_levels")); |
334 |
getTextFieldPath().setText(Configuration.getDefaultValue("path_tilecache").toString()); |
335 |
String struct = (String) Configuration.getDefaultValue("cache_struct"); |
336 |
if(struct != null) { |
337 |
for (int i = 0; i < getComboBoxStruct().getItemCount(); i++) |
338 |
if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
|
339 |
getComboBoxStruct().setSelectedIndex(i); |
340 |
break;
|
341 |
} |
342 |
} |
343 |
} |
344 |
|
345 |
/**
|
346 |
* Establece los valores que ha definido el usuario de la Cache
|
347 |
*/
|
348 |
public void initializeValues() { |
349 |
getTextFieldCacheSize().setValue(Configuration.getValue("tilecache_size", Integer.valueOf(TileCacheLibrary.MAX_CACHE_SIZE))); |
350 |
getTextFieldTileSize().setValue(Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILEWIDTH))); |
351 |
getTextFieldWMSTileSize().setValue(Configuration.getValue("tilesizewms", TILE_SIZE_WMS)); |
352 |
getTextFieldLevels().setValue(Configuration.getValue("tile_levels", Integer.valueOf(TileCacheLibrary.DEFAULT_LEVELS))); |
353 |
getTextFieldPath().setText(Configuration.getValue("path_tilecache", RasterLibrary.pathTileCache)); |
354 |
String struct = Configuration.getValue("cache_struct", TileCacheLibrary.DEFAULT_STRUCTURE); |
355 |
if(struct != null) { |
356 |
for (int i = 0; i < getComboBoxStruct().getItemCount(); i++) |
357 |
if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
|
358 |
getComboBoxStruct().setSelectedIndex(i); |
359 |
break;
|
360 |
} |
361 |
} |
362 |
} |
363 |
|
364 |
/**
|
365 |
* Guarda los valores de la cache establecidos por el usuario
|
366 |
*/
|
367 |
public void storeValues() { |
368 |
Integer tilecachesize = null; |
369 |
try {
|
370 |
String s = getTextFieldCacheSize().getText().replaceAll(",", ""); |
371 |
tilecachesize = new Integer(s); |
372 |
Configuration.setValue("tilecache_size", tilecachesize); |
373 |
} catch (NumberFormatException e) { |
374 |
|
375 |
} |
376 |
|
377 |
Integer tilesize = null; |
378 |
try {
|
379 |
String s = getTextFieldTileSize().getText().replaceAll(",", ""); |
380 |
tilesize = new Integer(s); |
381 |
Configuration.setValue("tilesize", tilesize); |
382 |
} catch (NumberFormatException e) { |
383 |
|
384 |
} |
385 |
|
386 |
Integer tilesizewms = null; |
387 |
try {
|
388 |
String s = getTextFieldWMSTileSize().getText().replaceAll(",", ""); |
389 |
tilesizewms = new Integer(s); |
390 |
Configuration.setValue("tilesizewms", tilesizewms); |
391 |
} catch (NumberFormatException e) { |
392 |
|
393 |
} |
394 |
|
395 |
Integer tilelevels = null; |
396 |
try {
|
397 |
String s = getTextFieldLevels().getText().replaceAll(",", ""); |
398 |
tilelevels = new Integer(s); |
399 |
Configuration.setValue("tile_levels", tilelevels); |
400 |
} catch (NumberFormatException e) { |
401 |
|
402 |
} |
403 |
|
404 |
Configuration.setValue("cache_struct", getComboBoxStruct().getSelectedItem() != null ? getComboBoxStruct().getSelectedItem().toString() : TileCacheLibrary.DEFAULT_STRUCTURE); |
405 |
Configuration.setValue("path_tilecache", getTextFieldPath().getText()); |
406 |
} |
407 |
|
408 |
public void actionPerformed(ActionEvent e) { |
409 |
String path = getTextFieldPath().getText();
|
410 |
IWindow parent = PluginServices.getMDIManager().getActiveWindow(); |
411 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
412 |
for (int i = 0; i < wList.length; i++) { |
413 |
if(wList[i] instanceof DlgPreferences) |
414 |
parent = wList[i]; |
415 |
} |
416 |
|
417 |
if(CacheExtension.messageBoxYesOrNot(PluginServices.getText(this, "remove_directory") + "<BR>" + path, parent)) { |
418 |
File f = new File(path); |
419 |
if(f.exists()) {
|
420 |
if(!deleteDirectory(f)) {
|
421 |
CacheExtension.messageBoxError("open_files", parent);
|
422 |
} |
423 |
}else
|
424 |
CacheExtension.messageBoxError("path_not_exists", parent);
|
425 |
} |
426 |
} |
427 |
|
428 |
public boolean deleteDirectory(File directory) { |
429 |
File[] files = directory.listFiles(); |
430 |
for(int i = 0; i < files.length; i++) { |
431 |
if(files[i].isDirectory()) {
|
432 |
this.deleteDirectory(files[i]);
|
433 |
} else {
|
434 |
files[i].delete(); |
435 |
} |
436 |
} |
437 |
return directory.delete();
|
438 |
} |
439 |
} |