svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / listener / LineProfileOptionsListener.java @ 19831
History | View | Annotate | Download (8.62 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 |
/**
|
44 |
* Clase que define el comportamiento para los eventos de un LineProfileOptionsPanel.
|
45 |
*
|
46 |
* @author aMu?oz (alejandro.munoz@uclm.es)
|
47 |
* @see LineProfileOptionsPanel
|
48 |
* @version 11/3/2008
|
49 |
*/
|
50 |
|
51 |
import java.awt.Color; |
52 |
import java.awt.event.ActionEvent; |
53 |
import java.awt.event.ActionListener; |
54 |
import java.util.ArrayList; |
55 |
import java.util.Iterator; |
56 |
|
57 |
import javax.swing.event.ListSelectionEvent; |
58 |
import javax.swing.event.ListSelectionListener; |
59 |
import javax.swing.event.TableModelEvent; |
60 |
import javax.swing.event.TableModelListener; |
61 |
import javax.swing.table.DefaultTableModel; |
62 |
|
63 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
64 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent; |
65 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener; |
66 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
67 |
import org.gvsig.gui.beans.table.models.IModel; |
68 |
import org.gvsig.raster.buffer.RasterBuffer; |
69 |
import org.gvsig.raster.grid.GridException; |
70 |
import org.gvsig.raster.grid.roi.ROI; |
71 |
import org.gvsig.remotesensing.profiles.gui.LineProfileOptionsPanel; |
72 |
|
73 |
import sun.rmi.runtime.GetThreadPoolAction; |
74 |
|
75 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
76 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
77 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
78 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
79 |
|
80 |
public class LineProfileOptionsListener implements ButtonsPanelListener, ActionListener, ListSelectionListener, TableModelListener { |
81 |
|
82 |
LineProfileOptionsPanel optionsPanel = null;
|
83 |
|
84 |
public LineProfileOptionsListener( LineProfileOptionsPanel optionsPanel){
|
85 |
this.optionsPanel= optionsPanel;
|
86 |
} |
87 |
|
88 |
|
89 |
public void actionPerformed(ActionEvent e) { |
90 |
if (e.getSource() == optionsPanel.getNewButton()){
|
91 |
try {
|
92 |
String roiName= ""; |
93 |
roiName = "Line" + String.valueOf(optionsPanel.getTable().getRowCount()); |
94 |
Object row [] = ((IModel)optionsPanel.getTable().getModel()).getNewLine(); |
95 |
row[0]= roiName;
|
96 |
((DefaultTableModel)optionsPanel.getTable().getModel()).addRow(row);
|
97 |
if (optionsPanel.getGrid()!=null){ |
98 |
ROI roi = new VectorialROI(optionsPanel.getGrid());
|
99 |
roi.setName(roiName); |
100 |
roi.setColor((Color)row[4]); |
101 |
optionsPanel.addROI(roi); |
102 |
} |
103 |
optionsPanel.getTable().setSelectedIndex(optionsPanel.getTable().getRowCount()-1);
|
104 |
} catch (NotInitializeException e1) {
|
105 |
e1.printStackTrace(); |
106 |
} |
107 |
optionsPanel.selectDrawRoiTool(); |
108 |
optionsPanel.getNewButton().setSelected(true);
|
109 |
optionsPanel.getDeleteButton().setSelected(false);
|
110 |
} |
111 |
|
112 |
|
113 |
// Cada vez que se elimina una roi
|
114 |
if (e.getSource() == optionsPanel.getDeleteButton()){
|
115 |
optionsPanel.getDeleteButton().setSelected(false);
|
116 |
try {
|
117 |
if (optionsPanel.getTable().getSelectedRows().length>0){ |
118 |
optionsPanel.getJPanelChart().cleanChart(); |
119 |
String className = (String)optionsPanel.getTable().getModel().getValueAt(optionsPanel.getTable().getSelectedRow(),0); |
120 |
optionsPanel.removeROI(className); |
121 |
((DefaultTableModel)optionsPanel.getTable().getModel()).removeRow(optionsPanel.getTable().getSelectedRow());
|
122 |
|
123 |
for (Iterator iter = optionsPanel.getROIs().iterator(); iter.hasNext();) { |
124 |
ROI roi =(VectorialROI) iter.next(); |
125 |
int nSeries = optionsPanel.getROIs().size();
|
126 |
int[][] series = new int[nSeries][roi.getValues()]; |
127 |
String[] names = new String[nSeries]; |
128 |
|
129 |
// Se establecen los colores de las graficas segun color de las rois
|
130 |
for(int iSerie = 0; iSerie < nSeries; iSerie++){ |
131 |
names[iSerie] = "Band " + (iSerie+1); |
132 |
roi.setBandToOperate(optionsPanel.getComboBands().getSelectedIndex()); |
133 |
roi=(VectorialROI) optionsPanel.getROIs().get(iSerie); |
134 |
series = new int[nSeries][roi.getValues()]; |
135 |
int k=0; |
136 |
|
137 |
if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
|
138 |
for (int i = 0; i < roi.getNX(); i++){ |
139 |
for (int j = 0; j < roi.getNY(); j++){ |
140 |
series[iSerie][k] = (int) roi.getCellValueAsByte(i,j);
|
141 |
k++; |
142 |
} |
143 |
} |
144 |
} |
145 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){ |
146 |
for (int i = 0; i < roi.getNX(); i++){ |
147 |
for (int j = 0; j < roi.getNY(); j++){ |
148 |
series[iSerie][k] = (int) roi.getCellValueAsShort(i,j);
|
149 |
k++; |
150 |
} |
151 |
} |
152 |
} |
153 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){ |
154 |
for (int i = 0; i < roi.getNX(); i++){ |
155 |
for (int j = 0; j < roi.getNY(); j++){ |
156 |
series[iSerie][k] = (int) roi.getCellValueAsInt(i,j);
|
157 |
k++; |
158 |
} |
159 |
} |
160 |
} |
161 |
} |
162 |
// Actualizacion del grafico
|
163 |
optionsPanel.UpdateChart(); |
164 |
optionsPanel.getJPanelChart().setNewChart(series, names); |
165 |
optionsPanel.updateUI(); |
166 |
} |
167 |
} |
168 |
} catch (NotInitializeException e2) {
|
169 |
e2.printStackTrace(); |
170 |
} catch (GridException e2) {
|
171 |
e2.printStackTrace(); |
172 |
} |
173 |
} |
174 |
} |
175 |
|
176 |
public void tableChanged(TableModelEvent e) { |
177 |
// Corregir segun cualsea definitivamente la columna asociada al color
|
178 |
if(e.getColumn()==4){ |
179 |
String roiName = (String)optionsPanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),0); |
180 |
ArrayList graphics = optionsPanel.getRoiGraphics(roiName);
|
181 |
if(optionsPanel.getMapControl()!=null){ |
182 |
GraphicLayer graphicLayer = optionsPanel.getMapControl().getMapContext().getGraphicsLayer(); |
183 |
ISymbol symbol = null;
|
184 |
Color color = (Color)optionsPanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),4); |
185 |
for (int i = 0; i< graphics.size(); i++){ |
186 |
symbol = SymbologyFactory.createDefaultSymbolByShapeType(((FGraphic)graphics.get(i)).getGeom().getGeometryType(), color); |
187 |
((FGraphic)graphics.get(i)).setIdSymbol(graphicLayer.addSymbol(symbol)); |
188 |
} |
189 |
optionsPanel.getROI(roiName).setColor(color); |
190 |
optionsPanel.getMapControl().drawGraphics(); |
191 |
} |
192 |
|
193 |
optionsPanel.UpdateChart(); |
194 |
} |
195 |
} |
196 |
|
197 |
public void valueChanged(ListSelectionEvent e) { |
198 |
|
199 |
|
200 |
try {
|
201 |
if(optionsPanel.getTable().getSelectedRow()!=-1){ |
202 |
|
203 |
ROI roi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow()); |
204 |
String[] names = new String[1]; |
205 |
names[0]="Serie0"; |
206 |
roi.setBandToOperate(optionsPanel.getComboBands().getSelectedIndex()); |
207 |
int[][] series = new int[1][roi.getValues()]; |
208 |
int k=0; |
209 |
|
210 |
if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
|
211 |
for (int i = 0; i < roi.getNX(); i++){ |
212 |
for (int j = 0; j < roi.getNY(); j++){ |
213 |
series[0][k] = (int) roi.getCellValueAsByte(i,j); |
214 |
k++; |
215 |
} |
216 |
} |
217 |
} |
218 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){ |
219 |
for (int i = 0; i < roi.getNX(); i++){ |
220 |
for (int j = 0; j < roi.getNY(); j++){ |
221 |
series[0][k] = (int) roi.getCellValueAsShort(i,j); |
222 |
k++; |
223 |
} |
224 |
} |
225 |
} |
226 |
else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){ |
227 |
for (int i = 0; i < roi.getNX(); i++){ |
228 |
for (int j = 0; j < roi.getNY(); j++){ |
229 |
series[0][k] = (int) roi.getCellValueAsInt(i,j); |
230 |
k++; |
231 |
} |
232 |
} |
233 |
} |
234 |
|
235 |
|
236 |
// Actualizacion del grafico
|
237 |
optionsPanel.getJPanelChart().getChart().getChart().getXYPlot().getRenderer().setSeriesPaint(0, roi.getColor());
|
238 |
optionsPanel.getJPanelChart().setNewChart(series, names); |
239 |
optionsPanel.updateUI(); |
240 |
} |
241 |
|
242 |
} catch (GridException e1) {
|
243 |
e1.printStackTrace(); |
244 |
} catch (NotInitializeException e3) {
|
245 |
|
246 |
e3.printStackTrace(); |
247 |
} |
248 |
|
249 |
} |
250 |
|
251 |
public void actionButtonPressed(ButtonsPanelEvent e) { |
252 |
// TODO Auto-generated method stub
|
253 |
|
254 |
} |
255 |
|
256 |
} |