Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / profiles / listener / LineProfileOptionsListener.java @ 26348

History | View | Annotate | Download (9.89 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

    
55
import javax.swing.event.ListSelectionEvent;
56
import javax.swing.event.ListSelectionListener;
57
import javax.swing.event.TableModelEvent;
58
import javax.swing.event.TableModelListener;
59
import javax.swing.table.DefaultTableModel;
60

    
61
import org.gvsig.fmap.raster.grid.roi.VectorialROI;
62
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelEvent;
63
import org.gvsig.gui.beans.buttonspanel.ButtonsPanelListener;
64
import org.gvsig.gui.beans.table.exceptions.NotInitializeException;
65
import org.gvsig.gui.beans.table.models.IModel;
66
import org.gvsig.raster.buffer.RasterBuffer;
67
import org.gvsig.raster.grid.GridException;
68
import org.gvsig.raster.grid.roi.ROI;
69
import org.gvsig.raster.util.RasterToolsUtil;
70
import org.gvsig.remotesensing.profiles.gui.LineProfileOptionsPanel;
71

    
72
import com.iver.andami.PluginServices;
73

    
74
public class LineProfileOptionsListener implements ButtonsPanelListener, ActionListener, ListSelectionListener, TableModelListener  {
75

    
76
        LineProfileOptionsPanel optionsPanel = null;
77
        int createRois =0;
78
        private boolean delete= false;
79
        
80
        /**
81
         * Constructor 
82
         * */
83
        public LineProfileOptionsListener( LineProfileOptionsPanel optionsPanel){
84
                this.optionsPanel= optionsPanel;
85
    
86
        }
87
        
88
        
89
        public void actionPerformed(ActionEvent e) {
90
                
91
                // Acciones a ejecutar cuando se crea una nueva entrada en la tabla
92
                // Construccion de la roi (vacia) que espera el dibujado de la geometria de tipo punto 
93
                // selecci?n de la herramienta de dibujado de point
94
                
95
                if (e.getSource() == optionsPanel.getNewButton()){
96
                        try {
97
                                String roiName = PluginServices.getText(this,"line") + String.valueOf(createRois);
98
                                createRois++;
99
                                Object row [] = ((IModel)optionsPanel.getTable().getModel()).getNewLine();
100
                                row[0]= roiName;
101
                                ((DefaultTableModel)optionsPanel.getTable().getModel()).addRow(row);
102
                                
103
                                if (optionsPanel.getGrid()!=null){
104
                                        ROI roi = new VectorialROI(optionsPanel.getGrid());
105
                                        roi.setName(roiName);
106
                                        roi.setColor((Color)row[1]);
107
                                        optionsPanel.addROI(roi);
108
                                }
109
                                optionsPanel.getTable().setSelectedIndex(optionsPanel.getTable().getRowCount()-1);
110
                        
111
                        } catch (NotInitializeException e1) {
112
                                RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e1);        
113
                        }
114
                        optionsPanel.selectDrawRoiTool();
115
                        optionsPanel.getNewButton().setSelected(true);
116
                        optionsPanel.getDeleteButton().setSelected(false);
117
                }
118
                
119
                // Seleccion de la banda cuyo perfil de linea se pretende representar.
120
                // Seleccionada la banda se actualiza la grafica y los datos en la tabla de la roi seleccionada
121
                if (e.getSource() == optionsPanel.getComboBands()){
122
                        
123
                        try {
124
                                if(optionsPanel.getTable().getRowCount()>0){
125
                                        ROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
126
                                        int band = optionsPanel.getComboBands().getSelectedIndex();
127
                                        drawChartRoi((VectorialROI)lineRoi,band);
128
                                }
129
                                
130
                        } catch (NotInitializeException e1) {
131
                                RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e1);        
132
                        }
133
                        optionsPanel.selectDrawRoiTool();
134
                }
135
                        
136
                // Borrado de una roi
137
                if (e.getSource() == optionsPanel.getDeleteButton()){
138
                        optionsPanel.getDeleteButton().setSelected(false);
139
                        delete=true;
140
                        try {
141
                                if (optionsPanel.getTable().getRowCount()>0){
142
                                        optionsPanel.getJPanelChart().cleanChart();
143
                                        String className = (String)optionsPanel.getTable().getModel().getValueAt(optionsPanel.getTable().getSelectedRow(),0);
144
                                        optionsPanel.removeROI(className);
145
                                        ((DefaultTableModel)optionsPanel.getTable().getModel()).removeRow(optionsPanel.getTable().getSelectedRow());
146
                                        
147
                                        if(optionsPanel.getTable().getRowCount()>0){
148
                                                optionsPanel.getTable().setSelectedIndex(0);
149
                                                ROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
150
                                                int band = optionsPanel.getComboBands().getSelectedIndex();
151
                                                drawChartRoi((VectorialROI)lineRoi,band);
152
                                        }
153
                                        delete=false;
154
                                }
155
                                
156
                        } catch (NotInitializeException e2) {
157
                                RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e2);        
158
                        } 
159
                }                        
160
        }
161

    
162
        
163
        /**
164
         * Acciones cuando se produce una modificaci?n en la tabla
165
         * */
