Statistics
| Revision:

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

History | View | Annotate | Download (8.46 KB)

1
/* 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
package org.gvsig.rastertools.properties.panels;
20

    
21
import java.awt.BorderLayout;
22
import java.awt.GridBagConstraints;
23
import java.awt.GridBagLayout;
24
import java.awt.GridLayout;
25
import java.awt.Insets;
26
import java.awt.event.ActionEvent;
27
import java.awt.event.ActionListener;
28

    
29
import javax.swing.JCheckBox;
30
import javax.swing.JPanel;
31
import javax.swing.JRadioButton;
32

    
33
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
34

    
35
import com.iver.andami.PluginServices;
36
/**
37
 * Panel para los controles de brillo y contraste.
38
 * 
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class EnhancedWithTrimPanel extends JPanel implements ActionListener {
42
        private static final long serialVersionUID = 9023137365069951866L;
43
        public static final int   LINEAR           = 0;
44
        private TrimPanel         trimPanel        = null;
45
        private SelectorPanel     selectorPanel    = null;
46
        private JCheckBox         active           = null;
47

    
48
        /**
49
         * Panel con los controles de eliminar extremos, recorte de colas y slider
50
         * con el porcentaje de recorte.
51
         * 
52
         * @author Nacho Brodin (nachobrodin@gmail.com)
53
         */
