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