Statistics
| Revision:

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

History | View | Annotate | Download (6.27 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.GridLayout;
23
import java.awt.event.ActionEvent;
24
import java.awt.event.ActionListener;
25
import java.awt.event.KeyListener;
26
import java.awt.event.MouseListener;
27

    
28
import javax.swing.JCheckBox;
29
import javax.swing.JPanel;
30
import javax.swing.event.ChangeListener;
31

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

    
34
import com.iver.andami.PluginServices;
35
/**
36
 * Panel para los controles de brillo y contrase .
37
 * 
38
 * @author Nacho Brodin (nachobrodin@gmail.com)
39
 */
40
public class EnhancedBrightnessContrastPanel extends JPanel implements ActionListener{
41
        final private static long         serialVersionUID = 0;
42
        private InternalPanel                 internalPanel = null;
43
        private JCheckBox                        active = null;
44
        private JCheckBox                        preview = null;
45

    
46
        /**
47
         * Panel con los controles deslizantes de brillo y contraste
48
         * 
49
         * @author Nacho Brodin (nachobrodin@gmail.com)
50
         */
51
        class InternalPanel extends JPanel{
52
                final private static long        serialVersionUID = 0;
53
                protected SliderTextContainer brightness = null;
54
                protected SliderTextContainer contrast = null;
55

    
56
                /**
57
                 * Contructor
58
                 */
59
                public InternalPanel(){
60
                        brightness = new SliderTextContainer(-255, 255, 0);
61
                        contrast = new SliderTextContainer(-255, 255, 0);
62
                        brightness.setBorder(PluginServices.getText(this, "brillo"));
63
                        contrast.setBorder(PluginServices.getText(this, "contraste"));
64
                        init();
65
                }
66

    
67
                private void init(){
68
                        this.setLayout(new GridLayout(2, 1));
69
                        this.add(brightness);
70
                        this.add(contrast);
71
                }
72

    
73
                /**
74
                 * Activa o desactiva el control
75
                 * @param enable true activa y false desactiva los controles del panel
76
                 */
77
                public void setControlEnabled(boolean enabled){
78
                        brightness.setControlEnabled(enabled);
79
                        contrast.setControlEnabled(enabled);
80
                }
81

    
82
        }
83

    
84
        /**
85
         * Contructor
86
         */
87
        public EnhancedBrightnessContrastPanel(){
88
                super();
89
                internalPanel = new InternalPanel();
90
                initialize();
91
        }
92

    
93
        private void initialize() {
94
                setBorder(javax.swing.BorderFactory.createTitledBorder(null, PluginServices.getText(this, "brillo_y_contraste"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
95
                setLayout(new BorderLayout());
96
                add(getActive(), BorderLayout.NORTH);
97
                add(internalPanel, BorderLayout.CENTER);
98
                add(getPreview(), BorderLayout.SOUTH);
99
                getActive().addActionListener(this);
100

    
101
        }
102

    
103
        /**
104
         * Obtiene el check de activar
105
         * @return
106
         */
107
        public JCheckBox getActive(){
108
                if(active == null){
109
                        active = new JCheckBox(PluginServices.getText(this, "activar"));
110
                        active.setSelected(false);
111
                        setControlEnabled(false);
112
                }
113
                return active;
114
        }
115

    
116
        /**
117
         * Obtiene el check de previsualizaci?n
118
         * @return
119
         */
120
        public JCheckBox getPreview(){
121
                if(preview == null){
122
                        preview = new JCheckBox(PluginServices.getText(this, "previsualizacion"));
123
                        preview.setSelected(true);
124
                }
125
                return preview;
126
        }
127

    
128
        /**
129
         * Activa o desactiva el control
130
         * @param enable true activa y false desactiva los controles del panel
131
         */
132
        public void setControlEnabled(boolean enabled){
133
                this.getActive().setSelected(enabled);
134
                this.getPreview().setEnabled(enabled);
135
                internalPanel.setControlEnabled(enabled);
136
        }
137

    
138
        /**
139
         * Obtiene el valor del brillo que hay seleccionado en el control
140
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que 
141
         * no se consideran decimales
142
         */
143
        public double getBrightnessValue(){
144
                return internalPanel.brightness.getValue();
145
        }
146

    
147
        /**
148
         * Obtiene el valor del contraste que hay seleccionado en el control
149
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que 
150
         * no se consideran decimales
151
         */
152
        public double getContrastValue(){
153
                return internalPanel.contrast.getValue();
154
        }
155

    
156
        /**
157
         * Asigna el valor del brillo al control
158
         * @param value
159
         */
160
        public void setBrightnessValue(double value){
161
                internalPanel.brightness.setValue(value);
162
        }
163

    
164
        /**
165
         * Asigna el valor del contraste al control
166
         * @param value
167
         */
168
        public void setContrastValue(double value){
169
                internalPanel.contrast.setValue(value);
170
        }
171

    
172
        /**
173
         * A?ade un listener para el slider de brillo
174
         * @param l ChangeListener
175
         */
176
        public void addBrightnessChangeListener(ChangeListener l){
177
                internalPanel.brightness.addChangeListener(l);
178
        }
179

    
180
        /**
181
         * A?ade un listener para el slider de contraste
182
         * @param l ChangeListener
183
         */
184
        public void addContrastChangeListener(ChangeListener l){
185
                internalPanel.contrast.addChangeListener(l);
186
        }
187

    
188
        /**
189
         * A?ade un listener para el slider de brillo
190
         * @param l MouseListener
191
         */
192
        public void addBrightnessMouseListener(MouseListener l){
193
                internalPanel.brightness.addMouseListener(l);
194
        }
195

    
196
        /**
197
         * A?ade un listener para el slider de contraste
198
         * @param l MouseListener
199
         */
200
        public void addContrastMouseListener(MouseListener l){
201
                internalPanel.contrast.addMouseListener(l);
202
        }
203

    
204
        /**
205
         * A?ade un listener para el slider de brillo
206
         * @param l MouseListener
207
         */
208
        public void addBrightnessKeyListener(KeyListener l){
209
                internalPanel.brightness.addKeyListener(l);
210
        }
211

    
212
        /**
213
         * A?ade un listener para el slider de contraste
214
         * @param l MouseListener
215
         */
216
        public void addContrastKeyListener(KeyListener l){
217
                internalPanel.contrast.addKeyListener(l);
218
        }
219

    
220
        /**
221
         * Maneja eventos de activar y desactivar el panel
222
         */
223
        public void actionPerformed(ActionEvent e) {
224
                if(e.getSource() == getActive()){
225
                        if(getActive().isSelected())
226
                                setControlEnabled(true);
227
                        else
228
                                setControlEnabled(false);
229
                }
230
        }
231

    
232
}
233