svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / RasterVectorialControls.java @ 4377
History | View | Annotate | Download (8.39 KB)
1 |
/*
|
---|---|
2 |
* Created on 28-jul-2005
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig; |
48 |
|
49 |
import java.util.ArrayList; |
50 |
|
51 |
import org.apache.log4j.Logger; |
52 |
import org.cresques.io.GeoRasterFile; |
53 |
import org.cresques.io.raster.RasterFilterStackManager; |
54 |
import org.cresques.ui.raster.BandSetupPanel; |
55 |
import org.cresques.ui.raster.EnhancedPanel; |
56 |
import org.cresques.ui.raster.FilterRasterDialogPanel; |
57 |
import org.cresques.ui.raster.RasterTransparencyPanel; |
58 |
|
59 |
import com.iver.andami.PluginServices; |
60 |
import com.iver.andami.plugins.Extension; |
61 |
import com.iver.cit.gvsig.fmap.FMap; |
62 |
import com.iver.cit.gvsig.fmap.MapControl; |
63 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
66 |
import com.iver.cit.gvsig.fmap.layers.RasterAdapter; |
67 |
import com.iver.cit.gvsig.gui.View; |
68 |
import com.iver.cit.gvsig.gui.Panels.PropertiesRasterDialog; |
69 |
import com.iver.cit.gvsig.gui.thememanager.FThemeManagerWindow; |
70 |
import com.iver.cit.gvsig.project.ProjectView; |
71 |
|
72 |
|
73 |
/**
|
74 |
* Extensi?n de operaciones sobre capas raster y vectorial.
|
75 |
* El control es com?n y visible para ambos tipos de capa. Dependiendo de que
|
76 |
* sea una capa u otra la seleccionada se ejecutar? una acci?n u otra.
|
77 |
*
|
78 |
* @author Nacho brodin (brodin_ign@gva.es)
|
79 |
*/
|
80 |
public class RasterVectorialControls implements Extension { |
81 |
private static Logger logger = Logger.getLogger(ThemeControls.class.getName()); |
82 |
|
83 |
/**
|
84 |
* @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
|
85 |
*/
|
86 |
public void execute(String s) { |
87 |
View vista = (View) PluginServices.getMDIManager().getActiveView(); |
88 |
ProjectView model = vista.getModel(); |
89 |
FMap mapa = model.getMapContext(); |
90 |
MapControl mapCtrl = vista.getMapControl(); |
91 |
logger.debug("Comand : " + s);
|
92 |
|
93 |
FLayer[] selected = mapa.getLayers().getActives();
|
94 |
|
95 |
if (s.compareTo("PROPERTIES") == 0) { |
96 |
if(selected[0] instanceof FLyrVect) { |
97 |
FThemeManagerWindow fThemeManagerWindow = new FThemeManagerWindow(selected[0], mapa); |
98 |
PluginServices.getMDIManager().addView(fThemeManagerWindow); |
99 |
} else if(selected[0] instanceof FLyrRaster) { |
100 |
showRasterProperties((FLyrRaster)selected[0]);
|
101 |
} |
102 |
} |
103 |
} |
104 |
|
105 |
public void showRasterProperties(FLyrRaster lyr){ |
106 |
RasterFilterStackManager stackManager = null;
|
107 |
PropertiesRasterDialog propsDialog = null;
|
108 |
BandSetupPanel bandSetup = null;
|
109 |
|
110 |
stackManager = new RasterFilterStackManager(((FLyrRaster)lyr).getSource().getFilterStack());
|
111 |
|
112 |
propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), stackManager.getTransparencyRGB());
|
113 |
|
114 |
int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency(); |
115 |
|
116 |
bandSetup = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getBandSetup(); |
117 |
|
118 |
//Asignaci?n del alpha actual de la imagen al dialogo
|
119 |
RasterTransparencyPanel rasterTrans = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getTransparencyPanel(); |
120 |
rasterTrans.setOpacity(alpha); |
121 |
|
122 |
//Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
|
123 |
EnhancedPanel pEnhan = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getEnhancedPanel(); |
124 |
|
125 |
propsDialog.setRasterFilterStackManager(stackManager); |
126 |
|
127 |
ArrayList stackList = stackManager.getStringsFromStack();
|
128 |
boolean remove = false; |
129 |
String hideBands = null; |
130 |
for(int i=0;i<stackList.size();i++){ |
131 |
//System.out.println("*=>"+((String)stackList.get(i)));
|
132 |
if(((String)stackList.get(i)).startsWith("filter.tail.value")){ |
133 |
int tail = (int)(Double.parseDouble(stackManager.getValue((String)stackList.get(i)))*200); |
134 |
pEnhan.setPercentTail(tail); |
135 |
} |
136 |
if(((String)stackList.get(i)).startsWith("filter.tail.remove")) |
137 |
remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue(); |
138 |
|
139 |
if(((String)stackList.get(i)).startsWith("filter.enhanced.remove")) |
140 |
remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue(); |
141 |
|
142 |
if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
143 |
hideBands = stackManager.getValue((String)stackList.get(i));
|
144 |
} |
145 |
|
146 |
if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))){ |
147 |
if(remove)
|
148 |
pEnhan.setSelectedFilter(1);
|
149 |
else
|
150 |
pEnhan.setSelectedFilter(2);
|
151 |
}else
|
152 |
pEnhan.setSelectedFilter(0);
|
153 |
|
154 |
GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
|
155 |
bandSetup.addFiles(files); |
156 |
for(int i=0; i< files.length;i++) |
157 |
propsDialog.addNumBands(files[i].getBandCount()); |
158 |
|
159 |
RasterAdapter rad = ((FLyrRaster)lyr).getSource(); |
160 |
int posR = 0, posG = 0, posB = 0; |
161 |
|
162 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++) |
163 |
posR += files[i].getBandCount(); |
164 |
posR += rad.getBand(GeoRasterFile.RED_BAND); |
165 |
|
166 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
167 |
posG += files[i].getBandCount(); |
168 |
posG += rad.getBand(GeoRasterFile.GREEN_BAND); |
169 |
|
170 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
171 |
posB += files[i].getBandCount(); |
172 |
posB += rad.getBand(GeoRasterFile.BLUE_BAND); |
173 |
|
174 |
bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
175 |
bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
176 |
bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
177 |
|
178 |
//Selecci?n de 1, 2 o 3 bandas para visualizar
|
179 |
if(hideBands != null){ |
180 |
int pos = 2; |
181 |
if(hideBands.length() == 1) |
182 |
pos = 1;
|
183 |
else if(hideBands.length() == 2) |
184 |
pos = 0;
|
185 |
bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
186 |
|
187 |
//Reseteamos los controles de la tabla
|
188 |
|
189 |
for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
190 |
for(int j=0;j<3;j++) |
191 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
192 |
|
193 |
if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
194 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
195 |
|
196 |
if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
197 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
198 |
|
199 |
if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
200 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
201 |
} |
202 |
|
203 |
propsDialog.readStat(); |
204 |
|
205 |
PluginServices.getMDIManager().addView(propsDialog); |
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
210 |
*/
|
211 |
public boolean isVisible() { |
212 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
213 |
.getActiveView(); |
214 |
|
215 |
if (f == null) { |
216 |
return false; |
217 |
} |
218 |
|
219 |
if (f.getClass() == View.class) { |
220 |
FMap mapa = ((View) f).getModel().getMapContext();
|
221 |
|
222 |
return mapa.getLayers().getLayersCount() > 0; |
223 |
} else {
|
224 |
return false; |
225 |
} |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
230 |
*/
|
231 |
public boolean isEnabled() { |
232 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
233 |
|
234 |
if (f == null) { |
235 |
return false; |
236 |
} |
237 |
|
238 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
239 |
if ( selected.length == 1 && |
240 |
(selected[0] instanceof FLyrVect || |
241 |
selected[0] instanceof FLyrRaster)){ |
242 |
return true; |
243 |
} |
244 |
return false; |
245 |
} |
246 |
|
247 |
/**
|
248 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
249 |
*/
|
250 |
public void inicializar() { |
251 |
} |
252 |
} |