svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / toc / WMSRasterPropsTocMenuEntry.java @ 6880
History | View | Annotate | Download (8.96 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.toc; |
42 |
|
43 |
import java.awt.event.ActionEvent; |
44 |
import java.util.ArrayList; |
45 |
|
46 |
import javax.swing.JMenuItem; |
47 |
|
48 |
import org.cresques.filter.RasterFilter; |
49 |
import org.cresques.filter.RasterFilterStackManager; |
50 |
import org.cresques.io.GeoRasterFile; |
51 |
import org.cresques.px.PxRaster; |
52 |
import org.cresques.ui.BrightnessContrast.EnhancedBrightnessContrastPanel; |
53 |
import org.cresques.ui.raster.BandSetupPanel; |
54 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
55 |
import org.cresques.ui.raster.InfoPanel; |
56 |
import org.cresques.ui.raster.RasterTransparencyPanel; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
62 |
import com.iver.cit.gvsig.gui.dialogs.WMSRasterPropsDialog; |
63 |
|
64 |
/**
|
65 |
*
|
66 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
67 |
*/
|
68 |
public class WMSRasterPropsTocMenuEntry extends TocMenuEntry { |
69 |
private JMenuItem propsMenuItem; |
70 |
FLayer lyr = null;
|
71 |
private WMSRasterPropsDialog propsDialog = null; |
72 |
private BandSetupPanel bandSetup = null; |
73 |
|
74 |
public void initialize(FPopupMenu m) { |
75 |
super.initialize(m);
|
76 |
|
77 |
if (isTocItemBranch()) {
|
78 |
lyr = getNodeLayer(); |
79 |
// Opcciones para capas WCS
|
80 |
if ((lyr instanceof FLyrWMS)) { |
81 |
propsMenuItem = new JMenuItem(PluginServices.getText(this, "propiedades_raster")); |
82 |
getMenu().add( propsMenuItem ); |
83 |
propsMenuItem.setFont(FPopupMenu.theFont); |
84 |
getMenu().setEnabled(true);
|
85 |
//getMenu().addSeparator();
|
86 |
//Cambio color
|
87 |
propsMenuItem.addActionListener(this);
|
88 |
} |
89 |
} |
90 |
} |
91 |
|
92 |
/**
|
93 |
* Selecciona las bandas activas en el panel de bandas a partir
|
94 |
* del los filtros contenidos en el FilterStack
|
95 |
* @param stackManager RasterFilterStackManager
|
96 |
* @param posR posici?n de la banda R en el selector
|
97 |
* @param posG posici?n de la banda G en el selector
|
98 |
* @param posB posici?n de la banda B en el selector
|
99 |
*/
|
100 |
private void bandSelector(RasterFilterStackManager stackManager, int posR, int posG, int posB){ |
101 |
ArrayList stackList = stackManager.getStringsFromStack();
|
102 |
String hideBands = null; |
103 |
for(int i=0;i<stackList.size();i++){ |
104 |
if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
105 |
hideBands = stackManager.getValue((String)stackList.get(i));
|
106 |
} |
107 |
|
108 |
//Selecci?n de 1, 2 o 3 bandas para visualizar
|
109 |
if(hideBands != null){ |
110 |
int pos = 2; |
111 |
if(hideBands.length() == 1) |
112 |
pos = 1;
|
113 |
else if(hideBands.length() == 2) |
114 |
pos = 0;
|
115 |
bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
116 |
|
117 |
//Reseteamos los controles de la tabla
|
118 |
|
119 |
for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
120 |
for(int j=0;j<3;j++) |
121 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
122 |
|
123 |
if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
124 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
125 |
|
126 |
if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
127 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
128 |
|
129 |
if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
130 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
131 |
} |
132 |
} |
133 |
|
134 |
/* (non-Javadoc)
|
135 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
136 |
*/
|
137 |
public void actionPerformed(ActionEvent e) { |
138 |
lyr = getNodeLayer(); |
139 |
|
140 |
if(lyr instanceof FLyrWMS && ((FLyrWMS)lyr).getPxRaster()!=null){ |
141 |
RasterFilterStackManager stackManager = null;
|
142 |
|
143 |
FLyrWMS layer = (FLyrWMS)lyr; |
144 |
|
145 |
stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
146 |
|
147 |
propsDialog = new WMSRasterPropsDialog(layer, stackManager.getTransparencyRGB());
|
148 |
|
149 |
int alpha = layer.getPxRaster().getAlpha();
|
150 |
|
151 |
bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("BandSetupPanel");
|
152 |
GeoRasterFile[] files = layer.getPxRaster().getFiles();
|
153 |
bandSetup.addFiles(files); |
154 |
for(int i=0; i< files.length;i++) |
155 |
propsDialog.addNumBands(files[i].getBandCount()); |
156 |
|
157 |
PxRaster px = layer.getPxRaster(); |
158 |
int posR = 0, posG = 0, posB = 0; |
159 |
|
160 |
for(int i=0;i<px.getPosFile(GeoRasterFile.RED_BAND);i++) |
161 |
posR += files[i].getBandCount(); |
162 |
posR += px.getBand(GeoRasterFile.RED_BAND); |
163 |
|
164 |
for(int i=0;i<px.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
165 |
posG += files[i].getBandCount(); |
166 |
posG += px.getBand(GeoRasterFile.GREEN_BAND); |
167 |
|
168 |
for(int i=0;i<px.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
169 |
posB += files[i].getBandCount(); |
170 |
posB += px.getBand(GeoRasterFile.BLUE_BAND); |
171 |
|
172 |
|
173 |
bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
174 |
bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
175 |
bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
176 |
|
177 |
InfoPanel pInfo = (InfoPanel)this.propsDialog.getPanelByClassName("InfoPanel"); |
178 |
pInfo.setBands(posR, posG, posB); |
179 |
pInfo.addFiles(files); |
180 |
|
181 |
//Asignaci?n del alpha actual de la imagen al dialogo
|
182 |
RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("RasterTransparencyPanel");
|
183 |
rasterTrans.setOpacity(alpha); |
184 |
|
185 |
propsDialog.setRasterFilterStackManager(stackManager); |
186 |
bandSelector(stackManager, posR, posG, posB); |
187 |
propsDialog.readStat(); |
188 |
actionPerformed(stackManager, propsDialog, null);
|
189 |
|
190 |
PluginServices.getMDIManager().addWindow(propsDialog); |
191 |
} |
192 |
} |
193 |
|
194 |
/**
|
195 |
* Modificaci?n del estado de los controles del panel de brillo y contraste
|
196 |
*/
|
197 |
public void actionPerformed(RasterFilterStackManager stackManager, WMSRasterPropsDialog propsDialog, FLyrRaster fLayer) { |
198 |
EnhancedBrightnessContrastPanel bcPanel = (EnhancedBrightnessContrastPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("EnhancedBrightnessContrastPanel");
|
199 |
//bcPanel.setPropertiesDialog(propsDialog);
|
200 |
|
201 |
if(stackManager.isActive(stackManager.getTypeFilter("brightness"))){ |
202 |
bcPanel.getCBrightC().setSelected(true);
|
203 |
bcPanel.setBCControlEnabled(true);
|
204 |
|
205 |
RasterFilter bright = stackManager.getFilter("brightness");
|
206 |
|
207 |
if(bright.getParam("incrBrillo") != null){ |
208 |
int incr = ((Integer)bright.getParam("incrBrillo")).intValue(); |
209 |
bcPanel.getLabelSliderText().setSliderValue(incr); |
210 |
bcPanel.getLabelSliderText().setTextValue(String.valueOf(incr));
|
211 |
} |
212 |
} |
213 |
|
214 |
if(stackManager.isActive(stackManager.getTypeFilter("contrast"))){ |
215 |
bcPanel.getCBrightC().setSelected(true);
|
216 |
bcPanel.setBCControlEnabled(true);
|
217 |
|
218 |
RasterFilter cont = stackManager.getFilter("contrast");
|
219 |
|
220 |
if(cont.getParam("incrContraste") != null){ |
221 |
int incr = ((Integer)cont.getParam("incrContraste")).intValue(); |
222 |
bcPanel.getLabelSliderText1().setSliderValue(incr); |
223 |
bcPanel.getLabelSliderText1().setTextValue(String.valueOf(incr));
|
224 |
} |
225 |
} |
226 |
|
227 |
if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))){ |
228 |
bcPanel.getCEnhanced().setSelected(true);
|
229 |
bcPanel.setEControlEnabled(true);
|
230 |
|
231 |
RasterFilter enhan = stackManager.getFilter("enhanced");
|
232 |
RasterFilter tail = stackManager.getFilter("tail");
|
233 |
|
234 |
|
235 |
boolean rem = ((Boolean)enhan.getParam("remove")).booleanValue(); |
236 |
bcPanel.getJCheckBox().setSelected(rem); |
237 |
|
238 |
if(stackManager.isActive(stackManager.getTypeFilter("tail"))){ |
239 |
double percent = (stackManager.getStackStats().tailPercent)*100; |
240 |
bcPanel.getCheckSliderText().setTextValue(String.valueOf(percent));
|
241 |
bcPanel.getCheckSliderText().setSliderValue((int)percent);
|
242 |
bcPanel.getCheckSliderText().setSelected(true);
|
243 |
bcPanel.getCheckSliderText().setControlEnabled(true);
|
244 |
boolean remove = ((Boolean)tail.getParam("remove")).booleanValue(); |
245 |
if((remove == true) || (rem == true)) |
246 |
bcPanel.getJCheckBox().setSelected(true);
|
247 |
else
|
248 |
bcPanel.getJCheckBox().setSelected(false);
|
249 |
|
250 |
} |
251 |
} |
252 |
} |
253 |
} |