svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / roi / ui / ROIManagerPanel.java @ 14321
History | View | Annotate | Download (18 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.rastertools.roi.ui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.Cursor; |
46 |
import java.awt.FlowLayout; |
47 |
import java.awt.Graphics2D; |
48 |
import java.awt.Image; |
49 |
import java.awt.Point; |
50 |
import java.awt.Toolkit; |
51 |
import java.awt.image.BufferedImage; |
52 |
import java.util.ArrayList; |
53 |
import java.util.HashMap; |
54 |
import java.util.Iterator; |
55 |
|
56 |
import javax.swing.ImageIcon; |
57 |
import javax.swing.JButton; |
58 |
import javax.swing.JMenu; |
59 |
import javax.swing.JMenuBar; |
60 |
import javax.swing.JMenuItem; |
61 |
import javax.swing.JPanel; |
62 |
import javax.swing.JToggleButton; |
63 |
import javax.swing.border.EmptyBorder; |
64 |
import javax.swing.border.LineBorder; |
65 |
import javax.swing.table.DefaultTableModel; |
66 |
|
67 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
68 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
69 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
70 |
import org.gvsig.gui.beans.table.TableContainer; |
71 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
72 |
import org.gvsig.gui.beans.table.models.IModel; |
73 |
import org.gvsig.raster.buffer.BufferFactory; |
74 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
75 |
import org.gvsig.raster.grid.Grid; |
76 |
import org.gvsig.raster.grid.roi.ROI; |
77 |
import org.gvsig.rastertools.roi.ui.listener.DrawMouseViewListener; |
78 |
import org.gvsig.rastertools.roi.ui.listener.ROIManagerPanelListener; |
79 |
|
80 |
import com.iver.andami.PluginServices; |
81 |
import com.iver.cit.gvsig.fmap.MapControl; |
82 |
import com.iver.cit.gvsig.fmap.ViewPort; |
83 |
import com.iver.cit.gvsig.fmap.core.FShape; |
84 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
85 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
86 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
87 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
88 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
89 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
90 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
91 |
import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
92 |
import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
93 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
94 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
95 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
96 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
97 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
98 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
99 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
100 |
|
101 |
/**
|
102 |
* Iterfazde usuario para la gesti?n de ROIs.
|
103 |
*
|
104 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
105 |
*
|
106 |
*/
|
107 |
public class ROIManagerPanel extends DefaultButtonsPanel { |
108 |
private static final long serialVersionUID = 2138437448356198224L; |
109 |
|
110 |
private ROIManagerDialog roiManagerDialog = null; |
111 |
private ROIManagerPanelListener listener = null; |
112 |
private JMenuBar menuBar = null; |
113 |
private JPanel tablePanel = null; |
114 |
private JPanel controlPanel = null; |
115 |
private JPanel tableButtonsPanel = null; |
116 |
private JPanel toolsPanel = null; |
117 |
private TableContainer tableContainer = null; |
118 |
private JButton newButton = null; |
119 |
private JButton deleteButton = null; |
120 |
private JToggleButton pointToolButton = null; |
121 |
private JToggleButton lineToolButton = null; |
122 |
private JToggleButton polygonToolButton = null; |
123 |
private JMenuItem closeMenuItem = null; |
124 |
private JMenuItem saveMenuItem = null; |
125 |
private JMenuItem loadMenuItem = null; |
126 |
private JMenuItem exportMenuItem = null; |
127 |
private JMenuItem helpMenuItem = null; |
128 |
private JMenuItem preferencesMenuItem = null; |
129 |
private FLayer fLayer = null; |
130 |
private MapControl mapControl = null; |
131 |
private View view = null; |
132 |
private HashMap rois = null; |
133 |
private HashMap roiGraphics = null; |
134 |
private Grid grid = null; |
135 |
private String pathToImages = "images/"; |
136 |
private Cursor cursor = null; |
137 |
|
138 |
public ROIManagerPanel(ROIManagerDialog roiManagerDialog) {
|
139 |
super();
|
140 |
this.roiManagerDialog = roiManagerDialog;
|
141 |
initialize(); |
142 |
|
143 |
|
144 |
} |
145 |
|
146 |
private void initialize() { |
147 |
setLayout(new BorderLayout(5,5)); |
148 |
setBorder(new EmptyBorder(0,15,11,15)); |
149 |
add(getMenuBar(),BorderLayout.NORTH);
|
150 |
add(getTablePanel(),BorderLayout.CENTER);
|
151 |
|
152 |
listener = new ROIManagerPanelListener(this); |
153 |
getCloseMenuItem().addActionListener(listener); |
154 |
getNewButton().addActionListener(listener); |
155 |
getDeleteButton().addActionListener(listener); |
156 |
getPointToolButton().addActionListener(listener); |
157 |
getLineToolButton().addActionListener(listener); |
158 |
getPolygonToolButton().addActionListener(listener); |
159 |
getTable().getTable().getJTable().getSelectionModel().addListSelectionListener(listener); |
160 |
getTable().getTable().getJTable().getModel().addTableModelListener(listener); |
161 |
|
162 |
getPolygonToolButton().setSelected(true);
|
163 |
setToolsEnabled(false);
|
164 |
} |
165 |
|
166 |
public void setToolsEnabled(boolean b) { |
167 |
getPointToolButton().setEnabled(b); |
168 |
getLineToolButton().setEnabled(b); |
169 |
getPolygonToolButton().setEnabled(b); |
170 |
} |
171 |
|
172 |
public JMenuBar getMenuBar() { |
173 |
if (menuBar==null){ |
174 |
menuBar = new JMenuBar(); |
175 |
menuBar.setBorder(new EmptyBorder(0,0,0,0)); |
176 |
JMenu fileMenu = new JMenu(PluginServices.getText(this, "archivo")); |
177 |
JMenu optionsMenu = new JMenu(PluginServices.getText(this, "opciones")); |
178 |
JMenu helpMenu = new JMenu(PluginServices.getText(this, "help")); |
179 |
|
180 |
fileMenu.add(getSaveMenuItem()); |
181 |
fileMenu.add(getLoadMenuItem()); |
182 |
fileMenu.add(getExportMenuItem()); |
183 |
fileMenu.add(getCloseMenuItem()); |
184 |
helpMenu.add(getHelpMenuItem()); |
185 |
optionsMenu.add(getPreferencesMenuItem()); |
186 |
menuBar.add(fileMenu); |
187 |
menuBar.add(optionsMenu); |
188 |
menuBar.add(helpMenu); |
189 |
} |
190 |
return menuBar;
|
191 |
} |
192 |
|
193 |
public TableContainer getTable(){
|
194 |
if (tableContainer == null){ |
195 |
String[] columnNames = {PluginServices.getText(this, "nombre"), |
196 |
PluginServices.getText(this, "poligonos"), |
197 |
PluginServices.getText(this, "lineas"), |
198 |
PluginServices.getText(this, "puntos"), |
199 |
PluginServices.getText(this, "color")}; |
200 |
int[] columnWidths = {70,30,30,30, 110}; |
201 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
202 |
tableContainer.setModel("ROIsTableModel");
|
203 |
tableContainer.initialize(); |
204 |
tableContainer.setControlVisible(false);
|
205 |
tableContainer.setBorder(new EmptyBorder(5,5,0,5)); |
206 |
} |
207 |
return tableContainer;
|
208 |
} |
209 |
|
210 |
public JPanel getTablePanel() { |
211 |
if (tablePanel == null){ |
212 |
tablePanel = new JPanel(); |
213 |
tablePanel.setBorder(new LineBorder(Color.GRAY)); |
214 |
tablePanel.setLayout(new BorderLayout()); |
215 |
tablePanel.add(getTable(),BorderLayout.CENTER);
|
216 |
tablePanel.add(getControlPanel(),BorderLayout.SOUTH);
|
217 |
} |
218 |
return tablePanel;
|
219 |
} |
220 |
|
221 |
public JPanel getControlPanel() { |
222 |
if (controlPanel == null){ |
223 |
controlPanel = new JPanel(); |
224 |
controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
225 |
|
226 |
controlPanel.add(getTableButtonsPanel()); |
227 |
|
228 |
controlPanel.add(getToolsPanel()); |
229 |
//controlPanel.add(getToolBar());
|
230 |
} |
231 |
return controlPanel;
|
232 |
} |
233 |
|
234 |
public JButton getDeleteButton() { |
235 |
if (deleteButton == null){ |
236 |
deleteButton = new JButton(PluginServices.getText(this, "borrar")); |
237 |
} |
238 |
return deleteButton;
|
239 |
} |
240 |
|
241 |
public JButton getNewButton() { |
242 |
if (newButton == null){ |
243 |
newButton = new JButton(PluginServices.getText(this, "nuevo")); |
244 |
} |
245 |
return newButton;
|
246 |
} |
247 |
|
248 |
public JMenuItem getCloseMenuItem() { |
249 |
if (closeMenuItem == null){ |
250 |
closeMenuItem = new JMenuItem(PluginServices.getText(this, "cerrar")); |
251 |
} |
252 |
return closeMenuItem;
|
253 |
} |
254 |
|
255 |
public ROIManagerDialog getRoiManagerDialog() {
|
256 |
return roiManagerDialog;
|
257 |
} |
258 |
|
259 |
public JMenuItem getExportMenuItem() { |
260 |
if (helpMenuItem == null){ |
261 |
exportMenuItem = new JMenuItem(PluginServices.getText(this, "exportar")); |
262 |
} |
263 |
return exportMenuItem;
|
264 |
} |
265 |
|
266 |
public JMenuItem getHelpMenuItem() { |
267 |
if (helpMenuItem == null){ |
268 |
helpMenuItem = new JMenuItem(PluginServices.getText(this, "help")); |
269 |
} |
270 |
return helpMenuItem;
|
271 |
} |
272 |
|
273 |
public JMenuItem getLoadMenuItem() { |
274 |
if (loadMenuItem == null){ |
275 |
loadMenuItem = new JMenuItem(PluginServices.getText(this, "cargar")); |
276 |
} |
277 |
return loadMenuItem;
|
278 |
} |
279 |
|
280 |
public JMenuItem getSaveMenuItem() { |
281 |
if (saveMenuItem == null){ |
282 |
saveMenuItem = new JMenuItem(PluginServices.getText(this, "salvar")); |
283 |
} |
284 |
return saveMenuItem;
|
285 |
} |
286 |
|
287 |
public JMenuItem getPreferencesMenuItem() { |
288 |
if (preferencesMenuItem == null){ |
289 |
preferencesMenuItem = new JMenuItem(PluginServices.getText(this, "preferencias")); |
290 |
} |
291 |
return preferencesMenuItem;
|
292 |
} |
293 |
|
294 |
public FLayer getFLayer() {
|
295 |
return fLayer;
|
296 |
} |
297 |
|
298 |
public void setFLayer(FLayer layer) { |
299 |
fLayer = layer; |
300 |
FLyrRasterSE rasterLayer = (FLyrRasterSE)layer; |
301 |
|
302 |
BufferFactory dataSource = rasterLayer.getBufferFactory(); |
303 |
|
304 |
int bands[]=null; |
305 |
bands = new int [rasterLayer.getBandCount()]; |
306 |
for(int i=0; i<rasterLayer.getBandCount();i++) |
307 |
bands[i]=i; |
308 |
try {
|
309 |
grid = new Grid(dataSource, bands);
|
310 |
} catch (RasterBufferInvalidException e) {
|
311 |
e.printStackTrace(); |
312 |
} |
313 |
|
314 |
view = (View) PluginServices.getMDIManager().getActiveWindow();
|
315 |
mapControl = view.getMapControl(); |
316 |
|
317 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
318 |
// la barra de estado
|
319 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
320 |
|
321 |
DrawMouseViewListener drawMouseViewListener = new DrawMouseViewListener(this); |
322 |
mapControl.addMapTool("drawPolygonROI", new Behavior[] { |
323 |
new PolygonBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
324 |
} |
325 |
); |
326 |
mapControl.addMapTool("drawLineROI", new Behavior[] { |
327 |
new PolylineBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
328 |
} |
329 |
); |
330 |
mapControl.addMapTool("drawPointROI", new Behavior[] { |
331 |
new PointBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
332 |
} |
333 |
); |
334 |
mapControl.getMapContext().addLayerDrawingListener(listener); |
335 |
/*
|
336 |
* Caragar las ROIs asociadas a la capa, si las hay:
|
337 |
*/
|
338 |
clearROIs(); |
339 |
loadROIs(); |
340 |
} |
341 |
|
342 |
private void clearROIs() { |
343 |
try {
|
344 |
getTable().removeAllRows(); |
345 |
} catch (NotInitializeException e) {
|
346 |
// TODO Auto-generated catch block
|
347 |
e.printStackTrace(); |
348 |
} |
349 |
getRoiGraphics().clear(); |
350 |
getRois().clear(); |
351 |
} |
352 |
|
353 |
/**
|
354 |
* Cargar las Capas asociadas a la capa, si las hay.
|
355 |
*
|
356 |
*/
|
357 |
private void loadROIs() { |
358 |
ArrayList roisArray = ((FLyrRasterSE)fLayer).getRois();
|
359 |
if (roisArray != null){ |
360 |
GraphicLayer graphicLayer = getMapControl().getMapContext().getGraphicsLayer(); |
361 |
ISymbol symbol = null;
|
362 |
FGraphic fGraphic = null;
|
363 |
int nPoints, nPolygons, nLines;
|
364 |
|
365 |
for (Iterator iter = roisArray.iterator(); iter.hasNext();) { |
366 |
nPoints = 0; nPolygons = 0; nLines = 0; |
367 |
|
368 |
ROI roi = (ROI) iter.next(); |
369 |
|
370 |
Object row [] = ((IModel)getTable().getModel()).getNewLine(); |
371 |
row[0]= roi.getName();
|
372 |
row[4]= roi.getColor();
|
373 |
|
374 |
addROI(roi); |
375 |
VectorialROI vectorialROI = (VectorialROI)roi; |
376 |
for (Iterator iterator = vectorialROI.getGeometries().iterator(); iterator.hasNext();) { |
377 |
IGeometry geometry = (IGeometry) iterator.next(); |
378 |
switch (geometry.getGeometryType()) {
|
379 |
case FShape.POINT:
|
380 |
symbol = SymbologyFactory.createDefaultMarkerSymbol(); |
381 |
((IMarkerSymbol)symbol).setColor(roi.getColor()); |
382 |
nPoints++; |
383 |
break;
|
384 |
case FShape.POLYGON:
|
385 |
symbol =SymbologyFactory.createDefaultFillSymbol(); |
386 |
((IFillSymbol)symbol).setFillColor(roi.getColor()); |
387 |
nPolygons++; |
388 |
break;
|
389 |
case FShape.LINE:
|
390 |
symbol =SymbologyFactory.createDefaultLineSymbol(); |
391 |
((ILineSymbol)symbol).setLineColor(roi.getColor()); |
392 |
nLines++; |
393 |
break;
|
394 |
} |
395 |
fGraphic = new FGraphic(geometry,graphicLayer.addSymbol(symbol));
|
396 |
graphicLayer.addGraphic(fGraphic); |
397 |
getRoiGraphics(roi.getName()).add(fGraphic); |
398 |
} |
399 |
row[1]= new Integer(nPolygons); row[2]= new Integer (nLines); row[3]= new Integer(nPoints); |
400 |
((DefaultTableModel)getTable().getModel()).addRow(row);
|
401 |
} |
402 |
selectDrawRoiTool(); |
403 |
setToolsEnabled(true);
|
404 |
getMapControl().drawGraphics(); |
405 |
} |
406 |
} |
407 |
|
408 |
public MapControl getMapControl() {
|
409 |
return mapControl;
|
410 |
} |
411 |
|
412 |
public void selectDrawRoiTool(){ |
413 |
if (mapControl!=null) |
414 |
if (getPolygonToolButton().isSelected()){
|
415 |
Image img = new ImageIcon(getClass().getResource("images/PoligonCursor.png")).getImage(); |
416 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
417 |
mapControl.setTool("drawPolygonROI");
|
418 |
} |
419 |
else if (getLineToolButton().isSelected()){ |
420 |
Image img = new ImageIcon(getClass().getResource("images/LineCursor.png")).getImage(); |
421 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
422 |
mapControl.setTool("drawLineROI");
|
423 |
} |
424 |
else if (getPointToolButton().isSelected()){ |
425 |
Image img = new ImageIcon(getClass().getResource("images/PointCursor.png")).getImage(); |
426 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
427 |
mapControl.setTool("drawPointROI");
|
428 |
} |
429 |
} |
430 |
|
431 |
public Grid getGrid() {
|
432 |
return grid;
|
433 |
} |
434 |
|
435 |
private HashMap getRois() { |
436 |
if (rois == null) |
437 |
rois = new HashMap(); |
438 |
return rois;
|
439 |
} |
440 |
|
441 |
public JPanel getToolsPanel() { |
442 |
if (toolsPanel==null){ |
443 |
toolsPanel = new JPanel(); |
444 |
toolsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
445 |
toolsPanel.add(getPointToolButton()); |
446 |
toolsPanel.add(getLineToolButton()); |
447 |
toolsPanel.add(getPolygonToolButton()); |
448 |
} |
449 |
return toolsPanel;
|
450 |
} |
451 |
|
452 |
public JPanel getTableButtonsPanel() { |
453 |
if (tableButtonsPanel == null){ |
454 |
tableButtonsPanel = new JPanel(); |
455 |
tableButtonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
456 |
|
457 |
tableButtonsPanel.add(getNewButton()); |
458 |
|
459 |
tableButtonsPanel.add(getDeleteButton()); |
460 |
} |
461 |
return tableButtonsPanel;
|
462 |
} |
463 |
|
464 |
public JToggleButton getPointToolButton() { |
465 |
if (pointToolButton==null){ |
466 |
pointToolButton = new JToggleButton(); |
467 |
pointToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Point.png"))); |
468 |
} |
469 |
return pointToolButton;
|
470 |
} |
471 |
|
472 |
public JToggleButton getLineToolButton() { |
473 |
if (lineToolButton==null){ |
474 |
lineToolButton = new JToggleButton(); |
475 |
lineToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Line.png"))); |
476 |
} |
477 |
return lineToolButton;
|
478 |
} |
479 |
|
480 |
public JToggleButton getPolygonToolButton() { |
481 |
if (polygonToolButton ==null){ |
482 |
polygonToolButton = new JToggleButton(); |
483 |
polygonToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Poligon.png"))); |
484 |
} |
485 |
return polygonToolButton;
|
486 |
} |
487 |
|
488 |
public Cursor getToolCursor(){ |
489 |
return cursor;
|
490 |
} |
491 |
|
492 |
public View getView() { |
493 |
return view;
|
494 |
} |
495 |
|
496 |
/**
|
497 |
* Dibuja en la vista las ROIs que aparecen en la tabla.
|
498 |
*
|
499 |
*/
|
500 |
public void drawROIs() { |
501 |
Color geometryColor;
|
502 |
|
503 |
BufferedImage img = getMapControl().getImage();
|
504 |
Graphics2D gImag = (Graphics2D) img.getGraphics(); |
505 |
ViewPort vp = getMapControl().getViewPort(); |
506 |
try {
|
507 |
for (int i = 0; i < getTable().getRowCount(); i++){ |
508 |
geometryColor = (Color)getTable().getModel().getValueAt(i, 4); |
509 |
VectorialROI vROI = (VectorialROI)getRois().get(getTable().getTable().getJTable().getValueAt(i, 0));
|
510 |
|
511 |
for (Iterator iter = vROI.getGeometries().iterator(); iter.hasNext();) { |
512 |
IGeometry geometry = (IGeometry) iter.next(); |
513 |
|
514 |
ISymbol sym = SymbologyFactory.createDefaultSymbolByShapeType(geometry.getGeometryType(), geometryColor); |
515 |
geometry.draw(gImag, vp, sym,null);
|
516 |
} |
517 |
} |
518 |
getView().repaint(); |
519 |
} catch (NotInitializeException e) {
|
520 |
// TODO Auto-generated catch block
|
521 |
e.printStackTrace(); |
522 |
} |
523 |
} |
524 |
|
525 |
private HashMap getRoiGraphics() { |
526 |
if (roiGraphics == null) |
527 |
roiGraphics = new HashMap(); |
528 |
return roiGraphics;
|
529 |
} |
530 |
|
531 |
public void addROI(ROI roi) { |
532 |
getRois().put(roi.getName(), roi); |
533 |
getRoiGraphics().put(roi.getName(), new ArrayList()); |
534 |
} |
535 |
|
536 |
public ROI getROI(String roiName){ |
537 |
|
538 |
return (ROI)getRois().get(roiName);
|
539 |
} |
540 |
|
541 |
public void removeROI(String roiName){ |
542 |
getRois().remove(roiName); |
543 |
ArrayList roiGraphics = getRoiGraphics(roiName);
|
544 |
if (roiGraphics!=null){ |
545 |
for (int i = 0; i< roiGraphics.size(); i++) |
546 |
getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic)getRoiGraphics(roiName).get(i)); |
547 |
getMapControl().rePaintDirtyLayers(); |
548 |
getRoiGraphics().remove(roiName); |
549 |
} |
550 |
} |
551 |
|
552 |
public ArrayList getRoiGraphics(String roiName){ |
553 |
return (ArrayList)getRoiGraphics().get(roiName); |
554 |
} |
555 |
|
556 |
/**
|
557 |
* Borra de capa GraphicsLayer de mapContext los gr?ficos pertenecientes
|
558 |
* a las rois del panel. Si la GraphicsLayer se queda sin gr?ficos se eliminan
|
559 |
* tambien los s?mbolos de esta.
|
560 |
*/
|
561 |
public void clearRoiGraphics(){ |
562 |
for (Iterator iter = getRoiGraphics().values().iterator(); iter.hasNext();) { |
563 |
ArrayList fGraphics = (ArrayList) iter.next(); |
564 |
|
565 |
for (Iterator iterator = fGraphics.iterator(); iterator.hasNext();) { |
566 |
FGraphic fGraphic = (FGraphic) iterator.next(); |
567 |
getMapControl().getMapContext().getGraphicsLayer().removeGraphic(fGraphic); |
568 |
} |
569 |
} |
570 |
if(getMapControl().getMapContext().getGraphicsLayer().getNumGraphics()==0) |
571 |
getMapControl().getMapContext().getGraphicsLayer().clearSymbolsGraphics(); |
572 |
} |
573 |
|
574 |
public ArrayList getROIs() { |
575 |
return new ArrayList(getRois().values()); |
576 |
} |
577 |
} |