Statistics
| Revision:

root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / gui / ManagerROIChartPanel.java @ 24986

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.scatterplot.gui;
42

    
43
import java.awt.BorderLayout;
44
import java.awt.Color;
45
import java.awt.Cursor;
46
import java.awt.FlowLayout;
47
import java.util.ArrayList;
48
import java.util.HashMap;
49
import java.util.Iterator;
50
import java.util.LinkedHashMap;
51

    
52
import javax.swing.JButton;
53
import javax.swing.JPanel;
54
import javax.swing.border.EmptyBorder;
55
import javax.swing.border.LineBorder;
56
import javax.swing.table.DefaultTableModel;
57

    
58
import org.gvsig.gui.beans.table.TableContainer;
59
import org.gvsig.gui.beans.table.models.IModel;
60
import org.gvsig.raster.grid.Grid;
61
import org.gvsig.raster.grid.GridException;
62
import org.gvsig.raster.grid.roi.ROI;
63
import org.gvsig.remotesensing.scatterplot.chart.ROIChart;
64
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram;
65
import org.gvsig.remotesensing.scatterplot.listener.ManagerROIChartPanelListener;
66

    
67
import com.iver.andami.PluginServices;
68
import com.iver.andami.ui.mdiManager.IWindow;
69
import com.iver.andami.ui.mdiManager.WindowInfo;
70
import com.iver.cit.gvsig.fmap.MapControl;
71
import com.iver.cit.gvsig.fmap.layers.FLayer;
72
import com.iver.cit.gvsig.fmap.rendering.FGraphic;
73
import com.iver.cit.gvsig.project.documents.view.gui.View;
74

    
75
/**
76
 * Clase que define el panel de gesti?n de Rois del grafico.  
77
 * 
78
 * @author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)  
79
 * @version 11/12/2007
80
 */
81
public class ManagerROIChartPanel extends JPanel  implements IWindow{
82

    
83
        private static final long serialVersionUID = 1L;
84
        private ManagerROIChartPanelListener listener = null;
85
        private JPanel controlPanel = null;
86
        private JPanel tableButtonsPanel = null;
87
        private JPanel toolsPanel = null;
88
        private TableContainer tableContainer = null;
89
        private JButton exportRoiButtom = null;
90
        private JButton newRoiButtom = null;
91
        private JButton deleteRoiButton = null;
92
        private FLayer fLayer = null;
93
        private MapControl mapControl = null;
94
        private View view = null;
95
        private LinkedHashMap rois = null;
96
        private HashMap roiGraphics = null;
97
        private Grid grid = null;
98
        private Cursor cursor = null;
99
        private String previousTool = null;
100
        private ChartScaterPlotPanel scatterPlotPanel = null;
101
        
102

    
103
        /**
104
         *  Constructor del panel.
105
         *  @param scatterPlotPanel panel con el grafico asociado
106
         * */
107
        public ManagerROIChartPanel(ChartScaterPlotPanel scatterPlotPanel) {
108
                super();
109
                setSize(400,200);
110
                this.scatterPlotPanel= scatterPlotPanel;
111
                setBorder(new LineBorder(Color.GRAY));
112
                setLayout(new BorderLayout());
113
                add(getTable(), BorderLayout.CENTER);
114
                add(getControlPanel(), BorderLayout.SOUTH);
115
                initialize();
116
                fLayer= scatterPlotPanel.getFLayer();
117
        }
118

    
119
        /**
120
         *  Inicializaci?n
121
         * */
122
        private void initialize() {
123
                listener = new ManagerROIChartPanelListener(this);
124
                //Se a?aden los listeners;
125
                getNewRoiButtom().addActionListener(listener);
126
                getDeleteButton().addActionListener(listener);
127
                getExportButton().addActionListener(listener);
128
                getTable().getTable().getJTable().getSelectionModel()
129
                                .addListSelectionListener(listener);
130
                getTable().getTable().getJTable().getModel().addTableModelListener(
131
                                listener);
132
                loadROIsChart();
133
        }
134

    
135
        
136
        public WindowInfo getWindowInfo() {
137
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.PALETTE| WindowInfo.RESIZABLE );
138
                m_viewinfo.setTitle(PluginServices.getText(this, "regiones_interes_chart"));
139
                m_viewinfo.setHeight(this.getHeight());
140
                m_viewinfo.setWidth(this.getWidth());
141
                return m_viewinfo;
142
        }
143

    
144
                
145
        /**
146
         *                Tabla de rois del grafico  
147
         * */
