svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / toc / WMSRasterPropsTocMenuEntry.java @ 4578
History | View | Annotate | Download (6.79 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.io.GeoRasterFile; |
49 |
import org.cresques.io.raster.RasterFilterStackManager; |
50 |
import org.cresques.px.PxRaster; |
51 |
import org.cresques.ui.raster.BandSetupPanel; |
52 |
import org.cresques.ui.raster.EnhancedPanel; |
53 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
54 |
import org.cresques.ui.raster.RasterTransparencyPanel; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
59 |
import com.iver.cit.gvsig.gui.dialogs.WMSRasterPropsDialog; |
60 |
|
61 |
/**
|
62 |
*
|
63 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
64 |
*/
|
65 |
public class WMSRasterPropsTocMenuEntry extends TocMenuEntry { |
66 |
private JMenuItem propsMenuItem; |
67 |
FLayer lyr = null;
|
68 |
private WMSRasterPropsDialog propsDialog = null; |
69 |
private BandSetupPanel bandSetup = null; |
70 |
|
71 |
public void initialize(FPopupMenu m) { |
72 |
super.initialize(m);
|
73 |
|
74 |
if (isTocItemBranch()) {
|
75 |
lyr = getNodeLayer(); |
76 |
// Opcciones para capas WCS
|
77 |
if ((lyr instanceof FLyrWMS)) { |
78 |
propsMenuItem = new JMenuItem(PluginServices.getText(this, "propiedades_raster")); |
79 |
getMenu().add( propsMenuItem ); |
80 |
propsMenuItem.setFont(FPopupMenu.theFont); |
81 |
getMenu().setEnabled(true);
|
82 |
//getMenu().addSeparator();
|
83 |
//Cambio color
|
84 |
propsMenuItem.addActionListener(this);
|
85 |
} |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* Selecciona las bandas activas en el panel de bandas a partir
|
91 |
* del los filtros contenidos en el FilterStack
|
92 |
* @param stackManager RasterFilterStackManager
|
93 |
* @param posR posici?n de la banda R en el selector
|
94 |
* @param posG posici?n de la banda G en el selector
|
95 |
* @param posB posici?n de la banda B en el selector
|
96 |
*/
|
97 |
private void bandSelector(RasterFilterStackManager stackManager, int posR, int posG, int posB){ |
98 |
ArrayList stackList = stackManager.getStringsFromStack();
|
99 |
String hideBands = null; |
100 |
for(int i=0;i<stackList.size();i++){ |
101 |
if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
102 |
hideBands = stackManager.getValue((String)stackList.get(i));
|
103 |
} |
104 |
|
105 |
//Selecci?n de 1, 2 o 3 bandas para visualizar
|
106 |
if(hideBands != null){ |
107 |
int pos = 2; |
108 |
if(hideBands.length() == 1) |
109 |
pos = 1;
|
110 |
else if(hideBands.length() == 2) |
111 |
pos = 0;
|
112 |
bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
113 |
|
114 |
//Reseteamos los controles de la tabla
|
115 |
|
116 |
for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
117 |
for(int j=0;j<3;j++) |
118 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
119 |
|
120 |
if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
121 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
122 |
|
123 |
if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
124 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
125 |
|
126 |
if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
127 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
128 |
} |
129 |
} |
130 |
|
131 |
/* (non-Javadoc)
|
132 |
* @see com.iver.cit.gvsig.gui.toc.TocMenuEntry#execute(com.iver.cit.gvsig.gui.toc.ITocItem)
|
133 |
*/
|
134 |
public void actionPerformed(ActionEvent e) { |
135 |
lyr = getNodeLayer(); |
136 |
|
137 |
if(lyr instanceof FLyrWMS && ((FLyrWMS)lyr).getPxRaster()!=null){ |
138 |
RasterFilterStackManager stackManager = null;
|
139 |
|
140 |
FLyrWMS layer = (FLyrWMS)lyr; |
141 |
|
142 |
stackManager = new RasterFilterStackManager(layer.getFilterStack());
|
143 |
|
144 |
propsDialog = new WMSRasterPropsDialog(layer, stackManager.getTransparencyRGB());
|
145 |
|
146 |
int alpha = layer.getPxRaster().getAlpha();
|
147 |
|
148 |
bandSetup = (BandSetupPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("BandSetupPanel");
|
149 |
GeoRasterFile[] files = layer.getPxRaster().getFiles();
|
150 |
bandSetup.addFiles(files); |
151 |
for(int i=0; i< files.length;i++) |
152 |
propsDialog.addNumBands(files[i].getBandCount()); |
153 |
|
154 |
PxRaster px = layer.getPxRaster(); |
155 |
int posR = 0, posG = 0, posB = 0; |
156 |
|
157 |
for(int i=0;i<px.getPosFile(GeoRasterFile.RED_BAND);i++) |
158 |
posR += files[i].getBandCount(); |
159 |
posR += px.getBand(GeoRasterFile.RED_BAND); |
160 |
|
161 |
for(int i=0;i<px.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
162 |
posG += files[i].getBandCount(); |
163 |
posG += px.getBand(GeoRasterFile.GREEN_BAND); |
164 |
|
165 |
for(int i=0;i<px.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
166 |
posB += files[i].getBandCount(); |
167 |
posB += px.getBand(GeoRasterFile.BLUE_BAND); |
168 |
|
169 |
|
170 |
bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
171 |
bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
172 |
bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
173 |
|
174 |
//Asignaci?n del alpha actual de la imagen al dialogo
|
175 |
RasterTransparencyPanel rasterTrans = (RasterTransparencyPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("RasterTransparencyPanel");
|
176 |
rasterTrans.setOpacity(alpha); |
177 |
|
178 |
//Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
|
179 |
EnhancedPanel pEnhan = (EnhancedPanel)((FilterRasterDialogPanel)propsDialog.getContentPane()).getPanelByClassName("EnhancedPanel");
|
180 |
|
181 |
propsDialog.setRasterFilterStackManager(stackManager); |
182 |
int tail = 0; |
183 |
if( pEnhan != null && |
184 |
stackManager.getStackStats() != null){
|
185 |
tail = (int)(stackManager.getStackStats().tailPercent*200); |
186 |
pEnhan.setPercentTail(tail); |
187 |
} |
188 |
if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))) |
189 |
pEnhan.setSelectedFilter(1);
|
190 |
else
|
191 |
pEnhan.setSelectedFilter(0);
|
192 |
|
193 |
bandSelector(stackManager, posR, posG, posB); |
194 |
|
195 |
propsDialog.readStat(); |
196 |
|
197 |
PluginServices.getMDIManager().addView(propsDialog); |
198 |
} |
199 |
} |
200 |
} |