Revision 399

View differences:

org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/RasterExtension.java
65 65
import org.gvsig.raster.app.extension.tool.properties.panel.TransparencyPanel;
66 66
import org.gvsig.raster.app.extension.tool.rasterresolution.ZoomPixelCursorTocMenuEntry;
67 67
import org.gvsig.raster.app.extension.tool.saveas.SaveAsTocMenuEntry;
68
import org.gvsig.raster.cache.tile.TileCache;
69
import org.gvsig.raster.cache.tile.TileCacheLibrary;
70
import org.gvsig.raster.cache.tile.TileCacheLocator;
71 68
import org.gvsig.raster.fmap.FmapRasterLibrary;
72 69
import org.gvsig.raster.fmap.config.Configuration;
73 70
import org.gvsig.raster.fmap.config.ConfigurationEvent;
......
636 633
			return;
637 634
		}
638 635

  
639
		if (e.getKey().equals("path_tilecache")) {
640
			if(e.getValue() instanceof String) {
641
				String value = (String)e.getValue();
642
				if(value != null && value.compareTo("") != 0) {
643
					RasterLibrary.pathTileCache =  (String)e.getValue();
644
					TileCache tc = TileCacheLocator.getManager().getTileCache(RasterLibrary.pathTileCache);
645
					tc.updateBaseDirectory(RasterLibrary.pathTileCache);
646
				}
647
			}
648
			return;
649
		}
650
		
651
		if (e.getKey().equals("tile_levels")) {
652
			if(e.getValue() instanceof String)
653
				try {
654
					TileCacheLibrary.DEFAULT_LEVELS = new Integer((String) e
655
							.getValue()).intValue();
656
				} catch (NumberFormatException exc) {
657
					//Valor por defecto en la cache
658
				}
659
			if(e.getValue() instanceof Integer)
660
				TileCacheLibrary.DEFAULT_LEVELS = ((Integer) e.getValue()).intValue();
661
			return;
662
		}
663
		
664
		if (e.getKey().equals("tilesize")) {
665
			if(e.getValue() instanceof String)
666
				try {
667
					TileCacheLibrary.DEFAULT_TILESIZE = new Integer((String) e
668
							.getValue()).intValue();
669
				} catch (NumberFormatException exc) {
670
					//Valor por defecto en la cache
671
				}
672
			if(e.getValue() instanceof Integer)
673
				TileCacheLibrary.DEFAULT_TILESIZE = ((Integer) e.getValue()).intValue();
674
			return;
675
		}
676
		
677
		if (e.getKey().equals("tilecache_size")) {
678
			if(e.getValue() instanceof String)
679
				try {
680
					TileCacheLibrary.MAX_CACHE_SIZE = new Integer((String) e
681
							.getValue()).intValue();
682
				} catch (NumberFormatException exc) {
683
					//Valor por defecto en la cache
684
				}
685
			if(e.getValue() instanceof Integer)
686
				TileCacheLibrary.MAX_CACHE_SIZE = ((Integer) e.getValue()).intValue();
687
			return;
688
		}
689
		
690
		if (e.getKey().equals("cache_struct")) {
691
			if(e.getValue() instanceof String)
692
				TileCacheLibrary.DEFAULT_STRUCTURE = (String)e.getValue();
693
			return;
694
		}
695 636
	}
696 637

  
697 638
	/*
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/raster/gui/preference/panel/PreferenceTileCache.java
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.app.extension.raster.gui.preference.panel;
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.fmap.config.Configuration;
51
import org.gvsig.raster.util.BasePanel;
52
import org.gvsig.raster.util.RasterToolsUtil;
53
/**
54
 * PreferenceCache es la clase que se encarga de configurar en RasterPreferences
55
 * las opciones de cacheamiento de capas en Raster.
56
 *
57
 * @version 14/12/2007
58
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
59
 */
