Statistics
| Revision:

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

History | View | Annotate | Download (9.72 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.fmap.raster.util.Configuration;
38
import org.gvsig.raster.RasterLibrary;
39
import org.gvsig.raster.util.PanelBase;
40

    
41
public class PreferenceCache extends PanelBase {
42
        JLabel              labelWarning          = null;
43
        JLabel              labelBlockHeight      = null;
44
        JComboBox           comboBoxBlockHeight   = null;
45
        JLabel              labelCacheSize        = null;
46
        JFormattedTextField textFieldCacheSize    = null;
47
        JLabel              labelPagsPerGroup     = null;
48
        JFormattedTextField textFieldPagsPerGroup = null;
49
        JLabel              labelPageSize         = null;
50
        JFormattedTextField textFieldPageSize     = null;
51

    
52
        public PreferenceCache() {
53
                initialize();
54
                translate();
55
        }
56

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

    
66
        private void initialize() {
67
                GridBagConstraints gridBagConstraints;
68

    
69
                getPanel().setLayout(new GridBagLayout());
70

    
71
                gridBagConstraints = new GridBagConstraints();
72
                gridBagConstraints.gridwidth = 2;
73
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
74
                gridBagConstraints.weightx = 1.0;
75
                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
76
                getPanel().add(getLabelWarning(), gridBagConstraints);
77

    
78
                gridBagConstraints = new GridBagConstraints();
79
                gridBagConstraints.gridx = 0;
80
                gridBagConstraints.gridy = 1;
81
                gridBagConstraints.anchor = GridBagConstraints.EAST;
82
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
83
                getPanel().add(getLabelCacheSize(), gridBagConstraints);
84

    
85
                gridBagConstraints = new GridBagConstraints();
86
                gridBagConstraints.gridx = 0;
87
                gridBagConstraints.gridy = 2;
88
                gridBagConstraints.anchor = GridBagConstraints.EAST;
89
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
90
                getPanel().add(getLabelPagsPerGroup(), gridBagConstraints);
91

    
92
                gridBagConstraints = new GridBagConstraints();
93
                gridBagConstraints.gridx = 0;
94
                gridBagConstraints.gridy = 3;
95
                gridBagConstraints.anchor = GridBagConstraints.EAST;
96
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
97
                getPanel().add(getLabelPageSize(), gridBagConstraints);
98

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

    
106
                gridBagConstraints = new GridBagConstraints();
107
                gridBagConstraints.gridx = 1;
108
                gridBagConstraints.gridy = 1;
109
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
110
                gridBagConstraints.anchor = GridBagConstraints.WEST;
111
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
112
                getPanel().add(getTextFieldCacheSize(), gridBagConstraints);
113

    
114
                gridBagConstraints = new GridBagConstraints();
115
                gridBagConstraints.gridx = 1;
116
                gridBagConstraints.gridy = 4;
117
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
118
                gridBagConstraints.anchor = GridBagConstraints.WEST;
119
                gridBagConstraints.insets = new Insets(2, 2, 5, 5);
120
                getPanel().add(getComboBoxBlockHeight(), gridBagConstraints);
121

    
122
                gridBagConstraints = new GridBagConstraints();
123
                gridBagConstraints.gridx = 1;
124
                gridBagConstraints.gridy = 3;
125
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
126
                gridBagConstraints.anchor = GridBagConstraints.WEST;
127
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
128
                getPanel().add(getTextFieldPageSize(), gridBagConstraints);
129

    
130
                gridBagConstraints = new GridBagConstraints();
131
                gridBagConstraints.gridx = 1;
132
                gridBagConstraints.gridy = 2;
133
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
134
                gridBagConstraints.anchor = GridBagConstraints.WEST;
135
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
136
                getPanel().add(getTextFieldPagsPerGroup(), gridBagConstraints);
137
        }
138

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

    
149
        private JFormattedTextField getTextFieldCacheSize() {
150
                if (textFieldCacheSize == null) {
151
                        NumberFormat integerFormat = NumberFormat.getNumberInstance();
152
                        integerFormat.setParseIntegerOnly(true);
153
                        textFieldCacheSize = new JFormattedTextField(new DefaultFormatterFactory(
154
                                        new NumberFormatter(integerFormat),
155
                                        new NumberFormatter(integerFormat),
156
                                        new NumberFormatter(integerFormat)));
157
                }
158
                return textFieldCacheSize;
159
        }
160

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

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

    
185
        private JLabel getLabelCacheSize() {
186
                if (labelCacheSize == null) {
187
                        labelCacheSize = new JLabel();
188
                }
189
                return labelCacheSize;
190
        }
191

    
192
        private JLabel getLabelPagsPerGroup() {
193
                if (labelPagsPerGroup == null) {
194
                        labelPagsPerGroup = new JLabel();
195
                }
196
                return labelPagsPerGroup;
197
        }
198

    
199
        private JLabel getLabelPageSize() {
200
                if (labelPageSize == null) {
201
                        labelPageSize = new JLabel();
202
                }
203
                return labelPageSize;
204
        }
205

    
206
        private JLabel getLabelBlockHeight() {
207
                if (labelBlockHeight == null) {
208
                        labelBlockHeight = new JLabel();
209
                }
210
                return labelBlockHeight;
211
        }
212

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

    
221
        public void initializeDefaults() {
222
                getTextFieldCacheSize().setValue((Long) Configuration.getDefaultValue("cache_size"));
223
                getTextFieldPageSize().setValue((Double) Configuration.getDefaultValue("cache_pagesize"));
224
                getTextFieldPagsPerGroup().setValue((Integer) Configuration.getDefaultValue("cache_pagspergroup"));
225

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

    
235
        public void initializeValues() {
236
                getTextFieldCacheSize().setValue(Configuration.getValue("cache_size", Long.valueOf(RasterLibrary.cacheSize)));
237
                getTextFieldPageSize().setValue(Configuration.getValue("cache_pagesize", Double.valueOf(RasterLibrary.pageSize)));
238
                getTextFieldPagsPerGroup().setValue(Configuration.getValue("cache_pagspergroup", Integer.valueOf(RasterLibrary.pagsPerGroup)));
239

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

    
249
        public void storeValues() {
250
                Configuration.setValue("cache_size", getTextFieldCacheSize().getText());
251
                Configuration.setValue("cache_pagesize", getTextFieldPageSize().getText());
252
                Configuration.setValue("cache_pagspergroup", getTextFieldPagsPerGroup().getText());
253
                Configuration.setValue("cache_blockheight", getComboBoxBlockHeight().getSelectedItem().toString());
254
        }
255
}