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