root / branches / v2_0_0_prep / extensions / extRemoteSensing / src / org / gvsig / remotesensing / scatterplot / gui / ManagerROIChartPanel.java @ 31496
History | View | Annotate | Download (11.6 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.andami.PluginServices; |
59 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
60 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
61 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
62 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
63 |
import org.gvsig.fmap.mapcontrol.MapControl; |
64 |
import org.gvsig.gui.beans.table.TableContainer; |
65 |
import org.gvsig.gui.beans.table.models.IModel; |
66 |
import org.gvsig.raster.grid.Grid; |
67 |
import org.gvsig.raster.grid.GridException; |
68 |
import org.gvsig.raster.grid.roi.ROI; |
69 |
import org.gvsig.rastertools.roi.ROIFeatureManager; |
70 |
import org.gvsig.remotesensing.scatterplot.chart.ROIChart; |
71 |
import org.gvsig.remotesensing.scatterplot.chart.ScatterPlotDiagram; |
72 |
import org.gvsig.remotesensing.scatterplot.listener.ManagerROIChartPanelListener; |
73 |
|
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 DefaultViewPanel 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 |
private ROIFeatureManager roiFeatureManager;
|
103 |
|
104 |
/**
|
105 |
* Constructor del panel.
|
106 |
* @param scatterPlotPanel panel con el grafico asociado
|
107 |
* */
|
108 |
public ManagerROIChartPanel(ChartScaterPlotPanel scatterPlotPanel) {
|
109 |
super();
|
110 |
setSize(400,200); |
111 |
this.scatterPlotPanel= scatterPlotPanel;
|
112 |
setBorder(new LineBorder(Color.GRAY)); |
113 |
setLayout(new BorderLayout()); |
114 |
add(getTable(), BorderLayout.CENTER);
|
115 |
add(getControlPanel(), BorderLayout.SOUTH);
|
116 |
initialize(); |
117 |
fLayer= scatterPlotPanel.getFLayer(); |
118 |
roiFeatureManager = new ROIFeatureManager(fLayer.getMetadataID()
|
119 |
.toString()); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Inicializaci?n
|
124 |
* */
|
125 |
private void initialize() { |
126 |
listener = new ManagerROIChartPanelListener(this); |
127 |
//Se a?aden los listeners;
|
128 |
getNewRoiButtom().addActionListener(listener); |
129 |
getDeleteButton().addActionListener(listener); |
130 |
getExportButton().addActionListener(listener); |
131 |
getTable().getTable().getJTable().getSelectionModel() |
132 |
.addListSelectionListener(listener); |
133 |
getTable().getTable().getJTable().getModel().addTableModelListener( |
134 |
listener); |
135 |
loadROIsChart(); |
136 |
} |
137 |
|
138 |
|
139 |
public WindowInfo getWindowInfo() {
|
140 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.PALETTE| WindowInfo.RESIZABLE );
|
141 |
m_viewinfo.setTitle(PluginServices.getText(this, "regiones_interes_chart")); |
142 |
m_viewinfo.setHeight(this.getHeight());
|
143 |
m_viewinfo.setWidth(this.getWidth());
|
144 |
return m_viewinfo;
|
145 |
} |
146 |
|
147 |
|
148 |
/**
|
149 |
* Tabla de rois del grafico
|
150 |
* */
|
151 |
public TableContainer getTable() {
|
152 |
if (tableContainer == null) { |
153 |
String[] columnNames = { PluginServices.getText(this, "nombre"), |
154 |
PluginServices.getText(this, "poligonos"), |
155 |
PluginServices.getText(this, "lineas"), |
156 |
PluginServices.getText(this, "puntos"), |
157 |
PluginServices.getText(this, "color"), |
158 |
PluginServices.getText(this, "pixeles")}; |
159 |
int[] columnWidths = { 50, 25, 25, 25, 45, 50 }; |
160 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
161 |
tableContainer.setModel("ROIsTableModel");
|
162 |
tableContainer.initialize(); |
163 |
tableContainer.setControlVisible(false);
|
164 |
tableContainer.setBorder(new EmptyBorder(5, 5, 0, 5)); |
165 |
} |
166 |
return tableContainer;
|
167 |
} |
168 |
|
169 |
|
170 |
|
171 |
public JPanel getControlPanel() { |
172 |
if (controlPanel == null) { |
173 |
controlPanel = new JPanel(); |
174 |
controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
175 |
controlPanel.add(getTableButtonsPanel()); |
176 |
controlPanel.add(getToolsPanel()); |
177 |
// controlPanel.add(getToolBar());
|
178 |
} |
179 |
return controlPanel;
|
180 |
} |
181 |
|
182 |
|
183 |
// Boton de borrado
|
184 |
public JButton getDeleteButton() { |
185 |
if (deleteRoiButton == null) { |
186 |
deleteRoiButton = new JButton(PluginServices.getText(this, "borrar")); |
187 |
} |
188 |
return deleteRoiButton;
|
189 |
} |
190 |
|
191 |
|
192 |
// Boton exportar
|
193 |
public JButton getExportButton() { |
194 |
if (exportRoiButtom == null) { |
195 |
exportRoiButtom = new JButton(PluginServices.getText(this, "exportar")); |
196 |
|
197 |
} |
198 |
return exportRoiButtom;
|
199 |
} |
200 |
|
201 |
public JButton getNewRoiButtom() { |
202 |
if (newRoiButtom== null) { |
203 |
newRoiButtom = new JButton(PluginServices.getText(this, "nuevo")); |
204 |
|
205 |
} |
206 |
return newRoiButtom;
|
207 |
} |
208 |
|
209 |
|
210 |
public FLayer getFLayer() {
|
211 |
return fLayer;
|
212 |
} |
213 |
|
214 |
|
215 |
public void setFLayer(FLayer layer) throws GridException { |
216 |
|
217 |
} |
218 |
|
219 |
/**
|
220 |
* Cargar las entradas en la tabla correspondientes a las ROichart ya definidas en el
|
221 |
* diagrama.
|
222 |
*/
|
223 |
public void loadROIsChart() { |
224 |
|
225 |
ArrayList chartRoisArray = scatterPlotPanel.getChart().getROIChartList().getList();
|
226 |
|
227 |
if (chartRoisArray != null) { |
228 |
|
229 |
for (Iterator iter = chartRoisArray.iterator(); iter.hasNext();) { |
230 |
ROIChart roi = (ROIChart) iter.next(); |
231 |
Object row[] = ((IModel) getTable().getModel()).getNewLine(); |
232 |
row[0] = roi.getName();
|
233 |
row[4] = roi.getColor();
|
234 |
((DefaultTableModel) getTable().getModel()).addRow(row);
|
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
|
240 |
/**
|
241 |
* A?ade la entrada en la tabla correspondiente a la roi
|
242 |
* */
|
243 |
public void addNewRoiEntry(ROIChart roi){ |
244 |
Object row[] = ((IModel) getTable().getModel()).getNewLine(); |
245 |
row[0] = roi.getName();
|
246 |
row[4] = roi.getColor();
|
247 |
((DefaultTableModel) getTable().getModel()).addRow(row);
|
248 |
// Establece la nueva como activa en el grafico
|
249 |
getScatterPlotPanel().getChart().setActiveRoi(roi); |
250 |
updateUI(); |
251 |
} |
252 |
|
253 |
|
254 |
|
255 |
public MapControl getMapControl() {
|
256 |
return mapControl;
|
257 |
} |
258 |
|
259 |
public void selectDrawRoiTool() { |
260 |
|
261 |
} |
262 |
|
263 |
public Grid getGrid() {
|
264 |
return grid;
|
265 |
} |
266 |
|
267 |
private LinkedHashMap getRois() { |
268 |
if (rois == null) |
269 |
rois = new LinkedHashMap(); |
270 |
return rois;
|
271 |
} |
272 |
|
273 |
public JPanel getToolsPanel() { |
274 |
if (toolsPanel == null) { |
275 |
toolsPanel = new JPanel(); |
276 |
toolsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
277 |
} |
278 |
return toolsPanel;
|
279 |
} |
280 |
|
281 |
public JPanel getTableButtonsPanel() { |
282 |
if (tableButtonsPanel == null) { |
283 |
tableButtonsPanel = new JPanel(); |
284 |
tableButtonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
285 |
tableButtonsPanel.add(getNewRoiButtom()); |
286 |
tableButtonsPanel.add(getDeleteButton()); |
287 |
BorderLayout fL= new BorderLayout(); |
288 |
JPanel p= new JPanel(); |
289 |
p.setLayout(fL); |
290 |
p.add(getExportButton(),BorderLayout.EAST);
|
291 |
tableButtonsPanel.add(p); |
292 |
} |
293 |
return tableButtonsPanel;
|
294 |
} |
295 |
|
296 |
|
297 |
|
298 |
|
299 |
public Cursor getToolCursor() { |
300 |
return cursor;
|
301 |
} |
302 |
|
303 |
public DefaultViewPanel getView() {
|
304 |
return view;
|
305 |
} |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
// private HashMap getRoiGraphics() {
|
311 |
// if (roiGraphics == null)
|
312 |
// roiGraphics = new HashMap();
|
313 |
// return roiGraphics;
|
314 |
// }
|
315 |
|
316 |
public void addROI(ROI roi) { |
317 |
getRois().put(roi.getName(), roi); |
318 |
// getRoiGraphics().put(roi.getName(), new ArrayList());
|
319 |
} |
320 |
|
321 |
public ROIChart getROI(String roiName) { |
322 |
return (ROIChart) getScatterPlotPanel().getChart().getROIChartList().getListRois().get(roiName);
|
323 |
} |
324 |
|
325 |
/**
|
326 |
* Elimina la ROI correspondiente al nombre <code>roiName</code> as?
|
327 |
* como sus objetos FGraphic asociados (borr?ndolos tambi?n de la vista).
|
328 |
* (NO elimina la fila correspondiente en la tabla del panel).
|
329 |
*
|
330 |
* @param roiName Nombre de la ROI a eliminar.
|
331 |
*/
|
332 |
public void removeROI(String roiName) { |
333 |
boolean repaint = false; |
334 |
getRois().remove(roiName); |
335 |
roiFeatureManager.removeROI(roiName, getMapControl().getMapContext() |
336 |
.getGraphicsLayer()); |
337 |
// ArrayList roiGraphics = getRoiGraphics(roiName);
|
338 |
// if (roiGraphics != null) {
|
339 |
// for (int i = 0; i < roiGraphics.size(); i++){
|
340 |
// getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic) getRoiGraphics(roiName).get(i));
|
341 |
// repaint = true;
|
342 |
// }
|
343 |
// if (repaint)
|
344 |
// getMapControl().rePaintDirtyLayers();
|
345 |
// getRoiGraphics().remove(roiName);
|
346 |
// }
|
347 |
} |
348 |
|
349 |
// public ArrayList getRoiGraphics(String roiName) {
|
350 |
// return (ArrayList) getRoiGraphics().get(roiName);
|
351 |
// }
|
352 |
|
353 |
/**
|
354 |
* Borra de capa GraphicsLayer de mapContext los gr?ficos pertenecientes a
|
355 |
* las rois del panel. Si la GraphicsLayer se queda sin gr?ficos se eliminan
|
356 |
* tambien los s?mbolos de esta.
|
357 |
*/
|
358 |
public void clearRoiGraphics() { |
359 |
/* for (Iterator iter = getRoiGraphics().values().iterator(); iter
|
360 |
.hasNext();) {
|
361 |
ArrayList fGraphics = (ArrayList) iter.next();
|
362 |
|
363 |
for (Iterator iterator = fGraphics.iterator(); iterator.hasNext();) {
|
364 |
FGraphic fGraphic = (FGraphic) iterator.next();
|
365 |
getMapControl().getMapContext().getGraphicsLayer()
|
366 |
.removeGraphic(fGraphic);
|
367 |
}
|
368 |
}
|
369 |
if (getMapControl().getMapContext().getGraphicsLayer().getNumGraphics() == 0)
|
370 |
getMapControl().getMapContext().getGraphicsLayer()
|
371 |
.clearSymbolsGraphics();*/
|
372 |
} |
373 |
|
374 |
public ArrayList getROIs() { |
375 |
return new ArrayList(getRois().values()); |
376 |
} |
377 |
|
378 |
public void setPreviousTool() { |
379 |
if (previousTool != null) |
380 |
getMapControl().setTool(previousTool); |
381 |
} |
382 |
|
383 |
public void changeRoiName(String currentName, String newName) { |
384 |
getROI(currentName).setName(newName); |
385 |
scatterPlotPanel.getChart().getROIChartList().getListRois().put(newName, scatterPlotPanel.getChart().getROIChartList().getListRois().remove(currentName)); |
386 |
} |
387 |
|
388 |
|
389 |
|
390 |
public void changeRoiColor(String roiName, Color color) { |
391 |
// getROI(roiName).setColor(color);
|
392 |
((ROIChart)scatterPlotPanel.getChart().getROIChartList().getListRois().get(roiName)).setColor(color); |
393 |
} |
394 |
|
395 |
|
396 |
public void sortTable(){ |
397 |
|
398 |
} |
399 |
|
400 |
|
401 |
public ChartScaterPlotPanel getScatterPlotPanel(){
|
402 |
return scatterPlotPanel;
|
403 |
|
404 |
} |
405 |
|
406 |
public ScatterPlotDiagram getDiagram(){
|
407 |
return scatterPlotPanel.getChart();
|
408 |
} |
409 |
|
410 |
|
411 |
public void updateTable(){ |
412 |
ROIChart roi = getDiagram().getActiveRoiChart(); |
413 |
Object row[] = ((IModel) getTable().getModel()).getNewLine(); |
414 |
row[0] = roi.getName();
|
415 |
row[4] = roi.getColor();
|
416 |
((DefaultTableModel) getTable().getModel()).addRow(row);
|
417 |
} |
418 |
|
419 |
public Object getWindowProfile() { |
420 |
return WindowInfo.PROPERTIES_PROFILE;
|
421 |
} |
422 |
|
423 |
|
424 |
|
425 |
} |