root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyPanel.java @ 12180
History | View | Annotate | Download (7.54 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.event.ActionEvent; |
23 |
import java.awt.event.ActionListener; |
24 |
|
25 |
import javax.swing.JCheckBox; |
26 |
import javax.swing.JPanel; |
27 |
|
28 |
import org.gvsig.gui.beans.checkslidertext.CheckSliderTextContainer; |
29 |
import org.gvsig.gui.beans.slidertext.listeners.SliderEvent; |
30 |
import org.gvsig.gui.beans.slidertext.listeners.SliderListener; |
31 |
import org.gvsig.raster.shared.IRasterProperties; |
32 |
import org.gvsig.rastertools.properties.control.TransparencyControl; |
33 |
import org.gvsig.rastertools.properties.dialog.IRegistrablePanel; |
34 |
|
35 |
import com.iver.andami.PluginServices; |
36 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
37 |
/**
|
38 |
* Dialogo para asignar la transparencia por pixel y global al raster.
|
39 |
*
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
41 |
*/
|
42 |
public class TransparencyPanel extends JPanel implements ActionListener, IRegistrablePanel, SliderListener { |
43 |
private static final long serialVersionUID = -4556920949255458471L; |
44 |
private IRasterProperties op = null; |
45 |
|
46 |
/**
|
47 |
* Nombre del panel
|
48 |
*/
|
49 |
private String id = "transparencia"; |
50 |
|
51 |
/**
|
52 |
* N?mero de bandas del raster
|
53 |
*/
|
54 |
public int nBands = 3; |
55 |
private JCheckBox cbTransparencia = null; |
56 |
private TransparencySelectionPanel pTransSelect = null; |
57 |
private TranspByPixelPanel pTranspByPixel = null; |
58 |
private CheckSliderTextContainer pOpacity = null; |
59 |
private TransparencyControl tControl = null; |
60 |
|
61 |
/**
|
62 |
* Constructor.
|
63 |
*/
|
64 |
public TransparencyPanel() {
|
65 |
id = PluginServices.getText(this, id);
|
66 |
tControl = new TransparencyControl(this); |
67 |
initialize(); |
68 |
} |
69 |
|
70 |
/**
|
71 |
* This method initializes this
|
72 |
* @return void
|
73 |
*/
|
74 |
private void initialize() { |
75 |
this.setLayout(new BorderLayout()); |
76 |
this.add(getPTranspByPixel(), BorderLayout.CENTER); |
77 |
this.add(getOpacityPanel(), BorderLayout.NORTH); |
78 |
//this.add(getSelectionPanel(), BorderLayout.SOUTH);
|
79 |
initControls(); |
80 |
} |
81 |
|
82 |
/**
|
83 |
* Asigna el n?mero de bandas de la imagen
|
84 |
* @param nBands
|
85 |
*/
|
86 |
public void setBands(int nBands) { |
87 |
this.nBands = nBands;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Inicializa controles a sus valores por defecto
|
92 |
*/
|
93 |
public void initControls() { |
94 |
this.setActiveTransparencyControl(false); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* This method initializes jCheckBox
|
99 |
* @return javax.swing.JCheckBox
|
100 |
*/
|
101 |
public JCheckBox getTransparencyCheck() { |
102 |
if (cbTransparencia == null) { |
103 |
cbTransparencia = new JCheckBox(); |
104 |
cbTransparencia.setText("Activar");
|
105 |
cbTransparencia.addActionListener(this);
|
106 |
} |
107 |
|
108 |
return cbTransparencia;
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* This method initializes TranspOpacitySliderPanel
|
113 |
* @return javax.swing.JPanel
|
114 |
*/
|
115 |
public CheckSliderTextContainer getOpacityPanel() {
|
116 |
if (pOpacity == null) { |
117 |
pOpacity = new CheckSliderTextContainer(0, 100, 100, false, PluginServices.getText(this, "activar"), false); |
118 |
pOpacity.setDecimal(false);
|
119 |
pOpacity.setBorder(PluginServices.getText(this, "opacidad")); |
120 |
pOpacity.addValueChangedListener(this);
|
121 |
} |
122 |
|
123 |
return pOpacity;
|
124 |
} |
125 |
|
126 |
/**
|
127 |
* This method initializes TranspOpacitySliderPanel
|
128 |
* @return javax.swing.JPanel
|
129 |
*/
|
130 |
public TransparencySelectionPanel getSelectionPanel() {
|
131 |
if (pTransSelect == null) |
132 |
pTransSelect = new TransparencySelectionPanel();
|
133 |
|
134 |
return pTransSelect;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* Activa/Desactiva los controles de transparencia
|
139 |
* @param active
|
140 |
*/
|
141 |
public void setActiveTransparencyControl(boolean active) { |
142 |
this.getTransparencyCheck().setSelected(active);
|
143 |
TranspByPixelRGBInputPanel rgbPanel = this.getPTranspByPixel().getPRGBInput();
|
144 |
rgbPanel.getTRed().setEnabled(active); |
145 |
|
146 |
if (op != null) { |
147 |
if (op.getBandCount() == 2) { |
148 |
rgbPanel.getTGreen().setEnabled(active); |
149 |
rgbPanel.getTBlue().setEnabled(false);
|
150 |
} |
151 |
|
152 |
if (op.getBandCount() == 3) { |
153 |
rgbPanel.getTGreen().setEnabled(active); |
154 |
rgbPanel.getTBlue().setEnabled(active); |
155 |
} |
156 |
} |
157 |
} |
158 |
|
159 |
/**
|
160 |
* This method initializes jPanel2
|
161 |
* @return javax.swing.JPanel
|
162 |
*/
|
163 |
public TranspByPixelPanel getPTranspByPixel() {
|
164 |
if (pTranspByPixel == null) |
165 |
pTranspByPixel = new TranspByPixelPanel();
|
166 |
|
167 |
return pTranspByPixel;
|
168 |
} |
169 |
|
170 |
/**
|
171 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de
|
172 |
* opacidad, transparencia, recorte de colas y los textfield de opacidad,
|
173 |
* valores de transparencia por banda y porcentaje de recorte.
|
174 |
*/
|
175 |
public void actionPerformed(ActionEvent e) { |
176 |
// Evento sobre el checkbox de transparencia
|
177 |
if (e.getSource().equals(getTransparencyCheck())) {
|
178 |
// Check de opacidad activado -> Activar controles de opacidad
|
179 |
if (getTransparencyCheck().isSelected()) {
|
180 |
getPTranspByPixel().setControlEnabled(true);
|
181 |
getPTranspByPixel().getPRGBInput().setActiveBands(nBands); |
182 |
} else
|
183 |
getPTranspByPixel().setControlEnabled(false);
|
184 |
} |
185 |
} |
186 |
|
187 |
/**
|
188 |
* Obtiene el interfaz de operaciones raster
|
189 |
* @return FLyrRasterSE
|
190 |
*/
|
191 |
public IRasterProperties getRasterOperations() {
|
192 |
return op;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Obtiene la capa si existe esta.
|
197 |
* @return FLayer si existe una capa o null si no existe.
|
198 |
*/
|
199 |
public FLayer getLayer() {
|
200 |
if (op instanceof FLayer) |
201 |
return (FLayer) op;
|
202 |
return null; |
203 |
} |
204 |
|
205 |
/*
|
206 |
* (non-Javadoc)
|
207 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
208 |
*/
|
209 |
public void setLayer(FLayer lyr) { |
210 |
if (lyr instanceof IRasterProperties) { |
211 |
op = (IRasterProperties) lyr; |
212 |
tControl.setTransparencyObject(op.getRenderTransparency()); |
213 |
} |
214 |
} |
215 |
|
216 |
/*
|
217 |
* (non-Javadoc)
|
218 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
|
219 |
*/
|
220 |
public void accept() { |
221 |
tControl.accept(); |
222 |
} |
223 |
|
224 |
/*
|
225 |
* (non-Javadoc)
|
226 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
|
227 |
*/
|
228 |
public void apply() { |
229 |
tControl.apply(); |
230 |
} |
231 |
|
232 |
/*
|
233 |
* (non-Javadoc)
|
234 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
|
235 |
*/
|
236 |
public void cancel() { |
237 |
tControl.cancel(); |
238 |
} |
239 |
|
240 |
/*
|
241 |
* (non-Javadoc)
|
242 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
243 |
*/
|
244 |
public String getID() { |
245 |
return id;
|
246 |
} |
247 |
|
248 |
/*
|
249 |
* (non-Javadoc)
|
250 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
251 |
*/
|
252 |
public void selectTab(String id) {} |
253 |
|
254 |
/*
|
255 |
* (non-Javadoc)
|
256 |
* @see org.gvsig.rastertools.properties.dialog.IResizable#setComponentSize(int, int)
|
257 |
*/
|
258 |
public void setComponentSize(int w, int h) {} |
259 |
|
260 |
/*
|
261 |
* (non-Javadoc)
|
262 |
* @see org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueChanged(org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
|
263 |
*/
|
264 |
public void actionValueChanged(SliderEvent e) { |
265 |
tControl.onlyApply(); |
266 |
} |
267 |
|
268 |
/*
|
269 |
* (non-Javadoc)
|
270 |
* @see org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueDragged(org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
|
271 |
*/
|
272 |
public void actionValueDragged(SliderEvent e) {} |
273 |
} |