Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / panels / PreferenceCache.java @ 22364

History | View | Annotate | Download (10.3 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
package org.gvsig.raster.gui.preferences.panels;
20

    
21
import java.awt.Color;
22
import java.awt.Dimension;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.Insets;
26
import java.text.NumberFormat;
27

    
28
import javax.swing.BorderFactory;
29
import javax.swing.DefaultComboBoxModel;
30
import javax.swing.JComboBox;
31
import javax.swing.JFormattedTextField;
32
import javax.swing.JLabel;
33
import javax.swing.SwingConstants;
34
import javax.swing.text.DefaultFormatterFactory;
35
import javax.swing.text.NumberFormatter;
36

    
37
import org.gvsig.raster.Configuration;
38
import org.gvsig.raster.RasterLibrary;
39
import org.gvsig.raster.util.BasePanel;
40
/**
41
 * PreferenceCache es la clase que se encarga de configurar en RasterPreferences
42
 * las opciones de cacheamiento de capas en Raster.
43
 * 
44
 * @version 14/12/2007
45
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
46
 */
47
public class PreferenceCache extends BasePanel {
48
        protected static final long serialVersionUID      = 1L;
49
        private JLabel              labelWarning          = null;
50
        private JLabel              labelBlockHeight      = null;
51
        private JComboBox           comboBoxBlockHeight   = null;
52
        private JLabel              labelCacheSize        = null;
53
        private JFormattedTextField textFieldCacheSize    = null;
54
        private JLabel              labelPagsPerGroup     = null;
55
        private JFormattedTextField textFieldPagsPerGroup = null;
56
        private JLabel              labelPageSize         = null;
57
        private JFormattedTextField textFieldPageSize     = null;
58
        
59
        /**
60
         *Inicializa componentes gr?ficos y traduce
61
         */
62
        public PreferenceCache() {
63
                init();
64
                translate();
65
        }
66
        
67
        /**
68
         * Define todas las traducciones de PreferenceCache
69
         */
70
        protected void translate() {
71
                setBorder(BorderFactory.createTitledBorder(getText(this, "cache")));
72
                getLabelWarning().setText(getText(this, "preference_cache_warning"));
73
                getLabelCacheSize().setText(getText(this, "tamanyo") + ":");
74
                getLabelPagsPerGroup().setText(getText(this, "paginas_grupo") + ":");
75
                getLabelPageSize().setText(getText(this, "tamanyo_pagina") + ":");
76
                getLabelBlockHeight().setText(getText(this, "bloques_procesos") + ":");
77
        }
78

    
79
        protected void init() {
80
                GridBagConstraints gridBagConstraints;
81

    
82
                setLayout(new GridBagLayout());
83

    
84
                gridBagConstraints = new GridBagConstraints();
85
                gridBagConstraints.gridwidth = 2;
86
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
87
                gridBagConstraints.weightx = 1.0;
88
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
89
                add(getLabelWarning(), gridBagConstraints);
90

    
91
                gridBagConstraints = new GridBagConstraints();
92
                gridBagConstraints.gridx = 0;
93
                gridBagConstraints.gridy = 1;
94
                gridBagConstraints.anchor = GridBagConstraints.EAST;
95
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
96
                add(getLabelCacheSize(), gridBagConstraints);
97

    
98
                gridBagConstraints = new GridBagConstraints();
99
                gridBagConstraints.gridx = 0;
100
                gridBagConstraints.gridy = 2;
101
                gridBagConstraints.anchor = GridBagConstraints.EAST;
102
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
103
                add(getLabelPagsPerGroup(), gridBagConstraints);
104

    
105
                gridBagConstraints = new GridBagConstraints();
106
                gridBagConstraints.gridx = 0;
107
                gridBagConstraints.gridy = 3;
108
                gridBagConstraints.anchor = GridBagConstraints.EAST;
109
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
110
                add(getLabelPageSize(), gridBagConstraints);
111

    
112
                gridBagConstraints = new GridBagConstraints();
113
                gridBagConstraints.gridx = 0;
114
                gridBagConstraints.gridy = 4;
115
                gridBagConstraints.anchor = GridBagConstraints.EAST;
116
                gridBagConstraints.insets = new Insets(2, 5, 5, 2);
117
                add(getLabelBlockHeight(), gridBagConstraints);
118

    
119
                gridBagConstraints = new GridBagConstraints();
120
                gridBagConstraints.gridx = 1;
121
                gridBagConstraints.gridy = 1;
122
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
123
                gridBagConstraints.anchor = GridBagConstraints.WEST;
124
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
125
                add(getTextFieldCacheSize(), gridBagConstraints);
126

    
127
                gridBagConstraints = new GridBagConstraints();
128
                gridBagConstraints.gridx = 1;
129
                gridBagConstraints.gridy = 4;
130
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
131
                gridBagConstraints.anchor = GridBagConstraints.WEST;
132
                gridBagConstraints.insets = new Insets(2, 2, 5, 5);
133
                add(getComboBoxBlockHeight(), gridBagConstraints);
134

    
135
                gridBagConstraints = new GridBagConstraints();
136
                gridBagConstraints.gridx = 1;
137
                gridBagConstraints.gridy = 3;
138
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
139
                gridBagConstraints.anchor = GridBagConstraints.WEST;
140
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
141
                add(getTextFieldPageSize(), gridBagConstraints);
142

    
143
                gridBagConstraints = new GridBagConstraints();
144
                gridBagConstraints.gridx = 1;
145
                gridBagConstraints.gridy = 2;
146
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
147
                gridBagConstraints.anchor = GridBagConstraints.WEST;
148
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
149
                add(getTextFieldPagsPerGroup(), gridBagConstraints);
150
        }
151

    
152
        private JLabel getLabelWarning() {
153
                if (labelWarning == null) {
154
                        labelWarning = new JLabel();
155
                        labelWarning.setForeground(new Color(255, 0, 0));
156
                        labelWarning.setHorizontalAlignment(SwingConstants.CENTER);
157
                        labelWarning.setPreferredSize(new Dimension(0, 32));
158
                }
159
                return labelWarning;
160
        }
161

    
162
        private JFormattedTextField getTextFieldCacheSize() {
163
                if (textFieldCacheSize == null) {
164
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
165
                        integerFormat.setParseIntegerOnly(true);
166
                        textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory(
167
                                        new NumberFormatter(integerFormat),
168
                                        new NumberFormatter(integerFormat),
169
                                        new NumberFormatter(integerFormat)));
170
                }
171
                return textFieldCacheSize;
172
        }
173

    
174
        private JFormattedTextField getTextFieldPagsPerGroup() {
175
                if (textFieldPagsPerGroup == null) {
176
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
177
                        integerFormat.setParseIntegerOnly(true);
178
                        textFieldPagsPerGroup = new JFormattedTextField(new DefaultFormatterFactory(
179
                                        new NumberFormatter(integerFormat),
180
                                        new NumberFormatter(integerFormat),
181
                                        new NumberFormatter(integerFormat)));
182
                }
183
                return textFieldPagsPerGroup;
184
        }
185

    
186
        private JFormattedTextField getTextFieldPageSize() {
187
                if (textFieldPageSize == null) {
188
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
189
                        integerFormat.setParseIntegerOnly(true);
190
                        textFieldPageSize = new JFormattedTextField(new DefaultFormatterFactory(
191
                                        new NumberFormatter(integerFormat),
192
                                        new NumberFormatter(integerFormat),
193
                                        new NumberFormatter(integerFormat)));
194
                }
195
                return textFieldPageSize;
196
        }
197

    
198
        private JLabel getLabelCacheSize() {
199
                if (labelCacheSize == null) {
200
                        labelCacheSize = new JLabel();
201
                }
202
                return labelCacheSize;
203
        }
204

    
205
        private JLabel getLabelPagsPerGroup() {
206
                if (labelPagsPerGroup == null) {
207
                        labelPagsPerGroup = new JLabel();
208
                }
209
                return labelPagsPerGroup;
210
        }
211

    
212
        private JLabel getLabelPageSize() {
213
                if (labelPageSize == null) {
214
                        labelPageSize = new JLabel();
215
                }
216
                return labelPageSize;
217
        }
218

    
219
        private JLabel getLabelBlockHeight() {
220
                if (labelBlockHeight == null) {
221
                        labelBlockHeight = new JLabel();
222
                }
223
                return labelBlockHeight;
224
        }
225

    
226
        private JComboBox getComboBoxBlockHeight() {
227
                if (comboBoxBlockHeight == null) {
228
                        comboBoxBlockHeight = new JComboBox();
229
                        comboBoxBlockHeight.setModel(new DefaultComboBoxModel(new String[] { "128", "256", "512", "1024", "2048", "4096" }));
230
                }
231
                return comboBoxBlockHeight;
232
        }
233

    
234
        /**
235
         * Establece los valores por defecto de la Cache
236
         */
237
        public void initializeDefaults() {
238
                getTextFieldCacheSize().setValue((Long) Configuration.getDefaultValue("cache_size"));
239
                getTextFieldPageSize().setValue((Double) Configuration.getDefaultValue("cache_pagesize"));
240
                getTextFieldPagsPerGroup().setValue((Integer) Configuration.getDefaultValue("cache_pagspergroup"));
241

    
242
                Integer blockHeight = (Integer) Configuration.getDefaultValue("cache_blockheight");
243
                for (int i = 0; i < getComboBoxBlockHeight().getItemCount(); i++) {
244
                        if (getComboBoxBlockHeight().getItemAt(i).toString().equals(blockHeight.toString())) {
245
                                getComboBoxBlockHeight().setSelectedIndex(i);
246
                                break;
247
                        }
248
                }
249
        }
250

    
251
        /**
252
         * Establece los valores que ha definido el usuario de la Cache
253
         */
254
        public void initializeValues() {
255
                getTextFieldCacheSize().setValue(Configuration.getValue("cache_size", Long.valueOf(RasterLibrary.cacheSize)));
256
                getTextFieldPageSize().setValue(Configuration.getValue("cache_pagesize", Double.valueOf(RasterLibrary.pageSize)));
257
                getTextFieldPagsPerGroup().setValue(Configuration.getValue("cache_pagspergroup", Integer.valueOf(RasterLibrary.pagsPerGroup)));
258

    
259
                Integer blockHeight = Configuration.getValue("cache_blockheight", Integer.valueOf(RasterLibrary.blockHeight));
260
                for (int i = 0; i < getComboBoxBlockHeight().getItemCount(); i++) {
261
                        if (getComboBoxBlockHeight().getItemAt(i).toString().equals(blockHeight.toString())) {
262
                                getComboBoxBlockHeight().setSelectedIndex(i);
263
                                break;
264
                        }
265
                }
266
        }
267

    
268
        /**
269
         * Guarda los valores de la cache establecidos por el usuario
270
         */
271
        public void storeValues() {
272
                Configuration.setValue("cache_size", getTextFieldCacheSize().getText());
273
                Configuration.setValue("cache_pagesize", Double.valueOf(getTextFieldPageSize().getText()));
274
                Configuration.setValue("cache_pagspergroup", getTextFieldPagsPerGroup().getText());
275
                Configuration.setValue("cache_blockheight", getComboBoxBlockHeight().getSelectedItem().toString());
276
        }
277
}