54
        class TrimPanel extends JPanel implements ActionListener {
55
                private static final long   serialVersionUID = -6435560458161006843L;
56
                private SliderTextContainer trimSlider       = null;
57
                private JCheckBox           remove           = null;
58
                private JCheckBox           trimCheck        = null;
59
                private JPanel              pCheck           = null;
60

    
61
                /**
62
                 * Contructor
63
                 */
64
                public TrimPanel() {
65
                        trimSlider = new SliderTextContainer(0, 100, 50);
66
                        trimSlider.setDecimal(true);
67
                        trimSlider.setBorder("");
68
                        init();
69
                        getTrim().addActionListener(this);
70
                }
71

    
72
                private void init() {
73
                        setBorder(javax.swing.BorderFactory.createTitledBorder(null, null, javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
74
                        this.setLayout(new BorderLayout());
75
                        this.add(getPCheck(), BorderLayout.NORTH);
76
                        this.add(trimSlider, BorderLayout.CENTER);
77
                }
78

    
79
                /**
80
                 * Obtiene el control con el slider de recorte de colas
81
                 * @return SliderTextContainer
82
                 */
83
                public SliderTextContainer getTrimSlider() {
84
                        if (trimSlider == null)
85
                                trimSlider = new SliderTextContainer(0, 100, 50);
86
                        return trimSlider;
87
                }
88

    
89
                public JPanel getPCheck() {
90
                        if (pCheck == null) {
91
                                pCheck = new JPanel();
92
                                pCheck.setLayout(new GridBagLayout());
93
                                GridBagConstraints gbc = new GridBagConstraints();
94
                                gbc.insets = new Insets(9, 0, 0, 0);
95
                                gbc.anchor = GridBagConstraints.WEST;
96
                                gbc.gridx = 0;
97
                                gbc.gridy = 0;
98
                                gbc.weightx = 8;
99

    
100
                                GridBagConstraints gbc1 = new GridBagConstraints();
101
                                gbc1.insets = new Insets(9, 0, 9, 0);
102
                                gbc1.gridx = 0;
103
                                gbc1.gridy = 1;
104
                                gbc1.anchor = GridBagConstraints.WEST;
105
                                gbc1.weightx = 8;
106

    
107
                                pCheck.add(getRemove(), gbc);
108
                                pCheck.add(getTrim(), gbc1);
109
                        }
110
                        return pCheck;
111
                }
112

    
113
                /**
114
                 * Obtiene el check de eliminar extremos
115
                 * @return
116
                 */
117
                public JCheckBox getRemove() {
118
                        if (remove == null)
119
                                remove = new JCheckBox(PluginServices.getText(this, "eliminar_extremos"));
120
                        return remove;
121
                }
122

    
123
                /**
124
                 * Obtiene el check de recorte de colas
125
                 * @return
126
                 */
127
                public JCheckBox getTrim() {
128
                        if (trimCheck == null)
129
                                trimCheck = new JCheckBox(PluginServices.getText(this, "recorte_colas"));
130
                        return trimCheck;
131
                }
132

    
133
                /**
134
                 * Activa o desactiva el control
135
                 * @param enable true activa y false desactiva los controles del panel
136
                 */
137
                public void setControlEnabled(boolean enabled) {
138
                        if (enabled && getTrim().isSelected())
139
                                trimSlider.setControlEnabled(true);
140
                        else
141
                                trimSlider.setControlEnabled(false);
142
                        remove.setEnabled(enabled);
143
                        trimCheck.setEnabled(enabled);
144
                }
145

    
146
                /**
147
                 * Maneja eventos de activar y desactivar el panel
148
                 */
149
                public void actionPerformed(ActionEvent e) {
150
                        if (e.getSource() == getTrim())
151
                                trimSlider.setControlEnabled(getTrim().isSelected());
152
                }
153
        }
154

    
155
        /**
156
         * Panel con los controles de selecci?n para el tipo de filtro
157
         * de realce.
158
         * 
159
         * @author Nacho Brodin (nachobrodin@gmail.com)
160
         */
161
        class SelectorPanel extends JPanel {
162
                private static final long serialVersionUID = 9036702518290091787L;
163
                private JRadioButton rb = null;
164

    
165
                /**
166
                 * Constructor
167
                 */
168
                public SelectorPanel() {
169
                        setLayout(new GridLayout(1, 1));
170
                        add(getLineal());
171
                }
172

    
173
                /**
174
                 * Obtiene el radio button de selecci?n de filtro lineal
175
                 * @return JRadioButton
176
                 */
177
                private JRadioButton getLineal() {
178
                        if (rb == null) {
179
                                rb = new JRadioButton(PluginServices.getText(this, "lineal_directo"));
180
                                rb.setSelected(true);
181
                        }
182
                        return rb;
183
                }
184

    
185
                /**
186
                 * Activa o desactiva el control
187
                 * @param enable true activa y false desactiva los controles del panel
188
                 */
189
                public void setControlEnabled(boolean enabled) {
190
                        rb.setEnabled(enabled);
191
                }
192
        }
193

    
194
        /**
195
         * Contructor
196
         */
197
        public EnhancedWithTrimPanel() {
198
                super();
199
                trimPanel = new TrimPanel();
200
                selectorPanel = new SelectorPanel();
201
                initialize();
202
        }
203

    
204
        private void initialize() {
205
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "realce"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
206
                setLayout(new BorderLayout());
207
                add(getActive(), BorderLayout.NORTH);
208
                add(selectorPanel, BorderLayout.CENTER);
209
                add(trimPanel, BorderLayout.SOUTH);
210
                getActive().addActionListener(this);
211
        }
212

    
213
        /**
214
         * Obtiene el check de activar
215
         * @return
216
         */
217
        public JCheckBox getActive() {
218
                if (active == null) {
219
                        active = new JCheckBox(PluginServices.getText(this, "activar"));
220
                        active.setSelected(false);
221
                        this.setControlEnabled(false);
222
                }
223
                return active;
224
        }
225

    
226
        /**
227
         * Activa o desactiva el control
228
         * @param enable true activa y false desactiva los controles del panel
229
         */
230
        public void setControlEnabled(boolean enabled) {
231
                getActive().setSelected(enabled);
232
                trimPanel.setControlEnabled(enabled);
233
                selectorPanel.setControlEnabled(enabled);
234
        }
235

    
236
        /**
237
         * Maneja eventos de activar y desactivar el panel
238
         */
239
        public void actionPerformed(ActionEvent e) {
240
                if (e.getSource() == getActive()) {
241
                        if (getActive().isSelected())
242
                                setControlEnabled(true);
243
                        else
244
                                setControlEnabled(false);
245
                }
246
        }
247

    
248
        /**
249
         * Obtiene el valor de selecci?n del check de eliminar extremos
250
         * @return boolean, true si est? seleccionado y false si no lo est?. 
251
         */
252
        public boolean isRemoveEndsSelected() {
253
                return trimPanel.getRemove().isSelected();
254
        }
255

    
256
        /**
257
         * Obtiene el valor de selecci?n del check de recorte de colas.
258
         * @return boolean, true si est? seleccionado y false si no lo est?.
259
         */
260
        public boolean isTailTrimCheckSelected() {
261
                return trimPanel.getTrim().isSelected();
262
        }
263

    
264
        /**
265
         * Obtiene el valor de recorte de colas seleccionado en el slider
266
         * @return double
267
         */
268
        public double getTrimValue() {
269
                return trimPanel.getTrimSlider().getValue();
270
        }
271

    
272
        /**
273
         * Activa o desactiva el checkbox de recorte de colas
274
         * @param active true si deseamos activarlo y false para desactivarlo
275
         */
276
        public void setTailTrimCheckActive(boolean active) {
277
                trimPanel.getTrim().setSelected(active);
278
        }
279

    
280
        /**
281
         * Activa o desactiva el checkbox de eliminar extremos
282
         * @param active true si deseamos activarlo y false para desactivarlo
283
         */
284
        public void setRemoveEndsActive(boolean active) {
285
                trimPanel.getRemove().setSelected(active);
286
        }
287

    
288
        /**
289
         * Asigna un valor al slider de porcentaje de recorte
290
         * @param active true si deseamos activarlo y false para desactivarlo
291
         */
292
        public void setTailTrimValue(double value) {
293
                trimPanel.getTrimSlider().setValue(value);
294
        }
295

    
296
        /**
297
         * Selecciona un metodo de realce entre los disponibles (linear)
298
         * @param method
299
         */
300
        public void setEnhancedMethod(int method) {
301
                switch (method) {
302
                        case LINEAR:
303
                                break;
304
                }
305
        }
306
}