root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / properties / panels / TransparencyPanel.java @ 12180
History | View | Annotate | Download (7.54 KB)
1 | 10740 | nacho | /* 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 | 12180 | bsanchez | import org.gvsig.gui.beans.slidertext.listeners.SliderEvent; |
30 | import org.gvsig.gui.beans.slidertext.listeners.SliderListener; |
||
31 | 10740 | nacho | import org.gvsig.raster.shared.IRasterProperties; |
32 | 12166 | bsanchez | import org.gvsig.rastertools.properties.control.TransparencyControl; |
33 | 10740 | nacho | 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 | 12180 | bsanchez | public class TransparencyPanel extends JPanel implements ActionListener, IRegistrablePanel, SliderListener { |
43 | 12154 | bsanchez | private static final long serialVersionUID = -4556920949255458471L; |
44 | private IRasterProperties op = null; |
||
45 | 10740 | nacho | |
46 | 12154 | bsanchez | /**
|
47 | * Nombre del panel
|
||
48 | */
|
||
49 | private String id = "transparencia"; |
||
50 | 10740 | nacho | |
51 | 12154 | bsanchez | /**
|
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 | 10740 | nacho | |
61 | 12154 | bsanchez | /**
|
62 | * Constructor.
|
||
63 | */
|
||
64 | public TransparencyPanel() {
|
||
65 | id = PluginServices.getText(this, id);
|
||
66 | tControl = new TransparencyControl(this); |
||
67 | initialize(); |
||
68 | } |
||
69 | 10740 | nacho | |
70 | 12154 | bsanchez | /**
|
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 | 10740 | nacho | |
82 | 12154 | bsanchez | /**
|
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 | 10740 | nacho | |
90 | 12154 | bsanchez | /**
|
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 | 12138 | bsanchez | } |
107 | 10740 | nacho | |
108 | 12154 | bsanchez | return cbTransparencia;
|
109 | } |
||
110 | 12138 | bsanchez | |
111 | 12154 | bsanchez | /**
|
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 | 12180 | bsanchez | pOpacity.addValueChangedListener(this);
|
121 | 12138 | bsanchez | } |
122 | |||
123 | 12154 | bsanchez | return pOpacity;
|
124 | } |
||
125 | 12138 | bsanchez | |
126 | 12154 | bsanchez | /**
|
127 | * This method initializes TranspOpacitySliderPanel
|
||
128 | * @return javax.swing.JPanel
|
||
129 | */
|
||
130 | public TransparencySelectionPanel getSelectionPanel() {
|
||
131 | if (pTransSelect == null) |
||
132 | pTransSelect = new TransparencySelectionPanel();
|
||
133 | 12138 | bsanchez | |
134 | 12154 | bsanchez | return pTransSelect;
|
135 | } |
||
136 | 12138 | bsanchez | |
137 | 12154 | bsanchez | /**
|
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 | 12138 | bsanchez | |
146 | 12154 | bsanchez | 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 | 12138 | bsanchez | } |
157 | 12154 | bsanchez | } |
158 | 12138 | bsanchez | |
159 | 12154 | bsanchez | /**
|
160 | * This method initializes jPanel2
|
||
161 | * @return javax.swing.JPanel
|
||
162 | 10740 | nacho | */
|
163 | public TranspByPixelPanel getPTranspByPixel() {
|
||
164 | 12138 | bsanchez | if (pTranspByPixel == null) |
165 | 10740 | nacho | pTranspByPixel = new TranspByPixelPanel();
|
166 | 12138 | bsanchez | |
167 | 10740 | nacho | return pTranspByPixel;
|
168 | } |
||
169 | |||
170 | /**
|
||
171 | 12154 | bsanchez | * 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 | 10740 | nacho | */
|
175 | public void actionPerformed(ActionEvent e) { |
||
176 | 12154 | bsanchez | // 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 | 10740 | nacho | } |
186 | 12138 | bsanchez | |
187 | 10740 | nacho | /**
|
188 | * Obtiene el interfaz de operaciones raster
|
||
189 | * @return FLyrRasterSE
|
||
190 | */
|
||
191 | 12154 | bsanchez | public IRasterProperties getRasterOperations() {
|
192 | 10740 | nacho | return op;
|
193 | } |
||
194 | 12138 | bsanchez | |
195 | 10740 | nacho | /**
|
196 | * Obtiene la capa si existe esta.
|
||
197 | * @return FLayer si existe una capa o null si no existe.
|
||
198 | */
|
||
199 | 12154 | bsanchez | public FLayer getLayer() {
|
200 | if (op instanceof FLayer) |
||
201 | return (FLayer) op;
|
||
202 | 10740 | nacho | return null; |
203 | } |
||
204 | 12138 | bsanchez | |
205 | 12154 | bsanchez | /*
|
206 | * (non-Javadoc)
|
||
207 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#setLayer(com.iver.cit.gvsig.fmap.layers.FLayer)
|
||
208 | */
|
||
209 | 10740 | nacho | public void setLayer(FLayer lyr) { |
210 | 12154 | bsanchez | if (lyr instanceof IRasterProperties) { |
211 | op = (IRasterProperties) lyr; |
||
212 | 10740 | nacho | 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 | 12138 | bsanchez | tControl.accept(); |
222 | 10740 | nacho | } |
223 | |||
224 | /*
|
||
225 | * (non-Javadoc)
|
||
226 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#apply()
|
||
227 | */
|
||
228 | public void apply() { |
||
229 | 12138 | bsanchez | tControl.apply(); |
230 | 10740 | nacho | } |
231 | |||
232 | /*
|
||
233 | * (non-Javadoc)
|
||
234 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#cancel()
|
||
235 | */
|
||
236 | public void cancel() { |
||
237 | 12138 | bsanchez | tControl.cancel(); |
238 | 10740 | nacho | } |
239 | |||
240 | /*
|
||
241 | * (non-Javadoc)
|
||
242 | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#getID()
|
||
243 | */
|
||
244 | public String getID() { |
||
245 | return id;
|
||
246 | } |
||
247 | 12138 | bsanchez | |
248 | 10740 | nacho | /*
|
249 | * (non-Javadoc)
|
||
250 | 12180 | bsanchez | * @see org.gvsig.rastertools.properties.dialog.IRegistrablePanel#selectTab(java.lang.String)
|
251 | 10740 | nacho | */
|
252 | 12180 | bsanchez | public void selectTab(String id) {} |
253 | 12154 | bsanchez | |
254 | /*
|
||
255 | * (non-Javadoc)
|
||
256 | 12180 | bsanchez | * @see org.gvsig.rastertools.properties.dialog.IResizable#setComponentSize(int, int)
|
257 | 12154 | bsanchez | */
|
258 | 12180 | bsanchez | public void setComponentSize(int w, int h) {} |
259 | 12154 | bsanchez | |
260 | /*
|
||
261 | * (non-Javadoc)
|
||
262 | 12180 | bsanchez | * @see org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueChanged(org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
|
263 | 12154 | bsanchez | */
|
264 | 12180 | bsanchez | 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 | 12138 | bsanchez | } |