148
        public TableContainer getTable() {
149
                if (tableContainer == null) {
150
                        String[] columnNames = { PluginServices.getText(this, "nombre"),
151
                                        PluginServices.getText(this, "poligonos"),
152
                                        PluginServices.getText(this, "lineas"),
153
                                        PluginServices.getText(this, "puntos"),
154
                                        PluginServices.getText(this, "color"),
155
                                        PluginServices.getText(this, "pixeles")};
156
                        int[] columnWidths = { 50, 25, 25, 25, 45, 50 };
157
                        tableContainer = new TableContainer(columnNames, columnWidths);
158
                        tableContainer.setModel("ROIsTableModel");
159
                        tableContainer.initialize();
160
                        tableContainer.setControlVisible(false);
161
                        tableContainer.setBorder(new EmptyBorder(5, 5, 0, 5));
162
                }
163
                return tableContainer;
164
        }
165

    
166
        
167
        
168
        public JPanel getControlPanel() {
169
                if (controlPanel == null) {
170
                        controlPanel = new JPanel();
171
                        controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
172
                        controlPanel.add(getTableButtonsPanel());
173
                        controlPanel.add(getToolsPanel());
174
                        // controlPanel.add(getToolBar());
175
                }
176
                return controlPanel;
177
        }
178

    
179
        
180
        // Boton de borrado
181
        public JButton getDeleteButton() {
182
                if (deleteRoiButton == null) {
183
                        deleteRoiButton = new JButton(PluginServices.getText(this, "borrar"));
184
                }
185
                return deleteRoiButton;
186
        }
187

    
188
        
189
        // Boton exportar 
190
        public JButton getExportButton() {
191
                if (exportRoiButtom == null) {
192
                        exportRoiButtom = new JButton(PluginServices.getText(this, "exportar"));
193
                        
194
                }
195
                return exportRoiButtom;
196
        }
197

    
198
        public JButton getNewRoiButtom() {
199
                if (newRoiButtom== null) {
200
                        newRoiButtom = new JButton(PluginServices.getText(this, "nuevo"));
201
                        
202
                }
203
                return newRoiButtom;
204
        }
205
        
206
        
207
        public FLayer getFLayer() {
208
                return fLayer;
209
        }
210

    
211
        
212
        public void setFLayer(FLayer layer) throws GridException {
213
                
214
        }
215

    
216
        /**
217
         * Cargar las entradas en la tabla correspondientes a las ROichart ya definidas en el 
218
         * diagrama.
219
         */
220
        public void loadROIsChart() {
221
        
222
                ArrayList chartRoisArray = scatterPlotPanel.getChart().getROIChartList().getList();
223
                
224
                if (chartRoisArray != null) {
225

    
226
                        for (Iterator iter = chartRoisArray.iterator(); iter.hasNext();) {
227
                                ROIChart roi = (ROIChart) iter.next();
228
                                Object row[] = ((IModel) getTable().getModel()).getNewLine();
229
                                row[0] = roi.getName();
230
                                row[4] = roi.getColor();
231
                                ((DefaultTableModel) getTable().getModel()).addRow(row);
232
                        }
233
                }
234
        }
235

    
236
        
237
        /**
238
         * A?ade la entrada en la tabla correspondiente a la roi
239
         * */
240
        public void addNewRoiEntry(ROIChart roi){
241
                Object row[] = ((IModel) getTable().getModel()).getNewLine();
242
                row[0] = roi.getName();
243
                row[4] = roi.getColor();        
244
                ((DefaultTableModel) getTable().getModel()).addRow(row);
245
                // Establece la nueva como activa en el grafico
246
                getScatterPlotPanel().getChart().setActiveRoi(roi);
247
                updateUI();
248
        }
249
        
250
        
251
        
252
        public MapControl getMapControl() {
253
                return mapControl;
254
        }
255

    
256
        public void selectDrawRoiTool() {
257
        
258
        }
259

    
260
        public Grid getGrid() {
261
                return grid;
262
        }
263

    
264
        private LinkedHashMap getRois() {
265
                if (rois == null)
266
                        rois = new LinkedHashMap();
267
                return rois;
268
        }
269

    
270
        public JPanel getToolsPanel() {
271
                if (toolsPanel == null) {
272
                        toolsPanel = new JPanel();
273
                        toolsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
274
                }
275
                return toolsPanel;
276
        }
277

    
278
        public JPanel getTableButtonsPanel() {
279
                if (tableButtonsPanel == null) {
280
                        tableButtonsPanel = new JPanel();
281
                        tableButtonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
282
                        tableButtonsPanel.add(getNewRoiButtom());
283
                        tableButtonsPanel.add(getDeleteButton());
284
                        BorderLayout fL= new BorderLayout();
285
                        JPanel p= new JPanel();
286
                        p.setLayout(fL);
287
                        p.add(getExportButton(),BorderLayout.EAST);
288
                        tableButtonsPanel.add(p);
289
                }
290
                return tableButtonsPanel;
291
        }
