svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / listener / DrawMouseProfileListener.java @ 20309
History | View | Annotate | Download (11.4 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 Instituto de Desarrollo Regional 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 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.profiles.listener; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Cursor; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.util.ArrayList; |
47 |
import java.util.Iterator; |
48 |
|
49 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
50 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
51 |
import org.gvsig.raster.buffer.RasterBuffer; |
52 |
import org.gvsig.raster.grid.GridException; |
53 |
import org.gvsig.raster.util.RasterToolsUtil; |
54 |
import org.gvsig.remotesensing.profiles.gui.ProfilePanel; |
55 |
|
56 |
import com.iver.andami.PluginServices; |
57 |
import com.iver.cit.gvsig.fmap.core.FShape; |
58 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
59 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
60 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
61 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
62 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
63 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
64 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
65 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
66 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
67 |
import com.iver.cit.gvsig.fmap.tools.BehaviorException; |
68 |
import com.iver.cit.gvsig.fmap.tools.Events.MeasureEvent; |
69 |
import com.iver.cit.gvsig.fmap.tools.Events.PointEvent; |
70 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener; |
71 |
import com.iver.cit.gvsig.fmap.tools.Listeners.PolylineListener; |
72 |
|
73 |
/**
|
74 |
* Clase que define el comportamiento tras los eventos de dibujado sobre la imagen.
|
75 |
* Se encarga del pintado de la grafica asociada a la geometria (punto o linea) dibujada.
|
76 |
*
|
77 |
* @author aMu?oz (alejandro.munoz@uclm.es)
|
78 |
* @version 11/3/2008
|
79 |
*/
|
80 |
|
81 |
public class DrawMouseProfileListener implements PolylineListener,PointListener { |
82 |
|
83 |
private ProfilePanel panel = null; |
84 |
|
85 |
/**
|
86 |
* Constructor
|
87 |
* @param panel principal de perfiles
|
88 |
* */
|
89 |
public DrawMouseProfileListener(ProfilePanel panel) {
|
90 |
this.panel= panel;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* Eventos tras el dibujado de una linea. Se pinta la geometria dibujada en la vista y se genera el
|
95 |
* gr?fico asociado.
|
96 |
* */
|
97 |
public void polylineFinished(MeasureEvent event) throws BehaviorException { |
98 |
|
99 |
GeneralPathX gp = event.getGP(); |
100 |
IGeometry geometry = null;
|
101 |
geometry = ShapeFactory.createPolyline2D(gp); |
102 |
String roiName = ""; |
103 |
VectorialROI lineRoi= null;
|
104 |
int selectedRow;
|
105 |
|
106 |
try {
|
107 |
selectedRow = panel.getLineOptionsPanel().getTable().getSelectedRow(); |
108 |
roiName = (String)panel.getLineOptionsPanel().getTable().getModel().getValueAt(selectedRow,0); |
109 |
lineRoi = (VectorialROI)panel.getLineOptionsPanel().getROI(roiName); |
110 |
|
111 |
// Si hay una roi con mas de una geometria no se hace nada.
|
112 |
if(lineRoi.getGeometries().size()>0) |
113 |
return;
|
114 |
|
115 |
else {
|
116 |
lineRoi.addGeometry(geometry); |
117 |
panel.getLineOptionsPanel().addROI(lineRoi); |
118 |
ISymbol sym = null;
|
119 |
Color geometryColor = (Color)panel.getLineOptionsPanel().getTable().getModel().getValueAt(selectedRow, 1); |
120 |
sym =SymbologyFactory.createDefaultLineSymbol(); |
121 |
((ILineSymbol)sym).setLineColor(geometryColor); |
122 |
|
123 |
GraphicLayer graphicLayer = panel.getLineOptionsPanel().getMapControl().getMapContext().getGraphicsLayer(); |
124 |
FGraphic fGraphic = new FGraphic(geometry,graphicLayer.addSymbol(sym));
|
125 |
panel.getLineOptionsPanel().getMapControl().getMapContext().getGraphicsLayer().addGraphic(fGraphic); |
126 |
panel.getLineOptionsPanel().getRoiGraphics(roiName).add(fGraphic); |
127 |
panel.getLineOptionsPanel().getMapControl().drawGraphics(); |
128 |
panel.getLineOptionsPanel().getNewButton().setSelected(false);
|
129 |
panel.getMapControl().setTool(panel.getLineOptionsPanel().getPreviousTool()); |
130 |
// Se pinta el grafico asociado
|
131 |
drawChartRoi(lineRoi,panel.getLineOptionsPanel().getComboBands().getSelectedIndex()); |
132 |
} |
133 |
} catch (NotInitializeException e) {
|
134 |
RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e); |
135 |
} |
136 |
} |
137 |
|
138 |
/**
|
139 |
* @return cursor asociado al panel activo
|
140 |
* */
|
141 |
public Cursor getCursor() { |
142 |
if(panel.getPointOptionsPanel().getNextActive()==ProfilePanel.PANELZPROFILE)
|
143 |
return panel.getLineOptionsPanel().getToolCursor();
|
144 |
else
|
145 |
return panel.getPointOptionsPanel().getToolCursor();
|
146 |
} |
147 |
|
148 |
|
149 |
/**
|
150 |
* Eventos tras el dibujado de un punto. Se a?ade el punto a la roi activa del panel.
|
151 |
* Si esta roi tiene alguna geometria, se elimina.
|
152 |
* */
|
153 |
public void point(PointEvent event) throws BehaviorException { |
154 |
|
155 |
Point2D point = event.getPoint();
|
156 |
Point2D p= panel.getPointOptionsPanel().getMapControl().getViewPort().toMapPoint(point);
|
157 |
IGeometry geometry = ShapeFactory.createPoint2D(p.getX(),p.getY()); |
158 |
VectorialROI pointRoi= null;
|
159 |
String roiName = ""; |
160 |
int selectedRow;
|
161 |
try {
|
162 |
|
163 |
selectedRow = panel.getPointOptionsPanel().getTable().getSelectedRow(); |
164 |
panel.getPointOptionsPanel().getTable().getModel().setValueAt(new Double(p.getX()), selectedRow, 2); |
165 |
panel.getPointOptionsPanel().getTable().getModel().setValueAt(new Double(p.getY()), selectedRow, 3); |
166 |
roiName = (String)panel.getPointOptionsPanel().getTable().getModel().getValueAt(selectedRow,0); |
167 |
pointRoi =(VectorialROI)panel.getPointOptionsPanel().getRois().get(roiName); |
168 |
pointRoi.clear(); |
169 |
pointRoi.addGeometry(geometry); |
170 |
panel.getPointOptionsPanel().addROI(pointRoi); |
171 |
// Actualizaci?n del gr?fico
|
172 |
drawChartAllPointsRois(); |
173 |
panel.getPointOptionsPanel().getNewButton().setSelected(false);
|
174 |
panel.getMapControl().setTool(panel.getPointOptionsPanel().getPreviousTool()); |
175 |
} catch (NotInitializeException e) {
|
176 |
RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e); |
177 |
} |
178 |
} |
179 |
|
180 |
|
181 |
/**
|
182 |
* Metodo que se encarga de pintar la roi de tipo linea que se pasa como parametro sobre el grafico.
|
183 |
* La vanda de la que se tomar?n los valores es la que se pasa como par?metro.
|
184 |
* */
|
185 |
private void drawChartRoi(VectorialROI roi, int band){ |
186 |
|
187 |
try {
|
188 |
int[][] series; |
189 |
series = new int[1][roi.getValues()]; |
190 |
String[] names = new String[1]; |
191 |
names[0] = "Grafico"; |
192 |
roi.setBandToOperate(band); |
193 |
series = new int[1][roi.getValues()]; |
194 |
int k=0; |
195 |
int z=0; |
196 |
if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
|
197 |
for (int i = 0; i < roi.getNX(); i++){ |
198 |
for (int j = 0; j < roi.getNY(); j++){ |
199 |
z= (int) roi.getCellValueAsByte(i,j);
|
200 |
if(!roi.isNoDataValue(z)){
|
201 |
series[0][k] =z;
|
202 |
k++; |
203 |
} |
204 |
} |
205 |
} |
206 |
} |
207 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){ |
208 |
for (int i = 0; i < roi.getNX(); i++){ |
209 |
for (int j = 0; j < roi.getNY(); j++){ |
210 |
z= (int) roi.getCellValueAsShort(i,j);
|
211 |
if(!roi.isNoDataValue(z)){
|
212 |
series[0][k] =z;
|
213 |
k++; |
214 |
} |
215 |
} |
216 |
} |
217 |
} |
218 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){ |
219 |
for (int i = 0; i < roi.getNX(); i++){ |
220 |
for (int j = 0; j < roi.getNY(); j++){ |
221 |
z= (int) roi.getCellValueAsInt(i,j);
|
222 |
if(!roi.isNoDataValue(z)){
|
223 |
series[0][k] =z;
|
224 |
k++; |
225 |
} |
226 |
} |
227 |
} |
228 |
} |
229 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_FLOAT){ |
230 |
for (int i = 0; i < roi.getNX(); i++){ |
231 |
for (int j = 0; j < roi.getNY(); j++){ |
232 |
z= (int) roi.getCellValueAsFloat(i,j);
|
233 |
if(!roi.isNoDataValue(z)){
|
234 |
series[0][k] =z;
|
235 |
k++; |
236 |
} |
237 |
} |
238 |
} |
239 |
} |
240 |
// Actualizacion del grafico
|
241 |
panel.getLineOptionsPanel().SetColorSeriesChart(); |
242 |
panel.getLineOptionsPanel().getJPanelChart().setNewChart(series, names); |
243 |
panel.getLineOptionsPanel().updateUI(); |
244 |
int selectedRow = panel.getLineOptionsPanel().getTable().getSelectedRow();
|
245 |
roi.setBandToOperate(band); |
246 |
double max=roi.getMaxValue();
|
247 |
double min= roi.getMinValue();
|
248 |
double mean = roi.getMeanValue();
|
249 |
panel.getLineOptionsPanel().getTable().getModel().setValueAt(new Double(max), selectedRow, 2); |
250 |
panel.getLineOptionsPanel().getTable().getModel().setValueAt(new Double(min), selectedRow, 3); |
251 |
panel.getLineOptionsPanel().getTable().getModel().setValueAt(new Double(mean), selectedRow, 4); |
252 |
|
253 |
} catch (GridException e) {
|
254 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "grid_error"), this, e); |
255 |
} catch (NotInitializeException e) {
|
256 |
RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e); |
257 |
} |
258 |
} |
259 |
|
260 |
/**
|
261 |
* M?todo que realiza el repintado del grafico con todas las rois la tabla del panel zprofile.
|
262 |
* */
|
263 |
private void drawChartAllPointsRois(){ |
264 |
|
265 |
ISymbol symbol = null;
|
266 |
FGraphic fGraphic = null;
|
267 |
IGeometry geometry=null;
|
268 |
ArrayList roisArray =panel.getPointOptionsPanel().getROIs();
|
269 |
GraphicLayer graphicLayer = panel.getPointOptionsPanel().getMapControl().getMapContext().getGraphicsLayer(); |
270 |
VectorialROI pointRoi=null;
|
271 |
|
272 |
for (Iterator iter = roisArray.iterator(); iter.hasNext();) { |
273 |
pointRoi= (VectorialROI)iter.next();; |
274 |
for (Iterator iterator = pointRoi.getGeometries() |
275 |
.iterator(); iterator.hasNext();) { |
276 |
geometry = (IGeometry) iterator.next(); |
277 |
switch (geometry.getGeometryType()) {
|
278 |
case FShape.POINT:
|
279 |
symbol = SymbologyFactory.createDefaultMarkerSymbol(); |
280 |
((IMarkerSymbol) symbol).setColor(pointRoi.getColor()); |
281 |
break;
|
282 |
} |
283 |
fGraphic = new FGraphic(geometry, graphicLayer
|
284 |
.addSymbol(symbol)); |
285 |
graphicLayer.addGraphic(fGraphic); |
286 |
panel.getPointOptionsPanel().getRoiGraphics(pointRoi.getName()).add(fGraphic); |
287 |
} |
288 |
} |
289 |
panel.getPointOptionsPanel().getMapControl().drawGraphics(); |
290 |
|
291 |
int nSeries = panel.getPointOptionsPanel().getROIs().size();
|
292 |
int[][] series = new int[nSeries][pointRoi.getBandCount()+1]; |
293 |
String[] names = new String[nSeries]; |
294 |
|
295 |
// Se establecen los colores de las graficas segun color de las rois
|
296 |
for(int iSerie = 0; iSerie < nSeries; iSerie++){ |
297 |
series[iSerie][0] = 0; |
298 |
names[iSerie] = "Band " + (iSerie+1); |
299 |
pointRoi=(VectorialROI) panel.getPointOptionsPanel().getROIs().get(iSerie); |
300 |
try {
|
301 |
for (int i = 1; i <= pointRoi.getBandCount(); i++){ |
302 |
pointRoi.setBandToOperate(i-1);
|
303 |
series[iSerie][i] = (int) pointRoi.getMeanValue();
|
304 |
} |
305 |
} catch (GridException e) {
|
306 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "grid_error"), this, e); |
307 |
} |
308 |
} |
309 |
panel.getPointOptionsPanel().UpdateChart(); |
310 |
panel.getPointOptionsPanel().getJPanelChart().setNewChart(series, names); |
311 |
} |
312 |
|
313 |
|
314 |
public boolean cancelDrawing() { |
315 |
return true; |
316 |
} |
317 |
|
318 |
public void pointFixed(MeasureEvent event) throws BehaviorException { |
319 |
} |
320 |
|
321 |
public void points(MeasureEvent event) throws BehaviorException { |
322 |
} |
323 |
|
324 |
public void pointDoubleClick(PointEvent event) throws BehaviorException { |
325 |
} |
326 |
} |