root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyPanel.java @ 10740
History | View | Annotate | Download (7.38 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.fmap.layers.FLyrRasterSE; |
29 |
import org.gvsig.gui.beans.checkslidertext.CheckSliderTextContainer; |
30 |
import org.gvsig.raster.shared.IRasterProperties; |
31 |
import org.gvsig.rastertools.properties.dialog.IRegistrablePanel; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
35 |
|
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{ |
42 |
final private static long serialVersionUID = 0; |
43 |
private IRasterProperties op = null; |
44 |
/**
|
45 |
* Nombre del panel
|
46 |
*/
|
47 |
private String id = "transparencia"; |
48 |
/**
|
49 |
* N?mero de bandas del raster
|
50 |
*/
|
51 |
public int nBands = 3; |
52 |
private JCheckBox cbTransparencia = null; |
53 |
private TransparencySelectionPanel pTransSelect = null; |
54 |
private TranspByPixelPanel pTranspByPixel = null; |
55 |
private CheckSliderTextContainer pOpacity = null; |
56 |
private TransparencyControl tControl = null; |
57 |
|
58 |
/**
|
59 |
* Constructor.
|
60 |
*/
|
61 |
public TransparencyPanel() {
|
62 |
id = PluginServices.getText(this, id);
|
63 |
tControl = new TransparencyControl(this); |
64 |
initialize(); |
65 |
} |
66 |
|
67 |
/**
|
68 |
* This method initializes this
|
69 |
*
|
70 |
* @return void
|
71 |
*/
|
72 |
private void initialize() { |
73 |
this.setLayout(new BorderLayout()); |
74 |
this.add(getPTranspByPixel(), BorderLayout.CENTER); |
75 |
this.add(getOpacityPanel(), BorderLayout.NORTH); |
76 |
this.add(getSelectionPanel(), BorderLayout.SOUTH); |
77 |
initControls(); |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Asigna el n?mero de bandas de la imagen
|
82 |
* @param nBands
|
83 |
*/
|
84 |
public void setBands(int nBands) { |
85 |
this.nBands = nBands;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Inicializa controles a sus valores por defecto
|
90 |
*/
|
91 |
public void initControls() { |
92 |
this.setActiveTransparencyControl(false); |
93 |
} |
94 |
|
95 |
/**
|
96 |
* This method initializes jCheckBox
|
97 |
*
|
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 |
*
|
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 |
} |
121 |
|
122 |
return pOpacity;
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* This method initializes TranspOpacitySliderPanel
|
127 |
*
|
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 |
*
|
162 |
* @return javax.swing.JPanel
|
163 |
*/
|
164 |
public TranspByPixelPanel getPTranspByPixel() {
|
165 |
if (pTranspByPixel == null) |
166 |
pTranspByPixel = new TranspByPixelPanel();
|
167 |
|
168 |
return pTranspByPixel;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Ajusta el tama?o de todos los componentes a partir del tama?o
|
173 |
* introducido para el panel.
|
174 |
* @param w
|
175 |
* @param h
|
176 |
*/
|
177 |
public void setComponentSize(int w, int h){ |
178 |
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Eventos sobre TextField y CheckBox. Controla eventos de checkbox de opacidad, transparencia,
|
183 |
* recorte de colas y los textfield de opacidad, valores de transparencia por banda y
|
184 |
* porcentaje de recorte.
|
185 |
*/
|
186 |
public void actionPerformed(ActionEvent e) { |
187 |
//Evento sobre el checkbox de transparencia
|
188 |
if (e.getSource().equals(getTransparencyCheck())) {
|
189 |
//Check de opacidad activado -> Activar controles de opacidad
|
190 |
if (getTransparencyCheck().isSelected()) {
|
191 |
getPTranspByPixel().setControlEnabled(true);
|
192 |
getPTranspByPixel().getPRGBInput().setActiveBands(nBands); |
193 |
}else
|
194 |
getPTranspByPixel().setControlEnabled(false);
|
195 |
} |
196 |
} |
197 |
|
198 |
/**
|
199 |
* Obtiene el interfaz de operaciones raster
|
200 |
* @return FLyrRasterSE
|
201 |
*/
|
202 |
public IRasterProperties getRasterOperations(){
|
203 |
return op;
|
204 |
} |
205 |
|
206 |
/**
|
207 |
* Obtiene la capa si existe esta.
|
208 |
* @return FLayer si existe una capa o null si no existe.
|
209 |
*/
|
210 |
public FLayer getLayer(){
|
211 |
if(op instanceof FLayer) |
212 |
return (FLayer)op;
|
213 |
return null; |
214 |
} |
215 |
|
216 |
/*
|
217 |
* (non-Javadoc)
|
218 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
219 |
*/
|
220 |
public void setLayer(FLayer lyr) { |
221 |
if(lyr instanceof IRasterProperties){ |
222 |
op = (IRasterProperties)lyr; |
223 |
tControl.setTransparencyObject(op.getRenderTransparency()); |
224 |
} |
225 |
} |
226 |
|
227 |
/*
|
228 |
* (non-Javadoc)
|
229 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#accept()
|
230 |
*/
|
231 |
public void accept() { |
232 |
tControl.accept(); |
233 |
} |
234 |
|
235 |
/*
|
236 |
* (non-Javadoc)
|
237 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
|
238 |
*/
|
239 |
public void apply() { |
240 |
tControl.apply(); |
241 |
} |
242 |
|
243 |
/*
|
244 |
* (non-Javadoc)
|
245 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
|
246 |
*/
|
247 |
public void cancel() { |
248 |
tControl.cancel(); |
249 |
} |
250 |
|
251 |
/*
|
252 |
* (non-Javadoc)
|
253 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
254 |
*/
|
255 |
public String getID() { |
256 |
return id;
|
257 |
} |
258 |
|
259 |
/*
|
260 |
* (non-Javadoc)
|
261 |
* @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
262 |
*/
|
263 |
public void selectTab(String id) { |
264 |
} |
265 |
} // @jve:decl-index=0:visual-constraint="36,15"
|