292

    
293
        
294
        
295

    
296
        public Cursor getToolCursor() {
297
                return cursor;
298
        }
299

    
300
        public View getView() {
301
                return view;
302
        }
303

    
304
        
305

    
306

    
307
        private HashMap getRoiGraphics() {
308
                if (roiGraphics == null)
309
                        roiGraphics = new HashMap();
310
                return roiGraphics;
311
        }
312

    
313
        public void addROI(ROI roi) {
314
                getRois().put(roi.getName(), roi);
315
                getRoiGraphics().put(roi.getName(), new ArrayList());
316
        }
317

    
318
        public ROIChart getROI(String roiName) {
319
                return (ROIChart) getScatterPlotPanel().getChart().getROIChartList().getListRois().get(roiName);
320
        }
321

    
322
        /**
323
         * Elimina la ROI correspondiente al nombre <code>roiName</code> as?
324
         * como sus objetos FGraphic asociados (borr?ndolos tambi?n de la vista).
325
         * (NO elimina la fila correspondiente en la tabla del panel).
326
         * 
327
         * @param roiName Nombre de la ROI a eliminar.
328
         */
329
        public void removeROI(String roiName) {
330
                boolean repaint = false;
331
                getRois().remove(roiName);
332
                ArrayList roiGraphics = getRoiGraphics(roiName);
333
                if (roiGraphics != null) {
334
                        for (int i = 0; i < roiGraphics.size(); i++){
335
                                getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic) getRoiGraphics(roiName).get(i));
336
                                repaint = true;
337
                        }
338
                        if (repaint)
339
                                getMapControl().rePaintDirtyLayers();
340
                        getRoiGraphics().remove(roiName);
341
                }
342
        }
343

    
344
        public ArrayList getRoiGraphics(String roiName) {
345
                return (ArrayList) getRoiGraphics().get(roiName);
346
        }
347

    
348
        /**
349
         * Borra de capa GraphicsLayer de mapContext los gr?ficos pertenecientes a
350
         * las rois del panel. Si la GraphicsLayer se queda sin gr?ficos se eliminan
351
         * tambien los s?mbolos de esta.
352
         */
353
        public void clearRoiGraphics() {
354
        /*        for (Iterator iter = getRoiGraphics().values().iterator(); iter
355
                                .hasNext();) {
356
                        ArrayList fGraphics = (ArrayList) iter.next();
357

358
                        for (Iterator iterator = fGraphics.iterator(); iterator.hasNext();) {
359
                                FGraphic fGraphic = (FGraphic) iterator.next();
360
                                getMapControl().getMapContext().getGraphicsLayer()
361
                                                .removeGraphic(fGraphic);
362
                        }
363
                }
364
                if (getMapControl().getMapContext().getGraphicsLayer().getNumGraphics() == 0)
365
                        getMapControl().getMapContext().getGraphicsLayer()
366
                                        .clearSymbolsGraphics();*/
367
        }
368

    
369
        public ArrayList getROIs() {
370
                return new ArrayList(getRois().values());
371
        }
372

    
373
        public void setPreviousTool() {
374
                if (previousTool != null)
375
                        getMapControl().setTool(previousTool);
376
        }
377

    
378
        public void changeRoiName(String currentName, String newName) {
379
                getROI(currentName).setName(newName);
380
                scatterPlotPanel.getChart().getROIChartList().getListRois().put(newName, scatterPlotPanel.getChart().getROIChartList().getListRois().remove(currentName));
381
        }
382
        
383
        
384
        
385
        public void changeRoiColor(String roiName, Color color) {
386
        //        getROI(roiName).setColor(color);
387
                ((ROIChart)scatterPlotPanel.getChart().getROIChartList().getListRois().get(roiName)).setColor(color);
388
        }
389
        
390
        
391
        public void sortTable(){
392
                
393
        }
394

    
395
        
396
        public ChartScaterPlotPanel getScatterPlotPanel(){
397
                return scatterPlotPanel;
398
                
399
        }
400
        
401
        public ScatterPlotDiagram getDiagram(){
402
                return scatterPlotPanel.getChart();
403
        }
404

    
405
        
406
        public void updateTable(){
407
                ROIChart roi = getDiagram().getActiveRoiChart();
408
                Object row[] = ((IModel) getTable().getModel()).getNewLine();
409
                row[0] = roi.getName();
410
                row[4] = roi.getColor();
411
                ((DefaultTableModel) getTable().getModel()).addRow(row);
412
        }
413

    
414
        public Object getWindowProfile() {
415
                return WindowInfo.PROPERTIES_PROFILE;
416
        }        
417
        
418
        
419
        
420
}