Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / gui / preferences / panels / PreferenceCache.java @ 18014

History | View | Annotate | Download (9.83 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.PanelBase;
40
/**
41
 *
42
 * @version 14/12/2007
43
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
44
 */
45
public class PreferenceCache extends PanelBase {
46
        JLabel              labelWarning          = null;
47
        JLabel              labelBlockHeight      = null;
48
        JComboBox           comboBoxBlockHeight   = null;
49
        JLabel              labelCacheSize        = null;
50
        JFormattedTextField textFieldCacheSize    = null;
51
        JLabel              labelPagsPerGroup     = null;
52
        JFormattedTextField textFieldPagsPerGroup = null;
53
        JLabel              labelPageSize         = null;
54
        JFormattedTextField textFieldPageSize     = null;
55

    
56
        public PreferenceCache() {
57
                initialize();
58
                translate();
59
        }
60

    
61
        private void translate() {
62
                getPanel().setBorder(BorderFactory.createTitledBorder(getText(this, "cache")));
63
                getLabelWarning().setText(getText(this, "preference_cache_warning"));
64
                getLabelCacheSize().setText(getText(this, "tamanyo") + ":");
65
                getLabelPagsPerGroup().setText(getText(this, "paginas_grupo") + ":");
66
                getLabelPageSize().setText(getText(this, "tamanyo_pagina") + ":");
67
                getLabelBlockHeight().setText(getText(this, "bloques_procesos") + ":");
68
        }
69

    
70
        private void initialize() {
71
                GridBagConstraints gridBagConstraints;
72

    
73
                getPanel().setLayout(new GridBagLayout());
74

    
75
                gridBagConstraints = new GridBagConstraints();
76
                gridBagConstraints.gridwidth = 2;
77
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
78
                gridBagConstraints.weightx = 1.0;
79
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
80
                getPanel().add(getLabelWarning(), gridBagConstraints);
81

    
82
                gridBagConstraints = new GridBagConstraints();
83
                gridBagConstraints.gridx = 0;
84
                gridBagConstraints.gridy = 1;
85
                gridBagConstraints.anchor = GridBagConstraints.EAST;
86
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
87
                getPanel().add(getLabelCacheSize(), gridBagConstraints);
88

    
89
                gridBagConstraints = new GridBagConstraints();
90
                gridBagConstraints.gridx = 0;
91
                gridBagConstraints.gridy = 2;
92
                gridBagConstraints.anchor = GridBagConstraints.EAST;
93
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
94
                getPanel().add(getLabelPagsPerGroup(), gridBagConstraints);
95

    
96
                gridBagConstraints = new GridBagConstraints();
97
                gridBagConstraints.gridx = 0;
98
                gridBagConstraints.gridy = 3;
99
                gridBagConstraints.anchor = GridBagConstraints.EAST;
100
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
101
                getPanel().add(getLabelPageSize(), gridBagConstraints);
102

    
103
                gridBagConstraints = new GridBagConstraints();
104
                gridBagConstraints.gridx = 0;
105
                gridBagConstraints.gridy = 4;
106
                gridBagConstraints.anchor = GridBagConstraints.EAST;
107
                gridBagConstraints.insets = new Insets(2, 5, 5, 2);
108
                getPanel().add(getLabelBlockHeight(), gridBagConstraints);
109

    
110
                gridBagConstraints = new GridBagConstraints();
111
                gridBagConstraints.gridx = 1;
112
                gridBagConstraints.gridy = 1;
113
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
114
                gridBagConstraints.anchor = GridBagConstraints.WEST;
115
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
116
                getPanel().add(getTextFieldCacheSize(), gridBagConstraints);
117

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

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

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

    
143
        private JLabel getLabelWarning() {
144
                if (labelWarning == null) {
145
                        labelWarning = new JLabel();
146
                        labelWarning.setForeground(new Color(255, 0, 0));
147
                        labelWarning.setHorizontalAlignment(SwingConstants.CENTER);
148
                        labelWarning.setPreferredSize(new Dimension(0, 32));
149
                }
150
                return labelWarning;
151
        }
152

    
153
        private JFormattedTextField getTextFieldCacheSize() {
154
                if (textFieldCacheSize == null) {
155
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
156
                        integerFormat.setParseIntegerOnly(true);
157
                        textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory(
158
                                        new NumberFormatter(integerFormat),
159
                                        new NumberFormatter(integerFormat),
160
                                        new NumberFormatter(integerFormat)));
161
                }
162
                return textFieldCacheSize;
163
        }
164

    
165
        private JFormattedTextField getTextFieldPagsPerGroup() {
166
                if (textFieldPagsPerGroup == null) {
167
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
168
                        integerFormat.setParseIntegerOnly(true);
169
                        textFieldPagsPerGroup = new JFormattedTextField(new DefaultFormatterFactory(
170
                                        new NumberFormatter(integerFormat),
171
                                        new NumberFormatter(integerFormat),
172
                                        new NumberFormatter(integerFormat)));
173
                }
174
                return textFieldPagsPerGroup;
175
        }
176

    
177
        private JFormattedTextField getTextFieldPageSize() {
178
                if (textFieldPageSize == null) {
179
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
180
                        integerFormat.setParseIntegerOnly(true);
181
                        textFieldPageSize = new JFormattedTextField(new DefaultFormatterFactory(
182
                                        new NumberFormatter(integerFormat),
183
                                        new NumberFormatter(integerFormat),
184
                                        new NumberFormatter(integerFormat)));
185
                }
186
                return textFieldPageSize;
187
        }
188

    
189
        private JLabel getLabelCacheSize() {
190
                if (labelCacheSize == null) {
191
                        labelCacheSize = new JLabel();
192
                }
193
                return labelCacheSize;
194
        }
195

    
196
        private JLabel getLabelPagsPerGroup() {
197
                if (labelPagsPerGroup == null) {
198
                        labelPagsPerGroup = new JLabel();
199
                }
200
                return labelPagsPerGroup;
201
        }
202

    
203
        private JLabel getLabelPageSize() {
204
                if (labelPageSize == null) {
205
                        labelPageSize = new JLabel();
206
                }
207
                return labelPageSize;
208
        }
209

    
210
        private JLabel getLabelBlockHeight() {
211
                if (labelBlockHeight == null) {
212
                        labelBlockHeight = new JLabel();
213
                }
214
                return labelBlockHeight;
215
        }
216

    
217
        private JComboBox getComboBoxBlockHeight() {
218
                if (comboBoxBlockHeight == null) {
219
                        comboBoxBlockHeight = new JComboBox();
220
                        comboBoxBlockHeight.setModel(new DefaultComboBoxModel(new String[] { "128", "256", "512", "1024", "2048", "4096" }));
221
                }
222
                return comboBoxBlockHeight;
223
        }
224

    
225
        public void initializeDefaults() {
226
                getTextFieldCacheSize().setValue((Long) Configuration.getDefaultValue("cache_size"));
227
                getTextFieldPageSize().setValue((Double) Configuration.getDefaultValue("cache_pagesize"));
228
                getTextFieldPagsPerGroup().setValue((Integer) Configuration.getDefaultValue("cache_pagspergroup"));
229

    
230
                Integer blockHeight = (Integer) Configuration.getDefaultValue("cache_blockheight");
231
                for (int i = 0; i < getComboBoxBlockHeight().getItemCount(); i++) {
232
                        if (getComboBoxBlockHeight().getItemAt(i).toString().equals(blockHeight.toString())) {
233
                                getComboBoxBlockHeight().setSelectedIndex(i);
234
                                break;
235
                        }
236
                }
237
        }
238

    
239
        public void initializeValues() {
240
                getTextFieldCacheSize().setValue(Configuration.getValue("cache_size", Long.valueOf(RasterLibrary.cacheSize)));
241
                getTextFieldPageSize().setValue(Configuration.getValue("cache_pagesize", Double.valueOf(RasterLibrary.pageSize)));
242
                getTextFieldPagsPerGroup().setValue(Configuration.getValue("cache_pagspergroup", Integer.valueOf(RasterLibrary.pagsPerGroup)));
243

    
244
                Integer blockHeight = Configuration.getValue("cache_blockheight", Integer.valueOf(RasterLibrary.blockHeight));
245
                for (int i = 0; i < getComboBoxBlockHeight().getItemCount(); i++) {
246
                        if (getComboBoxBlockHeight().getItemAt(i).toString().equals(blockHeight.toString())) {
247
                                getComboBoxBlockHeight().setSelectedIndex(i);
248
                                break;
249
                        }
250
                }
251
        }
252

    
253
        public void storeValues() {
254
                Configuration.setValue("cache_size", getTextFieldCacheSize().getText());
255
                Configuration.setValue("cache_pagesize", Double.valueOf(getTextFieldPageSize().getText()));
256
                Configuration.setValue("cache_pagspergroup", getTextFieldPagsPerGroup().getText());
257
                Configuration.setValue("cache_blockheight", getComboBoxBlockHeight().getSelectedItem().toString());
258
        }
259
}