Statistics
| Revision:

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

History | View | Annotate | Download (5.26 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
package org.gvsig.rastertools.properties.panels;
20
21
import java.awt.BorderLayout;
22 17047 nbrodin
import java.awt.Dimension;
23 10740 nacho
import java.awt.GridLayout;
24
import java.awt.event.ActionEvent;
25
import java.awt.event.ActionListener;
26
27
import javax.swing.JCheckBox;
28
import javax.swing.JPanel;
29
30
import org.gvsig.gui.beans.slidertext.SliderTextContainer;
31 12180 bsanchez
import org.gvsig.gui.beans.slidertext.listeners.SliderListener;
32 10740 nacho
33
import com.iver.andami.PluginServices;
34
/**
35
 * Panel para los controles de brillo y contrase .
36
 *
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 */
39 12180 bsanchez
public class EnhancedBrightnessContrastPanel extends JPanel implements ActionListener {
40
        private static final long serialVersionUID = -475762560608930500L;
41
        private InternalPanel     internalPanel    = null;
42
        private JCheckBox         active           = null;
43 12127 bsanchez
44 10740 nacho
        /**
45
         * Panel con los controles deslizantes de brillo y contraste
46
         *
47
         * @author Nacho Brodin (nachobrodin@gmail.com)
48
         */
49 12138 bsanchez
        class InternalPanel extends JPanel {
50 10740 nacho
                final private static long        serialVersionUID = 0;
51
                protected SliderTextContainer brightness = null;
52
                protected SliderTextContainer contrast = null;
53 12127 bsanchez
54 10740 nacho
                /**
55
                 * Contructor
56
                 */
57 12138 bsanchez
                public InternalPanel() {
58 10740 nacho
                        brightness = new SliderTextContainer(-255, 255, 0);
59
                        contrast = new SliderTextContainer(-255, 255, 0);
60
                        brightness.setBorder(PluginServices.getText(this, "brillo"));
61
                        contrast.setBorder(PluginServices.getText(this, "contraste"));
62
                        init();
63
                }
64 12127 bsanchez
65 12138 bsanchez
                private void init() {
66 10740 nacho
                        this.setLayout(new GridLayout(2, 1));
67
                        this.add(brightness);
68
                        this.add(contrast);
69
                }
70 12127 bsanchez
71 10740 nacho
                /**
72
                 * Activa o desactiva el control
73
                 * @param enable true activa y false desactiva los controles del panel
74
                 */
75 12138 bsanchez
                public void setControlEnabled(boolean enabled) {
76 10740 nacho
                        brightness.setControlEnabled(enabled);
77
                        contrast.setControlEnabled(enabled);
78
                }
79
        }
80 12127 bsanchez
81 10740 nacho
        /**
82
         * Contructor
83
         */
84 12138 bsanchez
        public EnhancedBrightnessContrastPanel() {
85 10740 nacho
                super();
86
                internalPanel = new InternalPanel();
87
                initialize();
88
        }
89 12127 bsanchez
90 10740 nacho
        private void initialize() {
91
                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));
92
                setLayout(new BorderLayout());
93
                add(getActive(), BorderLayout.NORTH);
94
                add(internalPanel, BorderLayout.CENTER);
95
                getActive().addActionListener(this);
96 17047 nbrodin
                this.setPreferredSize(new Dimension(100, 80));
97 10740 nacho
        }
98 12127 bsanchez
99 10740 nacho
        /**
100
         * Obtiene el check de activar
101
         * @return
102
         */
103 12138 bsanchez
        public JCheckBox getActive() {
104
                if (active == null) {
105 10740 nacho
                        active = new JCheckBox(PluginServices.getText(this, "activar"));
106
                        active.setSelected(false);
107
                        setControlEnabled(false);
108
                }
109
                return active;
110
        }
111 12127 bsanchez
112 10740 nacho
        /**
113
         * Activa o desactiva el control
114
         * @param enable true activa y false desactiva los controles del panel
115
         */
116
        public void setControlEnabled(boolean enabled){
117
                this.getActive().setSelected(enabled);
118
                internalPanel.setControlEnabled(enabled);
119
        }
120 12127 bsanchez
121 10740 nacho
        /**
122
         * Obtiene el valor del brillo que hay seleccionado en el control
123
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que
124
         * no se consideran decimales
125
         */
126
        public double getBrightnessValue(){
127
                return internalPanel.brightness.getValue();
128
        }
129 12127 bsanchez
130 10740 nacho
        /**
131
         * Obtiene el valor del contraste que hay seleccionado en el control
132
         * @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que
133
         * no se consideran decimales
134
         */
135
        public double getContrastValue(){
136
                return internalPanel.contrast.getValue();
137
        }
138 12127 bsanchez
139 10740 nacho
        /**
140
         * Asigna el valor del brillo al control
141
         * @param value
142
         */
143
        public void setBrightnessValue(double value){
144
                internalPanel.brightness.setValue(value);
145
        }
146 12127 bsanchez
147 10740 nacho
        /**
148
         * Asigna el valor del contraste al control
149
         * @param value
150
         */
151
        public void setContrastValue(double value){
152
                internalPanel.contrast.setValue(value);
153
        }
154 12127 bsanchez
155 10740 nacho
        /**
156
         * A?ade un listener para el slider de brillo
157
         * @param l ChangeListener
158
         */
159 12180 bsanchez
        public void addBrightnessValueChangedListener(SliderListener l){
160
                internalPanel.brightness.addValueChangedListener(l);
161 10740 nacho
        }
162 12127 bsanchez
163 10740 nacho
        /**
164
         * A?ade un listener para el slider de contraste
165
         * @param l ChangeListener
166
         */
167 12180 bsanchez
        public void addContrastValueChangedListener(SliderListener l){
168
                internalPanel.contrast.addValueChangedListener(l);
169 10740 nacho
        }
170 12127 bsanchez
171 10740 nacho
        /**
172
         * Maneja eventos de activar y desactivar el panel
173
         */
174
        public void actionPerformed(ActionEvent e) {
175 12138 bsanchez
                if (e.getSource() == getActive()) {
176
                        if (getActive().isSelected())
177 10740 nacho
                                setControlEnabled(true);
178
                        else
179
                                setControlEnabled(false);
180
                }
181
        }
182 12138 bsanchez
}