60
public class PreferenceTileCache extends BasePanel implements ActionListener {
61
	protected static final long serialVersionUID      = 1L;
62
	private JLabel              labelWarning          = null;
63
	private JLabel              labelCacheSize        = null;
64
	private JLabel              labelLevels           = null;
65
	private JLabel              labelStruct           = null;
66
	private JLabel              labelTileSize         = null;
67
	private JLabel              labelPath             = null;
68
	private JFormattedTextField textFieldCacheSize    = null;
69
	private JFormattedTextField textFieldLevels       = null;
70
	private JFormattedTextField textFieldTileSize     = null;
71
	private JTextField          textFieldPath         = null;
72
	private JComboBox           comboBoxStruct        = null;
73
	private JButton             buttonRemove          = null;
74

  
75
	/**
76
	 *Inicializa componentes gr?ficos y traduce
77
	 */
78
	public PreferenceTileCache() {
79
		init();
80
		translate();
81
	}
82

  
83
	/**
84
	 * Define todas las traducciones de PreferenceCache
85
	 */
86
	protected void translate() {
87
		setBorder(BorderFactory.createTitledBorder(getText(this, "tilecache")));
88
		getLabelWarning().setText(getText(this, "preference_cache_warning"));
89
		getLabelCacheSize().setText(getText(this, "tamanyo_max_tilecache") + ":");
90
		getLabelLevels().setText(getText(this, "res_levels") + ":");
91
		getLabelTileSize().setText(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(getLabelStruct(), gridBagConstraints);
136
		
137
		gridBagConstraints = new GridBagConstraints();
138
		gridBagConstraints.gridx = 0;
139
		gridBagConstraints.gridy = 5;
140
		gridBagConstraints.gridwidth = 2;
141
		gridBagConstraints.anchor = GridBagConstraints.WEST;
142
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
143
		add(getButtonRemove(), gridBagConstraints);
144
		
145
		gridBagConstraints = new GridBagConstraints();
146
		gridBagConstraints.gridx = 0;
147
		gridBagConstraints.gridy = 6;
148
		gridBagConstraints.anchor = GridBagConstraints.EAST;
149
		gridBagConstraints.insets = new Insets(2, 5, 2, 2);
150
		add(getLabelPath(), gridBagConstraints);
151

  
152
		gridBagConstraints = new GridBagConstraints();
153
		gridBagConstraints.gridx = 1;
154
		gridBagConstraints.gridy = 1;
155
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
156
		gridBagConstraints.anchor = GridBagConstraints.WEST;
157
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
158
		add(getTextFieldCacheSize(), gridBagConstraints);
159
		
160
		gridBagConstraints = new GridBagConstraints();
161
		gridBagConstraints.gridx = 1;
162
		gridBagConstraints.gridy = 2;
163
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
164
		gridBagConstraints.anchor = GridBagConstraints.WEST;
165
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
166
		add(getTextFieldLevels(), gridBagConstraints);
167
		
168
		gridBagConstraints = new GridBagConstraints();
169
		gridBagConstraints.gridx = 1;
170
		gridBagConstraints.gridy = 3;
171
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
172
		gridBagConstraints.anchor = GridBagConstraints.WEST;
173
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
174
		add(getTextFieldTileSize(), gridBagConstraints);
175
		
176
		gridBagConstraints = new GridBagConstraints();
177
		gridBagConstraints.gridx = 1;
178
		gridBagConstraints.gridy = 4;
179
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
180
		gridBagConstraints.anchor = GridBagConstraints.WEST;
181
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
182
		add(getComboBoxStruct(), gridBagConstraints);
183
		
184
		gridBagConstraints = new GridBagConstraints();
185
		gridBagConstraints.gridx = 1;
186
		gridBagConstraints.gridy = 6;
187
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
188
		gridBagConstraints.anchor = GridBagConstraints.WEST;
189
		gridBagConstraints.insets = new Insets(2, 2, 2, 5);
190
		add(getTextFieldPath(), gridBagConstraints);
191
		
192
	}
193

  
194
	private JLabel getLabelWarning() {
195
		if (labelWarning == null) {
196
			labelWarning = new JLabel();
197
			labelWarning.setForeground(new Color(255, 0, 0));
198
			labelWarning.setHorizontalAlignment(SwingConstants.CENTER);
199
			labelWarning.setPreferredSize(new Dimension(0, 32));
200
		}
201
		return labelWarning;
202
	}
203

  
204
	private JButton getButtonRemove() {
205
		if(buttonRemove == null) {
206
			buttonRemove = new JButton();
207
			buttonRemove.addActionListener(this);
208
		}
209
		return buttonRemove;
210
	}
211
	
212
	private JComboBox getComboBoxStruct() {
213
		if (comboBoxStruct == null) {
214
			comboBoxStruct = new JComboBox();
215
			comboBoxStruct.setModel(new DefaultComboBoxModel(new String[] { "FLATX" }));
216
		}
217
		return comboBoxStruct;
218
	}
219
	
220
	private JTextField getTextFieldPath() {
221
		if (textFieldPath == null) {
222
			textFieldPath = new JTextField();
223
		}
224
		return textFieldPath;
225
	}
226
	
227
	private JFormattedTextField getTextFieldCacheSize() {
228
		if (textFieldCacheSize == null) {
229
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
230
			integerFormat.setParseIntegerOnly(true);
231
			textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory(
232
					new NumberFormatter(integerFormat),
233
					new NumberFormatter(integerFormat),
234
					new NumberFormatter(integerFormat)));
235
		}
236
		return textFieldCacheSize;
237
	}
238
	
239
	private JFormattedTextField getTextFieldTileSize() {
240
		if (textFieldTileSize == null) {
241
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
242
			integerFormat.setParseIntegerOnly(true);
243
			textFieldTileSize = new JFormattedTextField(new DefaultFormatterFactory(
244
					new NumberFormatter(integerFormat),
245
					new NumberFormatter(integerFormat),
246
					new NumberFormatter(integerFormat)));
247
		}
248
		return textFieldTileSize;
249
	}
250
	
251
	private JFormattedTextField getTextFieldLevels() {
252
		if (textFieldLevels == null) {
253
			NumberFormat integerFormat = NumberFormat.getNumberInstance();
254
			integerFormat.setParseIntegerOnly(true);
255
			textFieldLevels = new JFormattedTextField(new DefaultFormatterFactory(
256
					new NumberFormatter(integerFormat),
257
					new NumberFormatter(integerFormat),
258
					new NumberFormatter(integerFormat)));
259
		}
260
		return textFieldLevels;
261
	}
262

  
263
	private JLabel getLabelPath() {
264
		if (labelPath == null)
265
			labelPath = new JLabel();
266
		return labelPath;
267
	}
268
	
269
	private JLabel getLabelCacheSize() {
270
		if (labelCacheSize == null)
271
			labelCacheSize = new JLabel();
272
		return labelCacheSize;
273
	}
274
	
275
	private JLabel getLabelLevels() {
276
		if (labelLevels == null)
277
			labelLevels = new JLabel();
278
		return labelLevels;
279
	}
280
	
281
	private JLabel getLabelStruct() {
282
		if (labelStruct == null)
283
			labelStruct = new JLabel();
284
		return labelStruct;
285
	}
286
	
287
	private JLabel getLabelTileSize() {
288
		if (labelTileSize == null)
289
			labelTileSize = new JLabel();
290
		return labelTileSize;
291
	}
292

  
293
	/**
294
	 * Establece los valores por defecto de la Cache
295
	 */
296
	public void initializeDefaults() {
297
		getTextFieldCacheSize().setValue(Configuration.getDefaultValue("tilecache_size"));
298
		getTextFieldTileSize().setValue(Configuration.getDefaultValue("tilesize"));
299
		getTextFieldLevels().setValue(Configuration.getDefaultValue("tile_levels"));
300
		getTextFieldPath().setText(Configuration.getDefaultValue("path_tilecache").toString());
301
		String struct = (String) Configuration.getDefaultValue("cache_struct");
302
		if(struct != null) {
303
			for (int i = 0; i < getComboBoxStruct().getItemCount(); i++)
304
				if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
305
					getComboBoxStruct().setSelectedIndex(i);
306
					break;
307
				}
308
		}
309
	}
