Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / EnhancedWithTrimPanel.java @ 10940

History | View | Annotate | Download (8.51 KB)

1 10740 nacho
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 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
20
package org.gvsig.rastertools.properties.panels;
21
22
import java.awt.BorderLayout;
23
import java.awt.GridBagConstraints;
24
import java.awt.GridBagLayout;
25
import java.awt.GridLayout;
26
import java.awt.Insets;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
30
import javax.swing.JCheckBox;
31
import javax.swing.JPanel;
32
import javax.swing.JRadioButton;
33
34
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
35
36
import com.iver.andami.PluginServices;
37
38
39
/**
40
 * Panel para los controles de brillo y contrase .
41
 *
42
 * @author Nacho Brodin (nachobrodin@gmail.com)
43
 */
44
public class EnhancedWithTrimPanel extends JPanel implements ActionListener{
45
        final private static long                         serialVersionUID = 0;
46
        public static final int                                LINEAR = 0;
47
        private TrimPanel trimPanel = null;
48
        private SelectorPanel selectorPanel = null;
49
        private JCheckBox        active = null;
50
51
        /**
52
         * Panel con los controles de eliminar extremos, recorte de colas y slider
53
         * con el porcentaje de recorte.
54
         *
55
         * @author Nacho Brodin (nachobrodin@gmail.com)
56
         *
57
         */
58
        class TrimPanel extends JPanel implements ActionListener{
59
                final private static long                 serialVersionUID = 0;
60
                private SliderTextContainer         trimSlider = null;
61
                private JCheckBox                                remove = null;
62
                private JCheckBox                                trimCheck = null;
63
                private JPanel                                        pCheck = null;
64
65
                /**
66
                 * Contructor
67
                 */
68
                public TrimPanel(){
69
                        trimSlider = new SliderTextContainer(0, 100, 50);
70
                        trimSlider.setDecimal(true);
71
                        trimSlider.setBorder("");
72
                        init();
73
                        getTrim().addActionListener(this);
74
                }
75
76
                private void init(){
77
                        setBorder(javax.swing.BorderFactory.createTitledBorder(null, null, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
78
                        this.setLayout(new BorderLayout());
79
                        this.add(getPCheck(), BorderLayout.NORTH );
80
                        this.add(trimSlider, BorderLayout.CENTER);
81
                }
82
83
                /**
84
                 * Obtiene el control con el slider de recorte de colas
85
                 * @return SliderTextContainer
86
                 */
87
                public SliderTextContainer getTrimSlider(){
88
                        if(trimSlider == null)
89
                                trimSlider = new SliderTextContainer(0, 100, 50);
90
                        return trimSlider;
91
                }
92
93
                public JPanel getPCheck(){
94
                        if(pCheck == null){
95
                                pCheck = new JPanel();
96
                                pCheck.setLayout(new GridBagLayout());
97
                                GridBagConstraints gbc = new GridBagConstraints();
98
                                gbc.insets = new Insets(9, 0, 0, 0);
99
                                gbc.anchor = GridBagConstraints.WEST;
100
                                gbc.gridx = 0;
101
                                gbc.gridy = 0;
102
                                gbc.weightx = 8;
103
104
                                GridBagConstraints gbc1 = new GridBagConstraints();
105
                                gbc1.insets = new Insets(9, 0, 9, 0);
106
                                gbc1.gridx = 0;
107
                                gbc1.gridy = 1;
108
                                gbc1.anchor = GridBagConstraints.WEST;
109
                                gbc1.weightx = 8;
110
111
                                pCheck.add(getRemove(), gbc);
112
                                pCheck.add(getTrim(), gbc1);
113
                        }
114
                        return pCheck;
115
                }
116
117
                /**
118
                 * Obtiene el check de eliminar extremos
119
                 * @return
120
                 */
121
                public JCheckBox getRemove(){
122
                        if(remove == null)
123
                                remove = new JCheckBox(PluginServices.getText(this, "eliminar_extremos"));
124
                        return remove;
125
                }
126
127
                /**
128
                 * Obtiene el check de recorte de colas
129
                 * @return
130
                 */
131
                public JCheckBox getTrim(){
132
                        if(trimCheck == null)
133
                                trimCheck = new JCheckBox(PluginServices.getText(this, "recorte_colas"));
134
                        return trimCheck;
135
                }
136
137
                /**
138
                 * Activa o desactiva el control
139
                 * @param enable true activa y false desactiva los controles del panel
140
                 */
141
                public void setControlEnabled(boolean enabled){
142
                        if(enabled && getTrim().isSelected())
143
                                trimSlider.setControlEnabled(true);
144
                        else
145
                                trimSlider.setControlEnabled(false);
146
                        remove.setEnabled(enabled);
147
                        trimCheck.setEnabled(enabled);
148
                }
149
150
                /**
151
                 * Maneja eventos de activar y desactivar el panel
152
                 */
153
                public void actionPerformed(ActionEvent e) {
154
                        if(e.getSource() == getTrim())
155
                                trimSlider.setControlEnabled(getTrim().isSelected());
156
157
                }
158
        }
159
160
        /**
161
         * Panel con los controles de selecci?n para el tipo de filtro
162
         * de realce.
163
         *
164
         * @author Nacho Brodin (nachobrodin@gmail.com)
165
         *
166
         */
167
        class SelectorPanel extends JPanel{
168
                final private static long         serialVersionUID = 0;
169
                private JRadioButton                  rb = null;
170
171
                /**
172
                 * Constructor
173
                 */
174
                public SelectorPanel(){
175
                        setLayout(new GridLayout(1, 1));
176
                        //setBorder(javax.swing.BorderFactory.createTitledBorder(null, null, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
177
                        add(getLineal());
178
                }
179
180
                /**
181
                 * Obtiene el radio button de selecci?n de filtro lineal
182
                 * @return JRadioButton
183
                 */
184
                private JRadioButton getLineal(){
185
                        if(rb == null){
186
                                rb = new JRadioButton(PluginServices.getText(this, "lineal_directo"));
187
                                rb.setSelected(true);
188
                        }
189
                        return rb;
190
                }
191
192
                /**
193
                 * Activa o desactiva el control
194
                 * @param enable true activa y false desactiva los controles del panel
195
                 */
196
                public void setControlEnabled(boolean enabled){
197
                        rb.setEnabled(enabled);
198
                }
199
200
        }
201
202
        /**
203
         * Contructor
204
         */
205
        public EnhancedWithTrimPanel(){
206
                super();
207
                trimPanel = new TrimPanel();
208
                selectorPanel = new SelectorPanel();
209
                initialize();
210
        }
211
212
        private void initialize() {
213
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "realce"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
214
                setLayout(new BorderLayout());
215
                add(getActive(), BorderLayout.NORTH);
216
                add(selectorPanel, BorderLayout.CENTER);
217
                add(trimPanel, BorderLayout.SOUTH);
218
                getActive().addActionListener(this);
219
        }
220
221
        /**
222
         * Obtiene el check de activar
223
         * @return
224
         */
225
        public JCheckBox getActive(){
226
                if(active == null){
227
                        active = new JCheckBox(PluginServices.getText(this, "activar"));
228
                        active.setSelected(false);
229
                        this.setControlEnabled(false);
230
                }
231
                return active;
232
        }
233
234
        /**
235
         * Activa o desactiva el control
236
         * @param enable true activa y false desactiva los controles del panel
237
         */
238
        public void setControlEnabled(boolean enabled){
239
                getActive().setSelected(enabled);
240
                trimPanel.setControlEnabled(enabled);
241
                selectorPanel.setControlEnabled(enabled);
242
        }
243
244
        /**
245
         * Maneja eventos de activar y desactivar el panel
246
         */
247
        public void actionPerformed(ActionEvent e) {
248
                if(e.getSource() == getActive()){
249
                        if(getActive().isSelected())
250
                                setControlEnabled(true);
251
                        else
252
                                setControlEnabled(false);
253
                }
254
        }
255
256
        /**
257
         * Obtiene el valor de selecci?n del check de eliminar extremos
258
         * @return boolean, true si est? seleccionado y false si no lo est?.
259
         */
260
        public boolean isRemoveEndsSelected(){
261
                return trimPanel.getRemove().isSelected();
262
        }
263
264
        /**
265
         * Obtiene el valor de selecci?n del check de recorte de colas.
266
         * @return boolean, true si est? seleccionado y false si no lo est?.
267
         */
268
        public boolean isTailTrimCheckSelected(){
269
                return trimPanel.getTrim().isSelected();
270
        }
271
272
        /**
273
         * Obtiene el valor de recorte de colas seleccionado en el slider
274
         * @return double
275
         */
276
        public double getTrimValue(){
277
                return trimPanel.getTrimSlider().getValue();
278
        }
279
280
        /**
281
         * Activa o desactiva el checkbox de recorte de colas
282
         * @param active true si deseamos activarlo y false para desactivarlo
283
         */
284
        public void setTailTrimCheckActive(boolean active){
285
                trimPanel.getTrim().setSelected(active);
286
        }
287
288
        /**
289
         * Activa o desactiva el checkbox de eliminar extremos
290
         * @param active true si deseamos activarlo y false para desactivarlo
291
         */
292
        public void setRemoveEndsActive(boolean active){
293
                trimPanel.getRemove().setSelected(active);
294
        }
295
296
        /**
297
         * Asigna un valor al slider de porcentaje de recorte
298
         * @param active true si deseamos activarlo y false para desactivarlo
299
         */
300
        public void setTailTrimValue(double value){
301
                trimPanel.getTrimSlider().setValue(value);
302
        }
303
304
        /**
305
         * Selecciona un metodo de realce entre los disponibles (linear)
306
         * @param method
307
         */
308
        public void setEnhancedMethod(int method){
309
                switch(method){
310
                case LINEAR: break;
311
                }
312
        }
313
}