Statistics
| Revision:

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

History | View | Annotate | Download (9.08 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.GridBagConstraints;
22
import java.awt.GridBagLayout;
23
import java.awt.Insets;
24

    
25
import javax.swing.BorderFactory;
26
import javax.swing.DefaultComboBoxModel;
27
import javax.swing.JComboBox;
28
import javax.swing.JLabel;
29

    
30
import org.gvsig.addo.Jaddo;
31
import org.gvsig.raster.Configuration;
32
import org.gvsig.raster.util.BasePanel;
33
/**
34
 * PreferenceOverviews es una clase para la configuracion de las overviews de
35
 * Raster en gvSIG
36
 * 
37
 * @version 14/12/2007
38
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
39
 */
40
public class PreferenceOverviews extends BasePanel {
41
        private static final long  serialVersionUID  = 1L;
42
        //        private JCheckBox jCheckBoxAsk           = null;
43
        private JComboBox          comboBoxRate      = null;
44
        private JComboBox          comboBoxNumber    = null;
45
        private JComboBox          comboBoxAlgorithm = null;
46
        private JLabel             labelNumber       = null;
47
        private JLabel             labelRate         = null;
48
        private JLabel             labelAlgorithm    = null;
49

    
50
        /**
51
         *Inicializa componentes gr?ficos y traduce
52
         */
53
        public PreferenceOverviews() {
54
                init();
55
                translate();
56
        }
57
        
58
        /*
59
         * (non-Javadoc)
60
         * @see org.gvsig.raster.util.BasePanel#translate()
61
         */
62
        protected void translate() {
63
                setBorder(BorderFactory.createTitledBorder(getText(this, "overviews")));
64
                getLabelNumber().setText(getText(this, "num_overviews") + ":");
65
                getLabelRate().setText(getText(this, "proporcion_overviews") + ":");
66
                getLabelAlgorithm().setText(getText(this, "algorithm") + ":");
67
//                getCheckBoxAsk().setText(getText(this, "generacion_overviews"));
68
//                getCheckBoxAsk().setToolTipText(getCheckBoxAsk().getText());
69
                
70
        }
71

    
72
        /*
73
         * (non-Javadoc)
74
         * @see org.gvsig.raster.util.BasePanel#init()
75
         */
76
        protected void init() {
77
                GridBagConstraints gridBagConstraints;
78

    
79
                setLayout(new GridBagLayout());
80

    
81
                int posy = 0;
82
                
83
//                gridBagConstraints = new GridBagConstraints();
84
//                gridBagConstraints.gridx = 0;
85
//                gridBagConstraints.gridy = posy;
86
//                gridBagConstraints.gridwidth = 2;
87
//                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
88
//                gridBagConstraints.weightx = 1.0;
89
//                gridBagConstraints.insets = new Insets(5, 5, 2, 5);
90
//                add(getCheckBoxAsk(), gridBagConstraints);
91

    
92
//                posy++;
93
                gridBagConstraints = new GridBagConstraints();
94
                gridBagConstraints.gridx = 0;
95
                gridBagConstraints.gridy = posy;
96
                gridBagConstraints.anchor = GridBagConstraints.EAST;
97
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
98
                add(getLabelNumber(), gridBagConstraints);
99

    
100
                gridBagConstraints = new GridBagConstraints();
101
                gridBagConstraints.gridx = 1;
102
                gridBagConstraints.gridy = posy;
103
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
104
                gridBagConstraints.anchor = GridBagConstraints.WEST;
105
                gridBagConstraints.weightx = 1.0;
106
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
107
                add(getComboNumber(), gridBagConstraints);
108

    
109
                posy++;
110
                gridBagConstraints = new GridBagConstraints();
111
                gridBagConstraints.gridx = 0;
112
                gridBagConstraints.gridy = posy;
113
                gridBagConstraints.anchor = GridBagConstraints.EAST;
114
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
115
                add(getLabelRate(), gridBagConstraints);
116

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

    
125
                posy++;
126
                gridBagConstraints = new GridBagConstraints();
127
                gridBagConstraints.gridx = 0;
128
                gridBagConstraints.gridy = posy;
129
                gridBagConstraints.anchor = GridBagConstraints.EAST;
130
                gridBagConstraints.insets = new Insets(2, 5, 5, 2);
131
                add(getLabelAlgorithm(), gridBagConstraints);
132

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

    
142
        private JLabel getLabelAlgorithm() {
143
                if (labelAlgorithm == null)
144
                        labelAlgorithm = new JLabel();
145
                return labelAlgorithm;
146
        }
147

    
148
        private JLabel getLabelRate() {
149
                if (labelRate == null)
150
                        labelRate = new JLabel();
151
                return labelRate;
152
        }
153

    
154
        private JLabel getLabelNumber() {
155
                if (labelNumber == null)
156
                        labelNumber = new JLabel();
157
                return labelNumber;
158
        }
159

    
160
//        private JCheckBox getCheckBoxAsk() {
161
//                if (jCheckBoxAsk == null) {
162
//                        jCheckBoxAsk = new JCheckBox();
163
//                        jCheckBoxAsk.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
164
//                        jCheckBoxAsk.setMargin(new Insets(0, 0, 0, 0));
165
//                }
166
//                return jCheckBoxAsk;
167
//        }
168

    
169
        private JComboBox getComboRate() {
170
                if (comboBoxRate == null) {
171
                        comboBoxRate = new JComboBox();
172
                        comboBoxRate.setModel(new DefaultComboBoxModel(new String[] { "/2", "/3" }));
173
                }
174
                return comboBoxRate;
175
        }
176

    
177
        private JComboBox getComboNumber() {
178
                if (comboBoxNumber == null) {
179
                        comboBoxNumber = new JComboBox();
180
                        comboBoxNumber.setModel(new DefaultComboBoxModel(new String[] { "2", "3", "4" }));
181
                }
182
                return comboBoxNumber;
183
        }
184

    
185
        private JComboBox getComboAlgorithm() {
186
                if (comboBoxAlgorithm == null) {
187
                        comboBoxAlgorithm = new JComboBox();
188
                        comboBoxAlgorithm.setModel(new DefaultComboBoxModel(new String[] { getText(this, "vecino_cercano"), getText(this, "media"), getText(this, "media_phase") }));
189
                }
190
                return comboBoxAlgorithm;
191
        }
192

    
193
        /**
194
         * Carga los valores por defecto del componente
195
         */
196
        public void initializeDefaults() {
197
                int pos = 0;
198
//                getCheckBoxAsk().setSelected(((Boolean) Configuration.getDefaultValue("overviews_ask_before_loading")).booleanValue());
199

    
200
                pos = ((Integer) Configuration.getDefaultValue("overviews_number")).intValue() - 2;
201
                if ((pos < 0) || (pos >= getComboNumber().getItemCount()))
202
                        pos = 2;
203
                getComboNumber().setSelectedIndex(pos);
204

    
205
                pos = ((Integer) Configuration.getDefaultValue("overviews_rate")).intValue() - 2;
206
                if ((pos < 0) || (pos >= getComboRate().getItemCount()))
207
                        pos = 0;
208
                getComboRate().setSelectedIndex(pos);
209

    
210
                pos = ((Integer) Configuration.getDefaultValue("overviews_resampling_algorithm")).intValue();
211
                int type = 1;
212
                switch (pos) {
213
                        case Jaddo.NEAREST:
214
                                type = 0;
215
                                break;
216
                        case Jaddo.AVERAGE_MAGPHASE:
217
                                type = 2;
218
                                break;
219
                }
220
                getComboAlgorithm().setSelectedIndex(type);
221
        }
222

    
223
        /**
224
         * Carga los valores definidos previamente por el usuario 
225
         */
226
        public void initializeValues() {
227
                int pos = 0;
228
//                getCheckBoxAsk().setSelected(Configuration.getValue("overviews_ask_before_loading", Boolean.FALSE).booleanValue());
229

    
230
                pos = Configuration.getValue("overviews_number", Integer.valueOf(4)).intValue() - 2;
231
                if ((pos < 0) || (pos >= getComboNumber().getItemCount()))
232
                        pos = 2;
233
                getComboNumber().setSelectedIndex(pos);
234

    
235
                pos = Configuration.getValue("overviews_rate", Integer.valueOf(2)).intValue() - 2;
236
                if ((pos < 0) || (pos >= getComboRate().getItemCount()))
237
                        pos = 0;
238
                getComboRate().setSelectedIndex(pos);
239

    
240
                pos = Configuration.getValue("overviews_resampling_algorithm", Integer.valueOf(Jaddo.AVERAGE)).intValue();
241
                int type = 1;
242
                switch (pos) {
243
                        case Jaddo.NEAREST:
244
                                type = 0;
245
                                break;
246
                        case Jaddo.AVERAGE_MAGPHASE:
247
                                type = 2;
248
                                break;
249
                }
250
                getComboAlgorithm().setSelectedIndex(type);
251
        }
252

    
253
        /**
254
         * Guarda los valores definidos por el usuario
255
         */
256
        public void storeValues() {
257
//                Configuration.setValue("overviews_ask_before_loading", Boolean.valueOf(getCheckBoxAsk().isSelected()));
258
                if (getComboRate().getSelectedIndex() > -1)
259
                        Configuration.setValue("overviews_rate", Integer.valueOf(getComboRate().getSelectedIndex() + 2));
260
                if (getComboNumber().getSelectedIndex() > -1)
261
                        Configuration.setValue("overviews_number", Integer.valueOf(getComboNumber().getSelectedIndex() + 2));
262

    
263
                int type = Jaddo.AVERAGE;
264
                switch (getComboAlgorithm().getSelectedIndex()) {
265
                        case 0:
266
                                type = Jaddo.NEAREST;
267
                                break;
268
                        case 2:
269
                                type = Jaddo.AVERAGE_MAGPHASE;
270
                                break;
271
                }
272
                Configuration.setValue("overviews_resampling_algorithm", Integer.valueOf(type));
273
        }
274

    
275
}