310

  
311
	/**
312
	 * Establece los valores que ha definido el usuario de la Cache
313
	 */
314
	public void initializeValues() {
315
		getTextFieldCacheSize().setValue(Configuration.getValue("tilecache_size", Integer.valueOf(TileCacheLibrary.MAX_CACHE_SIZE)));
316
		getTextFieldTileSize().setValue(Configuration.getValue("tilesize", Integer.valueOf(TileCacheLibrary.DEFAULT_TILESIZE)));
317
		getTextFieldLevels().setValue(Configuration.getValue("tile_levels", Integer.valueOf(TileCacheLibrary.DEFAULT_LEVELS)));
318
		getTextFieldPath().setText(Configuration.getValue("path_tilecache", RasterLibrary.pathTileCache));
319
		String struct = Configuration.getValue("cache_struct", TileCacheLibrary.DEFAULT_STRUCTURE);
320
		if(struct != null) {
321
			for (int i = 0; i < getComboBoxStruct().getItemCount(); i++)
322
				if (getComboBoxStruct().getItemAt(i).toString().equals(struct.toString())) {
323
					getComboBoxStruct().setSelectedIndex(i);
324
					break;
325
				}
326
		}
327
	}
328

  
329
	/**
330
	 * Guarda los valores de la cache establecidos por el usuario
331
	 */
