gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / properties / panel / EnhancedBrightnessContrastPanel.java @ 2480
History | View | Annotate | Download (5.32 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.properties.panel; |
23 |
|
24 |
import java.awt.BorderLayout; |
25 |
import java.awt.Dimension; |
26 |
import java.awt.GridLayout; |
27 |
import java.awt.event.ActionEvent; |
28 |
import java.awt.event.ActionListener; |
29 |
|
30 |
import javax.swing.JCheckBox; |
31 |
import javax.swing.JPanel; |
32 |
|
33 |
import org.gvsig.andami.PluginServices; |
34 |
import org.gvsig.gui.beans.slidertext.SliderTextContainer; |
35 |
import org.gvsig.gui.beans.slidertext.listeners.SliderListener; |
36 |
|
37 |
/**
|
38 |
* Panel para los controles de brillo y contrase .
|
39 |
*
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class EnhancedBrightnessContrastPanel extends JPanel implements ActionListener { |
43 |
private static final long serialVersionUID = -475762560608930500L; |
44 |
private InternalPanel internalPanel = null; |
45 |
private JCheckBox active = null; |
46 |
|
47 |
/**
|
48 |
* Panel con los controles deslizantes de brillo y contraste
|
49 |
*
|
50 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
51 |
*/
|
52 |
class InternalPanel extends JPanel { |
53 |
final private static long serialVersionUID = 0; |
54 |
protected SliderTextContainer brightness = null; |
55 |
protected SliderTextContainer contrast = null; |
56 |
|
57 |
/**
|
58 |
* Contructor
|
59 |
*/
|
60 |
public InternalPanel() {
|
61 |
brightness = new SliderTextContainer(-255, 255, 0, false); |
62 |
contrast = new SliderTextContainer(-255, 255, 0, false); |
63 |
brightness.setBorder(PluginServices.getText(this, "brillo")); |
64 |
contrast.setBorder(PluginServices.getText(this, "contraste")); |
65 |
init(); |
66 |
} |
67 |
|
68 |
private void init() { |
69 |
this.setLayout(new GridLayout(2, 1)); |
70 |
this.add(brightness);
|
71 |
this.add(contrast);
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* Activa o desactiva el control
|
76 |
* @param enable true activa y false desactiva los controles del panel
|
77 |
*/
|
78 |
public void setControlEnabled(boolean enabled) { |
79 |
brightness.setControlEnabled(enabled); |
80 |
contrast.setControlEnabled(enabled); |
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 |
getActive().addActionListener(this);
|
99 |
this.setPreferredSize(new Dimension(100, 80)); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Obtiene el check de activar
|
104 |
* @return
|
105 |
*/
|
106 |
public JCheckBox getActive() { |
107 |
if (active == null) { |
108 |
active = new JCheckBox(PluginServices.getText(this, "activar")); |
109 |
active.setSelected(false);
|
110 |
setControlEnabled(false);
|
111 |
} |
112 |
return active;
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Activa o desactiva el control
|
117 |
* @param enable true activa y false desactiva los controles del panel
|
118 |
*/
|
119 |
public void setControlEnabled(boolean enabled){ |
120 |
this.getActive().setSelected(enabled);
|
121 |
internalPanel.setControlEnabled(enabled); |
122 |
} |
123 |
|
124 |
/**
|
125 |
* Obtiene el valor del brillo que hay seleccionado en el control
|
126 |
* @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que
|
127 |
* no se consideran decimales
|
128 |
*/
|
129 |
public double getBrightnessValue(){ |
130 |
return internalPanel.brightness.getValue();
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* Obtiene el valor del contraste que hay seleccionado en el control
|
135 |
* @return double que representa el contraste seleccionado. Puede hacerse un casting a entero ya que
|
136 |
* no se consideran decimales
|
137 |
*/
|
138 |
public double getContrastValue(){ |
139 |
return internalPanel.contrast.getValue();
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Asigna el valor del brillo al control
|
144 |
* @param value
|
145 |
*/
|
146 |
public void setBrightnessValue(double value){ |
147 |
internalPanel.brightness.setValue(value); |
148 |
} |
149 |
|
150 |
/**
|
151 |
* Asigna el valor del contraste al control
|
152 |
* @param value
|
153 |
*/
|
154 |
public void setContrastValue(double value){ |
155 |
internalPanel.contrast.setValue(value); |
156 |
} |
157 |
|
158 |
/**
|
159 |
* A?ade un listener para el slider de brillo
|
160 |
* @param l ChangeListener
|
161 |
*/
|
162 |
public void addBrightnessValueChangedListener(SliderListener l){ |
163 |
internalPanel.brightness.addValueChangedListener(l); |
164 |
} |
165 |
|
166 |
/**
|
167 |
* A?ade un listener para el slider de contraste
|
168 |
* @param l ChangeListener
|
169 |
*/
|
170 |
public void addContrastValueChangedListener(SliderListener l){ |
171 |
internalPanel.contrast.addValueChangedListener(l); |
172 |
} |
173 |
|
174 |
/**
|
175 |
* Maneja eventos de activar y desactivar el panel
|
176 |
*/
|
177 |
public void actionPerformed(ActionEvent e) { |
178 |
if (e.getSource() == getActive()) {
|
179 |
if (getActive().isSelected())
|
180 |
setControlEnabled(true);
|
181 |
else
|
182 |
setControlEnabled(false);
|
183 |
} |
184 |
} |
185 |
} |