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 17271 bsanchez
/* 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 17330 bsanchez
import org.gvsig.addo.Jaddo;
31 18014 bsanchez
import org.gvsig.raster.Configuration;
32 22364 nbrodin
import org.gvsig.raster.util.BasePanel;
33 17511 bsanchez
/**
34 20274 bsanchez
 * PreferenceOverviews es una clase para la configuracion de las overviews de
35
 * Raster en gvSIG
36
 *
37 17511 bsanchez
 * @version 14/12/2007
38
 * @author BorSanZa - Borja S?nchez Zamorano (borja.sanchez@iver.es)
39
 */
40 22364 nbrodin
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 17271 bsanchez
50 22364 nbrodin
        /**
51
         *Inicializa componentes gr?ficos y traduce
52
         */
53 17271 bsanchez
        public PreferenceOverviews() {
54 22364 nbrodin
                init();
55 17330 bsanchez
                translate();
56 17271 bsanchez
        }
57 22364 nbrodin
58
        /*
59
         * (non-Javadoc)
60
         * @see org.gvsig.raster.util.BasePanel#translate()
61 20274 bsanchez
         */
62 22364 nbrodin
        protected void translate() {
63
                setBorder(BorderFactory.createTitledBorder(getText(this, "overviews")));
64 17330 bsanchez
                getLabelNumber().setText(getText(this, "num_overviews") + ":");
65
                getLabelRate().setText(getText(this, "proporcion_overviews") + ":");
66
                getLabelAlgorithm().setText(getText(this, "algorithm") + ":");
67 20840 bsanchez
//                getCheckBoxAsk().setText(getText(this, "generacion_overviews"));
68
//                getCheckBoxAsk().setToolTipText(getCheckBoxAsk().getText());
69 22364 nbrodin
70 17330 bsanchez
        }
71
72 22364 nbrodin
        /*
73
         * (non-Javadoc)
74
         * @see org.gvsig.raster.util.BasePanel#init()
75
         */
76
        protected void init() {
77 17271 bsanchez
                GridBagConstraints gridBagConstraints;
78
79 22364 nbrodin
                setLayout(new GridBagLayout());
80 17271 bsanchez
81 20840 bsanchez
                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 22364 nbrodin
//                add(getCheckBoxAsk(), gridBagConstraints);
91 17271 bsanchez
92 20840 bsanchez
//                posy++;
93 17271 bsanchez
                gridBagConstraints = new GridBagConstraints();
94
                gridBagConstraints.gridx = 0;
95 20840 bsanchez
                gridBagConstraints.gridy = posy;
96 17271 bsanchez
                gridBagConstraints.anchor = GridBagConstraints.EAST;
97
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
98 22364 nbrodin
                add(getLabelNumber(), gridBagConstraints);
99 17271 bsanchez
100
                gridBagConstraints = new GridBagConstraints();
101
                gridBagConstraints.gridx = 1;
102 20840 bsanchez
                gridBagConstraints.gridy = posy;
103 17271 bsanchez
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
104
                gridBagConstraints.anchor = GridBagConstraints.WEST;
105
                gridBagConstraints.weightx = 1.0;
106
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
107 22364 nbrodin
                add(getComboNumber(), gridBagConstraints);
108 17271 bsanchez
109 20840 bsanchez
                posy++;
110 17271 bsanchez
                gridBagConstraints = new GridBagConstraints();
111
                gridBagConstraints.gridx = 0;
112 20840 bsanchez
                gridBagConstraints.gridy = posy;
113 17271 bsanchez
                gridBagConstraints.anchor = GridBagConstraints.EAST;
114
                gridBagConstraints.insets = new Insets(2, 5, 2, 2);
115 22364 nbrodin
                add(getLabelRate(), gridBagConstraints);
116 17271 bsanchez
117
                gridBagConstraints = new GridBagConstraints();
118
                gridBagConstraints.gridx = 1;
119 20840 bsanchez
                gridBagConstraints.gridy = posy;
120 17271 bsanchez
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
121
                gridBagConstraints.anchor = GridBagConstraints.WEST;
122
                gridBagConstraints.insets = new Insets(2, 2, 2, 5);
123 22364 nbrodin
                add(getComboRate(), gridBagConstraints);
124 17271 bsanchez
125 20840 bsanchez
                posy++;
126 17271 bsanchez
                gridBagConstraints = new GridBagConstraints();
127
                gridBagConstraints.gridx = 0;
128 20840 bsanchez
                gridBagConstraints.gridy = posy;
129 17271 bsanchez
                gridBagConstraints.anchor = GridBagConstraints.EAST;
130
                gridBagConstraints.insets = new Insets(2, 5, 5, 2);
131 22364 nbrodin
                add(getLabelAlgorithm(), gridBagConstraints);
132 17271 bsanchez
133
                gridBagConstraints = new GridBagConstraints();
134
                gridBagConstraints.gridx = 1;
135 20840 bsanchez
                gridBagConstraints.gridy = posy;
136 17271 bsanchez
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
137
                gridBagConstraints.anchor = GridBagConstraints.WEST;
138
                gridBagConstraints.insets = new Insets(2, 2, 5, 5);
139 22364 nbrodin
                add(getComboAlgorithm(), gridBagConstraints);
140 17330 bsanchez
        }
141 17271 bsanchez
142 17330 bsanchez
        private JLabel getLabelAlgorithm() {
143
                if (labelAlgorithm == null)
144
                        labelAlgorithm = new JLabel();
145
                return labelAlgorithm;
146 17271 bsanchez
        }
147
148 17330 bsanchez
        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 20840 bsanchez
//        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 17271 bsanchez
169 17330 bsanchez
        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 22364 nbrodin
                if (comboBoxAlgorithm == null) {
187 17330 bsanchez
                        comboBoxAlgorithm = new JComboBox();
188 22364 nbrodin
                        comboBoxAlgorithm.setModel(new DefaultComboBoxModel(new String[] { getText(this, "vecino_cercano"), getText(this, "media"), getText(this, "media_phase") }));
189
                }
190 17330 bsanchez
                return comboBoxAlgorithm;
191
        }
192
193 20274 bsanchez
        /**
194
         * Carga los valores por defecto del componente
195
         */
196 17330 bsanchez
        public void initializeDefaults() {
197 17491 bsanchez
                int pos = 0;
198 20840 bsanchez
//                getCheckBoxAsk().setSelected(((Boolean) Configuration.getDefaultValue("overviews_ask_before_loading")).booleanValue());
199 17491 bsanchez
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 17330 bsanchez
        }
222
223 20274 bsanchez
        /**
224
         * Carga los valores definidos previamente por el usuario
225
         */
226 17271 bsanchez
        public void initializeValues() {
227 17330 bsanchez
                int pos = 0;
228 20840 bsanchez
//                getCheckBoxAsk().setSelected(Configuration.getValue("overviews_ask_before_loading", Boolean.FALSE).booleanValue());
229 17330 bsanchez
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 17271 bsanchez
        }
252
253 20274 bsanchez
        /**
254
         * Guarda los valores definidos por el usuario
255
         */
256 17271 bsanchez
        public void storeValues() {
257 20840 bsanchez
//                Configuration.setValue("overviews_ask_before_loading", Boolean.valueOf(getCheckBoxAsk().isSelected()));
258 17330 bsanchez
                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 17271 bsanchez
263 17330 bsanchez
                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 17271 bsanchez
        }
274 22364 nbrodin
275 17330 bsanchez
}