332
	public void storeValues() {
333
		Configuration.setValue("tilecache_size", getTextFieldCacheSize().getText());
334
		Configuration.setValue("tilesize", getTextFieldTileSize().getText());
335
		Configuration.setValue("tile_levels", getTextFieldLevels().getText());
336
		Configuration.setValue("cache_struct", getComboBoxStruct().getSelectedItem() != null ? getComboBoxStruct().getSelectedItem().toString() : TileCacheLibrary.DEFAULT_STRUCTURE);
337
		Configuration.setValue("path_tilecache", getTextFieldPath().getText());
338
	}
339

  
340
	public void actionPerformed(ActionEvent e) {
341
		String path = getTextFieldPath().getText();
342
		IWindow parent = PluginServices.getMDIManager().getActiveWindow();
343
		IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
344
		for (int i = 0; i < wList.length; i++) {
345
			if(wList[i] instanceof DlgPreferences)
346
				parent = wList[i];
347
		}
348
		
349
		if(RasterToolsUtil.messageBoxYesOrNot(PluginServices.getText(this, "remove_directory") + "<BR>" + path, parent)) {
350
			File f = new File(path);
351
			if(f.exists()) {
352
				if(!deleteDirectory(f)) {
353
					RasterToolsUtil.messageBoxError("open_files", parent);
354
				}
355
			}else
356
				RasterToolsUtil.messageBoxError("path_not_exists", parent);
357
		}
358
	}
359

  
360
	public boolean deleteDirectory(File directory) {  
361
		File[] files = directory.listFiles();  
362
		for(int i = 0; i < files.length; i++) {  
363
			if(files[i].isDirectory()) {  
364
				this.deleteDirectory(files[i]);  
365
			} else {  
366
				files[i].delete();  
367
			}  
368
		}  
369
		return directory.delete();  
370
	}  
