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