Statistics
| Revision:

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

History | View | Annotate | Download (5.19 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

    
26
import javax.swing.JCheckBox;
27
import javax.swing.JPanel;
28

    
29
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
30
import org.gvsig.gui.beans.slidertext.listeners.SliderListener;
31

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

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

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

    
64
                private void init() {
65
                        this.setLayout(new GridLayout(2, 1));
66
                        this.add(brightness);
67
                        this.add(contrast);
68
                }
69

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

    
80
        /**
81
         * Contructor
82
         */
83
        public EnhancedBrightnessContrastPanel() {
84
                super();
85
                internalPanel = new InternalPanel();
86
                initialize();
87
        }
88

    
89
        private void initialize() {
90
                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));
91
                setLayout(new BorderLayout());
92
                add(getActive(), BorderLayout.NORTH);
93
                add(internalPanel, BorderLayout.CENTER);
94
                getActive().addActionListener(this);
95
        }
96

    
97
        /**
98
         * Obtiene el check de activar
99
         * @return
100
         */
101
        public JCheckBox getActive() {
102
                if (active == null) {
103
                        active = new JCheckBox(PluginServices.getText(this, "activar"));
104
                        active.setSelected(false);
105
                        setControlEnabled(false);
106
                }
107
                return active;
108
        }
109

    
110
        /**
111
         * Activa o desactiva el control
112
         * @param enable true activa y false desactiva los controles del panel
113
         */
114
        public void setControlEnabled(boolean enabled){
115
                this.getActive().setSelected(enabled);
116
                internalPanel.setControlEnabled(enabled);
117
        }
118

    
119
        /**
120
         * Obtiene el valor del brillo que hay seleccionado en el control
121
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que 
122
         * no se consideran decimales
123
         */
124
        public double getBrightnessValue(){
125
                return internalPanel.brightness.getValue();
126
        }
127

    
128
        /**
129
         * Obtiene el valor del contraste que hay seleccionado en el control
130
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que 
131
         * no se consideran decimales
132
         */
133
        public double getContrastValue(){
134
                return internalPanel.contrast.getValue();
135
        }
136

    
137
        /**
138
         * Asigna el valor del brillo al control
139
         * @param value
140
         */
141
        public void setBrightnessValue(double value){
142
                internalPanel.brightness.setValue(value);
143
        }
144

    
145
        /**
146
         * Asigna el valor del contraste al control
147
         * @param value
148
         */
149
        public void setContrastValue(double value){
150
                internalPanel.contrast.setValue(value);
151
        }
152

    
153
        /**
154
         * A?ade un listener para el slider de brillo
155
         * @param l ChangeListener
156
         */
157
        public void addBrightnessValueChangedListener(SliderListener l){
158
                internalPanel.brightness.addValueChangedListener(l);
159
        }
160

    
161
        /**
162
         * A?ade un listener para el slider de contraste
163
         * @param l ChangeListener
164
         */
165
        public void addContrastValueChangedListener(SliderListener l){
166
                internalPanel.contrast.addValueChangedListener(l);
167
        }
168

    
169
        /**
170
         * Maneja eventos de activar y desactivar el panel
171
         */
172
        public void actionPerformed(ActionEvent e) {
173
                if (e.getSource() == getActive()) {
174
                        if (getActive().isSelected())
175
                                setControlEnabled(true);
176
                        else
177
                                setControlEnabled(false);
178
                }
179
        }
180
}