166
        public void tableChanged(TableModelEvent e) {
167
                // Corregir segun cual sea definitivamente  la columna asociada al color
168
                /*if(e.getColumn()==1){
169
                        String roiName = (String)optionsPanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),0);
170
                        ArrayList graphics = optionsPanel.getRoiGraphics(roiName);
171
                        if(optionsPanel.getMapControl()!=null){
172
                                GraphicLayer graphicLayer = optionsPanel.getMapControl().getMapContext().getGraphicsLayer();
173
                                ISymbol symbol = null;
174
                                Color color = (Color)optionsPanel.getTable().getTable().getJTable().getValueAt(e.getFirstRow(),1);
175
                                for (int i = 0; i< graphics.size(); i++){
176
                                        symbol = SymbologyFactory.createDefaultSymbolByShapeType(((FGraphic)graphics.get(i)).getGeom().getGeometryType(), color);
177
                                        ((FGraphic)graphics.get(i)).setIdSymbol(graphicLayer.addSymbol(symbol));
178
                                }
179
                                
180
                                optionsPanel.getROI(roiName).setColor(color);
181
                                optionsPanel.getMapControl().drawGraphics();
182
                        }
183
                optionsPanel.SetColorSeriesChart();
184
                }*/
185
        }
186
        
187
        
188
        public void valueChanged(ListSelectionEvent e) {        
189
                try {
190
                        if(optionsPanel.getTable().getRowCount()>0 && !delete){                        
191
                                VectorialROI lineRoi =(VectorialROI)optionsPanel.getROIs().get(optionsPanel.getTable().getSelectedRow());
192
                                int band = optionsPanel.getComboBands().getSelectedIndex();
193
                                
194
                                if(lineRoi.getGeometries().size()>0)
195
                                        drawChartRoi((VectorialROI)lineRoi,band);
196
                        }
197
                } catch (NotInitializeException e3) {
198
                        RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e3);        
199
                }
200
        }
201

    
202
        /** 
203
         *         Metodo que se encarga de pintar la roi que se pasa como parametro sobre el grafico.
204
         *         La banda de la que se tomar?n los valores es la que se pasa como par?metro.
205
         * */
206
        private  void drawChartRoi(VectorialROI roi, int band){
207
                try {
208
                        int[][] series;
209
                        series = new int[1][roi.getValues()];
210
                        String[] names = new String[1];
211
                        names[0] = "Grafico";
212
                        roi.setBandToOperate(band);
213
                        series = new int[1][roi.getValues()];
214
                        int k=0;
215
                        int z=0;
216
                        if(roi.getGrid().getDataType() == RasterBuffer.TYPE_BYTE){
217
                                for (int i = 0; i < roi.getNX(); i++){
218
                                        for (int j = 0; j < roi.getNY(); j++){        
219
                                                z= (int) roi.getCellValueAsByte(i,j);
220
                                                if(!roi.isNoDataValue(z)){
221
                                                        series[0][k] =z;
222
                                                        k++;
223
                                                }
224
                                        }
225
                                }
226
                        }
227
                        else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_SHORT){
228
                                for (int i = 0; i < roi.getNX(); i++){
229
                                        for (int j = 0; j < roi.getNY(); j++){        
230
                                                z= (int) roi.getCellValueAsShort(i,j);
231
                                                if(!roi.isNoDataValue(z)){
232
                                                        series[0][k] =z;
233
                                                        k++;
234
                                                }
235
                                        }
236
                                }
237
                        }
238
                        else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_INT){
239
                                for (int i = 0; i < roi.getNX(); i++){
240
                                        for (int j = 0; j < roi.getNY(); j++){        
241
                                                z= (int) roi.getCellValueAsInt(i,j);
242
                                                if(!roi.isNoDataValue(z)){
243
                                                        series[0][k] =z;
244
                                                        k++;
245
                                                }
246
                                        }
247
                                }
248
                        }
249
                        else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_FLOAT){
250
                                for (int i = 0; i < roi.getNX(); i++){
251
                                        for (int j = 0; j < roi.getNY(); j++){        
252
                                                z= (int) roi.getCellValueAsFloat(i,j);
253
                                                if(!roi.isNoDataValue(z)){
254
                                                        series[0][k] =z;
255
                                                        k++;
256
                                                }
257
                                        }
258
                                }
259
                        }
260
                        else if(roi.getGrid().getDataType() == RasterBuffer.TYPE_DOUBLE){
261
                                for (int i = 0; i < roi.getNX(); i++){
262
                                        for (int j = 0; j < roi.getNY(); j++){        
263
                                                z= (int) roi.getCellValueAsDouble(i,j);
264
                                                if(!roi.isNoDataValue(z)){
265
                                                        series[0][k] =z;
266
                                                        k++;
267
                                                }
268
                                        }
269
                                }
270
                        }
271
                        
272
                        // Actualizacion del grafico
273
                        optionsPanel.SetColorSeriesChart();
274
                        optionsPanel.getJPanelChart().setNewChart(series, names);
275
                
276
                        // Actualizacion de la tabla
277
                        int selectedRow = optionsPanel.getTable().getSelectedRow();
278
                        roi.setBandToOperate(band);
279
                        double max=roi.getMaxValue();
280
                        double min= roi.getMinValue();
281
                        double mean = roi.getMeanValue();
282
                        optionsPanel.getTable().getModel().setValueAt(new Double(max), selectedRow, 2);
283
                        optionsPanel.getTable().getModel().setValueAt(new Double(min), selectedRow, 3);
284
                        optionsPanel.getTable().getModel().setValueAt(new Double(mean), selectedRow, 4);
285
                        optionsPanel.updateUI();
286
                } catch (GridException e) {
287
                        RasterToolsUtil.messageBoxError(PluginServices.getText(this, "grid_error"), this, e);
288
                } catch (NotInitializeException e) {
289
                        RasterToolsUtil.messageBoxError("tabla_no_inicializada", this, e);        
290
                }
291
        }
292
                        
293
        
294
        public void actionButtonPressed(ButtonsPanelEvent e) {
295
        }
296

    
297
}