371
}
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/src/main/java/org/gvsig/raster/app/extension/raster/gui/preference/RasterPreferences.java
39 39
import org.gvsig.raster.app.extension.raster.gui.preference.panel.PreferenceNoData;
40 40
import org.gvsig.raster.app.extension.raster.gui.preference.panel.PreferenceOverviews;
41 41
import org.gvsig.raster.app.extension.raster.gui.preference.panel.PreferenceTemporal;
42
import org.gvsig.raster.app.extension.raster.gui.preference.panel.PreferenceTileCache;
43 42

  
44 43
/**
45 44
 * RasterPreferences es un panel de preferencias situado a nivel de las
......
60 59
	private PreferenceTemporal  temporal  = null;
61 60
	private PreferenceGeneral   general   = null;
62 61
	private PreferenceLoadLayer loadLayer = null;
63
	private PreferenceTileCache tilecache = null;
64 62

  
65 63
	/**
66 64
	 * Constructor de la clase RasterPreferences
......
122 120
		gridBagConstraints.gridy = 5;
123 121
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
124 122
		panel.add(getPreferenceCache(), gridBagConstraints);
125
		
126
		gridBagConstraints = new GridBagConstraints();
127
		gridBagConstraints.gridx = 0;
128
		gridBagConstraints.gridy = 6;
129
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
130
		panel.add(getPreferenceTileCache(), gridBagConstraints);
131 123

  
132 124
		gridBagConstraints = new GridBagConstraints();
133 125
		gridBagConstraints.gridx = 0;
134
		gridBagConstraints.gridy = 7;
126
		gridBagConstraints.gridy = 6;
135 127
		gridBagConstraints.weightx = 1.0;
136 128
		gridBagConstraints.weighty = 1.0;
137 129
		panel.add(new JPanel(), gridBagConstraints);
......
154 146
		}
155 147
		return noData;
156 148
	}
157

  
158
	/**
159
	 * Gets a tile cache configuration panel
160
	 * @return
161
	 */
162
	private PreferenceTileCache getPreferenceTileCache() {
163
		if (tilecache == null) {
164
			tilecache = new PreferenceTileCache();
165
		}
166
		return tilecache;
167
	}
168 149
	
169 150
	/**
170 151
	 * Devuelve el panel de configuracion general de Raster. Aqui es donde se
......
229 210
		getPreferenceTemporal().initializeValues();
230 211
		getPreferenceGeneral().initializeValues();
231 212
		getPreferenceLoadLayer().initializeValues();
232
		getPreferenceTileCache().initializeValues();
233 213
	}
234 214

  
235 215
	/*
......
243 223
		getPreferenceTemporal().storeValues();
244 224
		getPreferenceGeneral().storeValues();
245 225
		getPreferenceLoadLayer().storeValues();
246
		getPreferenceTileCache().storeValues();
247 226
	}
248 227

  
249 228
	/*
......
257 236
		getPreferenceTemporal().initializeDefaults();
258 237
		getPreferenceGeneral().initializeDefaults();
259 238
		getPreferenceLoadLayer().initializeDefaults();
260
		getPreferenceTileCache().initializeDefaults();
261 239
	}
262 240

  
263 241
	/*
org.gvsig.raster.app/trunk/org.gvsig.raster.app/org.gvsig.raster.app.tools/distribution/distribution.xml
34 34
				<include>org.gvsig:org.gvsig.jecw:jar</include>
35 35
				<include>org.gvsig:org.gvsig.jmrsid:jar</include>
36 36
				<include>org.gvsig:org.gvsig.jpotrace:jar</include>
37
				<include>org.gvsig:org.gvsig.raster.cache.api:jar</include>
38
				<include>org.gvsig:org.gvsig.raster.cache.impl:jar</include>
37
				<include>org.gvsig:org.gvsig.raster.cache.lib.api:jar</include>
38
				<include>org.gvsig:org.gvsig.raster.cache.lib.impl:jar</include>
39
				<include>essi-unidata:netcdf-java:jar</include>
39 40
			</includes>
40 41
		</dependencySet>
41 42
	</dependencySets>

Also available in: Unified diff