root / branches / gvSIG_CAD / applications / appgvSIG / src / com / iver / cit / gvsig / RasterVectorialControls.java @ 3513
History | View | Annotate | Download (8.58 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().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 |
int[][] rangeR = stackManager.getTransparecyR(); |
113 |
int[][] rangeG = stackManager.getTransparecyG(); |
114 |
int[][] rangeB = stackManager.getTransparecyB(); |
115 |
|
116 |
propsDialog = new PropertiesRasterDialog(((FLyrRaster)lyr), rangeR, rangeG, rangeB);
|
117 |
|
118 |
int alpha = 255-((FLyrRaster)lyr).getSource().getTransparency(); |
119 |
|
120 |
bandSetup = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getBandSetup(); |
121 |
|
122 |
//Asignaci?n del alpha actual de la imagen al dialogo
|
123 |
RasterTransparencyPanel rasterTrans = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getTransparencyPanel(); |
124 |
rasterTrans.setOpacity(alpha); |
125 |
|
126 |
//Asignaci?n del porcentaje de recorte actual de la imagen al dialogo
|
127 |
EnhancedPanel pEnhan = ((FilterRasterDialogPanel)propsDialog.getContentPane()).getEnhancedPanel(); |
128 |
|
129 |
propsDialog.setRasterFilterStackManager(stackManager); |
130 |
|
131 |
ArrayList stackList = stackManager.getStringsFromStack();
|
132 |
boolean remove = false; |
133 |
String hideBands = null; |
134 |
for(int i=0;i<stackList.size();i++){ |
135 |
//System.out.println("*=>"+((String)stackList.get(i)));
|
136 |
if(((String)stackList.get(i)).startsWith("filter.tail.value")){ |
137 |
int tail = (int)(Double.parseDouble(stackManager.getValue((String)stackList.get(i)))*200); |
138 |
pEnhan.setPercentTail(tail); |
139 |
} |
140 |
if(((String)stackList.get(i)).startsWith("filter.tail.remove")) |
141 |
remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue(); |
142 |
|
143 |
if(((String)stackList.get(i)).startsWith("filter.enhanced.remove")) |
144 |
remove = Boolean.valueOf(stackManager.getValue((String)stackList.get(i))).booleanValue(); |
145 |
|
146 |
if(((String)stackList.get(i)).startsWith("filter.removebands.bands")) |
147 |
hideBands = stackManager.getValue((String)stackList.get(i));
|
148 |
} |
149 |
|
150 |
if(stackManager.isActive(stackManager.getTypeFilter("enhanced"))){ |
151 |
if(remove)
|
152 |
pEnhan.setSelectedFilter(1);
|
153 |
else
|
154 |
pEnhan.setSelectedFilter(2);
|
155 |
}else
|
156 |
pEnhan.setSelectedFilter(0);
|
157 |
|
158 |
GeoRasterFile[] files = ((FLyrRaster)lyr).getSource().getFiles();
|
159 |
bandSetup.addFiles(files); |
160 |
for(int i=0; i< files.length;i++) |
161 |
propsDialog.addNumBands(files[i].getBandCount()); |
162 |
|
163 |
RasterAdapter rad = ((FLyrRaster)lyr).getSource(); |
164 |
int posR = 0, posG = 0, posB = 0; |
165 |
|
166 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.RED_BAND);i++) |
167 |
posR += files[i].getBandCount(); |
168 |
posR += rad.getBand(GeoRasterFile.RED_BAND); |
169 |
|
170 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.GREEN_BAND);i++) |
171 |
posG += files[i].getBandCount(); |
172 |
posG += rad.getBand(GeoRasterFile.GREEN_BAND); |
173 |
|
174 |
for(int i=0;i<rad.getPosFile(GeoRasterFile.BLUE_BAND);i++) |
175 |
posB += files[i].getBandCount(); |
176 |
posB += rad.getBand(GeoRasterFile.BLUE_BAND); |
177 |
|
178 |
bandSetup.assignBand(posR, GeoRasterFile.RED_BAND); |
179 |
bandSetup.assignBand(posG, GeoRasterFile.GREEN_BAND); |
180 |
bandSetup.assignBand(posB, GeoRasterFile.BLUE_BAND); |
181 |
|
182 |
//Selecci?n de 1, 2 o 3 bandas para visualizar
|
183 |
if(hideBands != null){ |
184 |
int pos = 2; |
185 |
if(hideBands.length() == 1) |
186 |
pos = 1;
|
187 |
else if(hideBands.length() == 2) |
188 |
pos = 0;
|
189 |
bandSetup.getFileList().getJComboBox().setSelectedIndex(pos); |
190 |
|
191 |
//Reseteamos los controles de la tabla
|
192 |
|
193 |
for(int i=0;i<bandSetup.getRGBTable().getModel().getRowCount();i++) |
194 |
for(int j=0;j<3;j++) |
195 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(false), i, j); |
196 |
|
197 |
if(hideBands.equals("GB") || hideBands.equals("G") || hideBands.equals("B") ) |
198 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posR, 0); |
199 |
|
200 |
if(hideBands.equals("RB") || hideBands.equals("R") || hideBands.equals("B") ) |
201 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posG, 1); |
202 |
|
203 |
if(hideBands.equals("RG") || hideBands.equals("R") || hideBands.equals("G") ) |
204 |
bandSetup.getRGBTable().getModel().setValueAt(new Boolean(true), posB, 2); |
205 |
} |
206 |
|
207 |
propsDialog.readStat(); |
208 |
|
209 |
PluginServices.getMDIManager().addView(propsDialog); |
210 |
} |
211 |
|
212 |
/**
|
213 |
* @see com.iver.mdiApp.plugins.Extension#isVisible()
|
214 |
*/
|
215 |
public boolean isVisible() { |
216 |
com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager() |
217 |
.getActiveView(); |
218 |
|
219 |
if (f == null) { |
220 |
return false; |
221 |
} |
222 |
|
223 |
if (f.getClass() == View.class) { |
224 |
FMap mapa = ((View) f).getModel().getMapContext();
|
225 |
|
226 |
return mapa.getLayers().getLayersCount() > 0; |
227 |
} else {
|
228 |
return false; |
229 |
} |
230 |
} |
231 |
|
232 |
/**
|
233 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
234 |
*/
|
235 |
public boolean isEnabled() { |
236 |
View f = (View) PluginServices.getMDIManager().getActiveView(); |
237 |
|
238 |
if (f == null) { |
239 |
return false; |
240 |
} |
241 |
|
242 |
FLayer[] selected = f.getModel().getMapContext().getLayers().getActives();
|
243 |
if ( selected.length == 1 && |
244 |
(selected[0] instanceof FLyrVect || |
245 |
selected[0] instanceof FLyrRaster)){ |
246 |
return true; |
247 |
} |
248 |
return false; |
249 |
} |
250 |
|
251 |
/**
|
252 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
253 |
*/
|
254 |
public void inicializar() { |
255 |
} |
256 |
} |