svn-gvsig-desktop / branches / v2_0_0_prep / extensions / extRasterTools-SE / src / org / gvsig / rastertools / roi / ui / ROIsTablePanel.java @ 30043
History | View | Annotate | Download (20.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.rastertools.roi.ui; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.Color; |
45 |
import java.awt.FlowLayout; |
46 |
import java.awt.Image; |
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.ImageIcon; |
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JPanel; |
55 |
import javax.swing.JToggleButton; |
56 |
import javax.swing.border.EmptyBorder; |
57 |
import javax.swing.border.LineBorder; |
58 |
import javax.swing.table.DefaultTableModel; |
59 |
|
60 |
import org.gvsig.andami.PluginServices; |
61 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
62 |
import org.gvsig.app.project.documents.view.gui.BaseView; |
63 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
64 |
import org.gvsig.fmap.geom.Geometry; |
65 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
66 |
import org.gvsig.fmap.mapcontext.layers.GraphicLayer; |
67 |
import org.gvsig.fmap.mapcontext.rendering.legend.FGraphic; |
68 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol; |
69 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
70 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol; |
71 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
72 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
73 |
import org.gvsig.fmap.mapcontrol.MapControl; |
74 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
75 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
76 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
77 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolygonBehavior; |
78 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PolylineBehavior; |
79 |
import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
80 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
81 |
import org.gvsig.gui.beans.table.TableContainer; |
82 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
83 |
import org.gvsig.gui.beans.table.models.IModel; |
84 |
import org.gvsig.raster.buffer.BufferFactory; |
85 |
import org.gvsig.raster.buffer.RasterBuffer; |
86 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
87 |
import org.gvsig.raster.dataset.IRasterDataSource; |
88 |
import org.gvsig.raster.grid.Grid; |
89 |
import org.gvsig.raster.grid.GridException; |
90 |
import org.gvsig.raster.grid.roi.ROI; |
91 |
import org.gvsig.raster.util.RasterToolsUtil; |
92 |
import org.gvsig.rastertools.roi.ui.listener.DrawMouseViewListener; |
93 |
import org.gvsig.rastertools.roi.ui.listener.ROIsTablePanelListener; |
94 |
|
95 |
|
96 |
/**
|
97 |
* Panel con la tabla de ROIs.
|
98 |
*
|
99 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
100 |
*
|
101 |
*/
|
102 |
public class ROIsTablePanel extends JPanel { |
103 |
private static final long serialVersionUID = 2138437448356198224L; |
104 |
|
105 |
private ROIsManagerPanel managerPanel;
|
106 |
|
107 |
private ROIsTablePanelListener listener = null; |
108 |
|
109 |
private JPanel controlPanel = null; |
110 |
|
111 |
private JPanel tableButtonsPanel = null; |
112 |
|
113 |
private JPanel toolsPanel = null; |
114 |
|
115 |
private TableContainer tableContainer = null; |
116 |
|
117 |
private JButton newButton = null; |
118 |
|
119 |
private JButton deleteButton = null; |
120 |
|
121 |
private JButton exportButton = null; |
122 |
|
123 |
private JButton importButton = null; |
124 |
|
125 |
private JToggleButton pointToolButton = null; |
126 |
|
127 |
private JToggleButton lineToolButton = null; |
128 |
|
129 |
private JToggleButton polygonToolButton = null; |
130 |
|
131 |
private FLayer fLayer = null; |
132 |
|
133 |
private MapControl mapControl = null; |
134 |
|
135 |
private BaseView view = null; |
136 |
|
137 |
private GraphicLayer graphicLayer = null; |
138 |
|
139 |
private LinkedHashMap rois = null; |
140 |
|
141 |
private HashMap roiGraphics = null; |
142 |
|
143 |
private Grid grid = null; |
144 |
|
145 |
private String pathToImages = "images/"; |
146 |
|
147 |
private Image curImage = null; |
148 |
|
149 |
private String previousTool = null; |
150 |
|
151 |
public ROIsTablePanel(ROIsManagerPanel managerPanel) {
|
152 |
super();
|
153 |
|
154 |
this.managerPanel = managerPanel;
|
155 |
setBorder(new LineBorder(Color.GRAY)); |
156 |
setLayout(new BorderLayout()); |
157 |
add(getTable(), BorderLayout.CENTER);
|
158 |
add(getControlPanel(), BorderLayout.SOUTH);
|
159 |
|
160 |
initialize(); |
161 |
} |
162 |
|
163 |
private void initialize() { |
164 |
listener = new ROIsTablePanelListener(this); |
165 |
getNewButton().addActionListener(listener); |
166 |
getDeleteButton().addActionListener(listener); |
167 |
getImportButton().addActionListener(listener); |
168 |
getExportButton().addActionListener(listener); |
169 |
getPointToolButton().addActionListener(listener); |
170 |
getLineToolButton().addActionListener(listener); |
171 |
getPolygonToolButton().addActionListener(listener); |
172 |
|
173 |
getTable().getTable().getJTable().getSelectionModel() |
174 |
.addListSelectionListener(listener); |
175 |
getTable().getTable().getJTable().getModel().addTableModelListener( |
176 |
listener); |
177 |
|
178 |
getPolygonToolButton().setSelected(true);
|
179 |
setToolsEnabled(false);
|
180 |
} |
181 |
|
182 |
public ROIsManagerPanel getManagerPanel() {
|
183 |
return managerPanel;
|
184 |
} |
185 |
|
186 |
public void setToolsEnabled(boolean b) { |
187 |
getPointToolButton().setEnabled(b); |
188 |
getLineToolButton().setEnabled(b); |
189 |
getPolygonToolButton().setEnabled(b); |
190 |
} |
191 |
|
192 |
public TableContainer getTable() {
|
193 |
if (tableContainer == null) { |
194 |
String[] columnNames = { PluginServices.getText(this, "nombre"), |
195 |
PluginServices.getText(this, "poligonos"), |
196 |
PluginServices.getText(this, "lineas"), |
197 |
PluginServices.getText(this, "puntos"), |
198 |
PluginServices.getText(this, "color")}; |
199 |
int[] columnWidths = { 50, 25, 25, 25, 45}; |
200 |
tableContainer = new TableContainer(columnNames, columnWidths);
|
201 |
tableContainer.setModel("ROIsTableModel");
|
202 |
tableContainer.initialize(); |
203 |
tableContainer.setControlVisible(false);
|
204 |
tableContainer.setBorder(new EmptyBorder(5, 5, 0, 5)); |
205 |
} |
206 |
return tableContainer;
|
207 |
} |
208 |
|
209 |
public JPanel getControlPanel() { |
210 |
if (controlPanel == null) { |
211 |
controlPanel = new JPanel(); |
212 |
controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
213 |
|
214 |
controlPanel.add(getTableButtonsPanel()); |
215 |
|
216 |
controlPanel.add(getToolsPanel()); |
217 |
} |
218 |
return controlPanel;
|
219 |
} |
220 |
|
221 |
public JButton getDeleteButton() { |
222 |
if (deleteButton == null) { |
223 |
deleteButton = new JButton(PluginServices.getText(this, "borrar")); |
224 |
} |
225 |
return deleteButton;
|
226 |
} |
227 |
|
228 |
public JButton getNewButton() { |
229 |
if (newButton == null) { |
230 |
newButton = new JButton(PluginServices.getText(this, "nuevo")); |
231 |
} |
232 |
return newButton;
|
233 |
} |
234 |
|
235 |
public FLayer getFLayer() {
|
236 |
return fLayer;
|
237 |
} |
238 |
|
239 |
public void setFLayer(FLayer layer) throws GridException { |
240 |
fLayer = layer; |
241 |
/*FLyrRasterSE rasterLayer = (FLyrRasterSE) layer;
|
242 |
IRasterDataSource dsetCopy = null;
|
243 |
dsetCopy = rasterLayer.getDataSource().newDataset();
|
244 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
245 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
246 |
bufferFactory.setReadOnly(true);
|
247 |
bufferFactory.setAllDrawableBands();
|
248 |
|
249 |
int bands[] = null;
|
250 |
bands = new int[rasterLayer.getBandCount()];
|
251 |
for (int i = 0; i < rasterLayer.getBandCount(); i++)
|
252 |
bands[i] = i;
|
253 |
try {
|
254 |
grid = new Grid(bufferFactory, bands);
|
255 |
} catch (RasterBufferInvalidException e) {
|
256 |
e.printStackTrace();
|
257 |
}*/
|
258 |
|
259 |
if (view==null){ |
260 |
IWindow[] list = PluginServices.getMDIManager().getAllWindows();
|
261 |
for (int i = 0; i < list.length; i++) { |
262 |
if(list[i] instanceof BaseView) |
263 |
view = (BaseView)list[i]; |
264 |
} |
265 |
if (view == null) |
266 |
return;
|
267 |
mapControl = view.getMapControl(); |
268 |
graphicLayer = view.getMapControl().getMapContext().getGraphicsLayer(); |
269 |
|
270 |
/*
|
271 |
* Guardar la herramienta actual para recuperarla m?s tarde, por ejemplo
|
272 |
* al cerrar el contenedor del este panel.
|
273 |
*/
|
274 |
previousTool = mapControl.getCurrentTool(); |
275 |
|
276 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n
|
277 |
// en la barra de estado
|
278 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
279 |
|
280 |
DrawMouseViewListener drawMouseViewListener = new DrawMouseViewListener(
|
281 |
this);
|
282 |
mapControl.addMapTool("drawPolygonROI", new Behavior[] { |
283 |
new PolygonBehavior(drawMouseViewListener),
|
284 |
new MouseMovementBehavior(sbl) });
|
285 |
mapControl.addMapTool("drawLineROI", new Behavior[] { |
286 |
new PolylineBehavior(drawMouseViewListener),
|
287 |
new MouseMovementBehavior(sbl) });
|
288 |
mapControl.addMapTool("drawPointROI", new Behavior[] { |
289 |
new PointBehavior(drawMouseViewListener),
|
290 |
new MouseMovementBehavior(sbl) });
|
291 |
} |
292 |
|
293 |
/*
|
294 |
* Caragar las ROIs asociadas a la capa, si las hay:
|
295 |
*/
|
296 |
clearROIs(); |
297 |
loadROIs(); |
298 |
} |
299 |
|
300 |
/**
|
301 |
* Elimina todas las filas de la tabla de rois as? como la ROI y objetos
|
302 |
* FGraphic asociados (borr?ndolos tambi?n de la vista) a cada una.
|
303 |
*
|
304 |
*/
|
305 |
public void clearROIs() { |
306 |
boolean repaint = false; |
307 |
try {
|
308 |
getTable().removeAllRows(); |
309 |
} catch (NotInitializeException e) {
|
310 |
RasterToolsUtil.messageBoxError("error_tabla_rois", this, e); |
311 |
} |
312 |
for (Iterator iter = getRoiGraphics().values().iterator(); iter.hasNext();) { |
313 |
ArrayList roiGraphics = (ArrayList) iter.next(); |
314 |
for (int i = 0; i < roiGraphics.size(); i++){ |
315 |
getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic)roiGraphics.get(i)); |
316 |
repaint = true;
|
317 |
} |
318 |
} |
319 |
if (repaint)
|
320 |
getMapControl().rePaintDirtyLayers(); |
321 |
getRoiGraphics().clear(); |
322 |
getRois().clear(); |
323 |
} |
324 |
|
325 |
/**
|
326 |
* Cargar las ROIs asociadas a la capa, si las hay.
|
327 |
* @throws GridException
|
328 |
*
|
329 |
*/
|
330 |
private void loadROIs() throws GridException { |
331 |
ArrayList roisArray = ((FLyrRasterSE) fLayer).getRois();
|
332 |
if (roisArray != null) { |
333 |
GraphicLayer graphicLayer = getMapControl().getMapContext() |
334 |
.getGraphicsLayer(); |
335 |
ISymbol symbol = null;
|
336 |
FGraphic fGraphic = null;
|
337 |
int nPoints, nPolygons, nLines;
|
338 |
|
339 |
for (Iterator iter = roisArray.iterator(); iter.hasNext();) { |
340 |
ROI roi = (ROI) iter.next(); |
341 |
|
342 |
nPoints = 0;
|
343 |
nPolygons = 0;
|
344 |
nLines = 0;
|
345 |
|
346 |
Object row[] = ((IModel) getTable().getModel()).getNewLine(); |
347 |
row[0] = roi.getName();
|
348 |
row[4] = roi.getColor();
|
349 |
|
350 |
addROI(roi); |
351 |
VectorialROI vectorialROI = (VectorialROI) roi; |
352 |
for (Iterator iterator = vectorialROI.getGeometries() |
353 |
.iterator(); iterator.hasNext();) { |
354 |
Geometry geometry = (Geometry) iterator.next(); |
355 |
switch (geometry.getType()) {
|
356 |
case Geometry.TYPES.POINT:
|
357 |
symbol = SymbologyFactory.createDefaultMarkerSymbol(); |
358 |
((IMarkerSymbol) symbol).setColor(roi.getColor()); |
359 |
nPoints++; |
360 |
break;
|
361 |
case Geometry.TYPES.SURFACE:
|
362 |
symbol = SymbologyFactory.createDefaultFillSymbol(); |
363 |
((IFillSymbol) symbol).setFillColor(roi.getColor()); |
364 |
nPolygons++; |
365 |
break;
|
366 |
case Geometry.TYPES.CURVE:
|
367 |
symbol = SymbologyFactory.createDefaultLineSymbol(); |
368 |
((ILineSymbol) symbol).setLineColor(roi.getColor()); |
369 |
nLines++; |
370 |
break;
|
371 |
} |
372 |
fGraphic = new FGraphic(geometry, graphicLayer
|
373 |
.addSymbol(symbol)); |
374 |
graphicLayer.addGraphic(fGraphic); |
375 |
getRoiGraphics(roi.getName()).add(fGraphic); |
376 |
} |
377 |
row[1] = new Integer(nPolygons); |
378 |
row[2] = new Integer(nLines); |
379 |
row[3] = new Integer(nPoints); |
380 |
row[5] = new Integer(roi.getValues()); |
381 |
((DefaultTableModel) getTable().getModel()).addRow(row);
|
382 |
} |
383 |
selectDrawRoiTool(); |
384 |
getMapControl().drawGraphics(); |
385 |
} |
386 |
} |
387 |
|
388 |
public void setROIs(ArrayList roisArray) throws GridException{ |
389 |
if (roisArray != null) { |
390 |
rois = new LinkedHashMap(); |
391 |
GraphicLayer graphicLayer = getMapControl().getMapContext() |
392 |
.getGraphicsLayer(); |
393 |
ISymbol symbol = null;
|
394 |
FGraphic fGraphic = null;
|
395 |
int nPoints, nPolygons, nLines;
|
396 |
|
397 |
for (Iterator iter = roisArray.iterator(); iter.hasNext();) { |
398 |
ROI roi = (ROI) iter.next(); |
399 |
|
400 |
nPoints = 0;
|
401 |
nPolygons = 0;
|
402 |
nLines = 0;
|
403 |
|
404 |
Object row[] = ((IModel) getTable().getModel()).getNewLine(); |
405 |
row[0] = roi.getName();
|
406 |
row[4] = roi.getColor();
|
407 |
|
408 |
addROI(roi); |
409 |
VectorialROI vectorialROI = (VectorialROI) roi; |
410 |
for (Iterator iterator = vectorialROI.getGeometries() |
411 |
.iterator(); iterator.hasNext();) { |
412 |
Geometry geometry = (Geometry) iterator.next(); |
413 |
switch (geometry.getType()) {
|
414 |
case Geometry.TYPES.POINT:
|
415 |
symbol = SymbologyFactory.createDefaultMarkerSymbol(); |
416 |
((IMarkerSymbol) symbol).setColor(roi.getColor()); |
417 |
nPoints++; |
418 |
break;
|
419 |
case Geometry.TYPES.SURFACE:
|
420 |
symbol = SymbologyFactory.createDefaultFillSymbol(); |
421 |
((IFillSymbol) symbol).setFillColor(roi.getColor()); |
422 |
nPolygons++; |
423 |
break;
|
424 |
case Geometry.TYPES.CURVE:
|
425 |
symbol = SymbologyFactory.createDefaultLineSymbol(); |
426 |
((ILineSymbol) symbol).setLineColor(roi.getColor()); |
427 |
nLines++; |
428 |
break;
|
429 |
} |
430 |
fGraphic = new FGraphic(geometry, graphicLayer
|
431 |
.addSymbol(symbol)); |
432 |
graphicLayer.addGraphic(fGraphic); |
433 |
getRoiGraphics(roi.getName()).add(fGraphic); |
434 |
} |
435 |
row[1] = new Integer(nPolygons); |
436 |
row[2] = new Integer(nLines); |
437 |
row[3] = new Integer(nPoints); |
438 |
row[5] = new Integer(roi.getValues()); |
439 |
((DefaultTableModel) getTable().getModel()).addRow(row);
|
440 |
} |
441 |
selectDrawRoiTool(); |
442 |
getMapControl().drawGraphics(); |
443 |
} |
444 |
} |
445 |
|
446 |
public MapControl getMapControl() {
|
447 |
return mapControl;
|
448 |
} |
449 |
|
450 |
public void selectDrawRoiTool() { |
451 |
if (mapControl != null) |
452 |
if (getPolygonToolButton().isSelected()) {
|
453 |
Image img = new ImageIcon(getClass().getResource( |
454 |
"images/PoligonCursor.png")).getImage();
|
455 |
curImage = img; |
456 |
mapControl.setTool("drawPolygonROI");
|
457 |
} else if (getLineToolButton().isSelected()) { |
458 |
Image img = new ImageIcon(getClass().getResource( |
459 |
"images/LineCursor.png")).getImage();
|
460 |
curImage = img; |
461 |
mapControl.setTool("drawLineROI");
|
462 |
} else if (getPointToolButton().isSelected()) { |
463 |
Image img = new ImageIcon(getClass().getResource( |
464 |
"images/PointCursor.png")).getImage();
|
465 |
curImage = img; |
466 |
mapControl.setTool("drawPointROI");
|
467 |
} |
468 |
} |
469 |
|
470 |
public Grid getGrid() {
|
471 |
if(grid == null) { |
472 |
FLyrRasterSE rasterLayer = (FLyrRasterSE) getFLayer(); |
473 |
IRasterDataSource dsetCopy = null;
|
474 |
dsetCopy = rasterLayer.getDataSource().newDataset(); |
475 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
476 |
bufferFactory.setReadOnly(true);
|
477 |
bufferFactory.setAllDrawableBands(); |
478 |
|
479 |
int bands[] = null; |
480 |
bands = new int[rasterLayer.getBandCount()]; |
481 |
for (int i = 0; i < rasterLayer.getBandCount(); i++) |
482 |
bands[i] = i; |
483 |
try {
|
484 |
grid = new Grid(bufferFactory, bands);
|
485 |
} catch (RasterBufferInvalidException e) {
|
486 |
e.printStackTrace(); |
487 |
} |
488 |
} |
489 |
return grid;
|
490 |
} |
491 |
|
492 |
private LinkedHashMap getRois() { |
493 |
if (rois == null) |
494 |
rois = new LinkedHashMap(); |
495 |
return rois;
|
496 |
} |
497 |
|
498 |
public JPanel getToolsPanel() { |
499 |
if (toolsPanel == null) { |
500 |
toolsPanel = new JPanel(); |
501 |
toolsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
502 |
toolsPanel.add(getPointToolButton()); |
503 |
toolsPanel.add(getLineToolButton()); |
504 |
toolsPanel.add(getPolygonToolButton()); |
505 |
toolsPanel.add(getExportButton()); |
506 |
toolsPanel.add(getImportButton()); |
507 |
} |
508 |
return toolsPanel;
|
509 |
} |
510 |
|
511 |
public JPanel getTableButtonsPanel() { |
512 |
if (tableButtonsPanel == null) { |
513 |
tableButtonsPanel = new JPanel(); |
514 |
tableButtonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
515 |
|
516 |
tableButtonsPanel.add(getNewButton()); |
517 |
|
518 |
tableButtonsPanel.add(getDeleteButton()); |
519 |
} |
520 |
return tableButtonsPanel;
|
521 |
} |
522 |
|
523 |
public JToggleButton getPointToolButton() { |
524 |
if (pointToolButton == null) { |
525 |
pointToolButton = new JToggleButton(); |
526 |
pointToolButton.setIcon(new ImageIcon(getClass().getResource( |
527 |
pathToImages + "Point.png")));
|
528 |
} |
529 |
return pointToolButton;
|
530 |
} |
531 |
|
532 |
public JToggleButton getLineToolButton() { |
533 |
if (lineToolButton == null) { |
534 |
lineToolButton = new JToggleButton(); |
535 |
lineToolButton.setIcon(new ImageIcon(getClass().getResource( |
536 |
pathToImages + "Line.png")));
|
537 |
} |
538 |
return lineToolButton;
|
539 |
} |
540 |
|
541 |
public JToggleButton getPolygonToolButton() { |
542 |
if (polygonToolButton == null) { |
543 |
polygonToolButton = new JToggleButton(); |
544 |
polygonToolButton.setIcon(new ImageIcon(getClass().getResource( |
545 |
pathToImages + "Poligon.png")));
|
546 |
} |
547 |
return polygonToolButton;
|
548 |
} |
549 |
|
550 |
public JButton getImportButton() { |
551 |
if (importButton == null) { |
552 |
importButton = new JButton(); |
553 |
importButton.setIcon(PluginServices.getIconTheme().get("tfwload-icon"));
|
554 |
importButton.setToolTipText(PluginServices.getText(this,"cargar_rois")); |
555 |
} |
556 |
return importButton;
|
557 |
} |
558 |
|
559 |
public JButton getExportButton() { |
560 |
if (exportButton == null) { |
561 |
exportButton = new JButton(); |
562 |
exportButton.setIcon(PluginServices.getIconTheme().get("save-icon"));
|
563 |
exportButton.setToolTipText(PluginServices.getText(this,"salvar_rois")); |
564 |
} |
565 |
return exportButton;
|
566 |
} |
567 |
|
568 |
public Image getToolImage() { |
569 |
return curImage;
|
570 |
} |
571 |
|
572 |
public BaseView getView() {
|
573 |
return view;
|
574 |
} |
575 |
|
576 |
|
577 |
/* public void drawROIs() {
|
578 |
Color geometryColor;
|
579 |
|
580 |
BufferedImage img = getMapControl().getImage();
|
581 |
Graphics2D gImag = (Graphics2D) img.getGraphics();
|
582 |
ViewPort vp = getMapControl().getViewPort();
|
583 |
try {
|
584 |
for (int i = 0; i < getTable().getRowCount(); i++) {
|
585 |
geometryColor = (Color) getTable().getModel().getValueAt(i, 4);
|
586 |
VectorialROI vROI = (VectorialROI) getRois().get(
|
587 |
getTable().getTable().getJTable().getValueAt(i, 0));
|
588 |
|
589 |
for (Iterator iter = vROI.getGeometries().iterator(); iter
|
590 |
.hasNext();) {
|
591 |
IGeometry geometry = (IGeometry) iter.next();
|
592 |
|
593 |
ISymbol sym = SymbologyFactory
|
594 |
.createDefaultSymbolByShapeType(geometry
|
595 |
.getGeometryType(), geometryColor);
|
596 |
geometry.draw(gImag, vp, sym, null);
|
597 |
}
|
598 |
}
|
599 |
getView().repaint();
|
600 |
} catch (NotInitializeException e) {
|
601 |
// TODO Auto-generated catch block
|
602 |
e.printStackTrace();
|
603 |
}
|
604 |
}
|
605 |
*/
|
606 |
|
607 |
private HashMap getRoiGraphics() { |
608 |
if (roiGraphics == null) |
609 |
roiGraphics = new HashMap(); |
610 |
return roiGraphics;
|
611 |
} |
612 |
|
613 |
public void addROI(ROI roi) { |
614 |
getRois().put(roi.getName(), roi); |
615 |
getRoiGraphics().put(roi.getName(), new ArrayList()); |
616 |
} |
617 |
|
618 |
public ROI getROI(String roiName) { |
619 |
|
620 |
return (ROI) getRois().get(roiName);
|
621 |
} |
622 |
|
623 |
/**
|
624 |
* Elimina la ROI correspondiente al nombre <code>roiName</code> as?
|
625 |
* como sus objetos FGraphic asociados (borr?ndolos tambi?n de la vista).
|
626 |
* (NO elimina la fila correspondiente en la tabla del panel).
|
627 |
*
|
628 |
* @param roiName Nombre de la ROI a eliminar.
|
629 |
*/
|
630 |
public void removeROI(String roiName) { |
631 |
boolean repaint = false; |
632 |
getRois().remove(roiName); |
633 |
ArrayList roiGraphics = getRoiGraphics(roiName);
|
634 |
if (roiGraphics != null) { |
635 |
for (int i = 0; i < roiGraphics.size(); i++){ |
636 |
getMapControl().getMapContext().getGraphicsLayer().removeGraphic((FGraphic) getRoiGraphics(roiName).get(i)); |
637 |
repaint = true;
|
638 |
} |
639 |
if (repaint)
|
640 |
getMapControl().rePaintDirtyLayers(); |
641 |
getRoiGraphics().remove(roiName); |
642 |
} |
643 |
} |
644 |
|
645 |
public ArrayList getRoiGraphics(String roiName) { |
646 |
return (ArrayList) getRoiGraphics().get(roiName); |
647 |
} |
648 |
|
649 |
/**
|
650 |
* Borra de capa GraphicsLayer de mapContext los gr?ficos pertenecientes a
|
651 |
* las rois del panel. Si la GraphicsLayer se queda sin gr?ficos se eliminan
|
652 |
* tambien los s?mbolos de esta.
|
653 |
*/
|
654 |
public void clearRoiGraphics() { |
655 |
for (Iterator iter = getRoiGraphics().values().iterator(); iter |
656 |
.hasNext();) { |
657 |
ArrayList fGraphics = (ArrayList) iter.next(); |
658 |
|
659 |
for (Iterator iterator = fGraphics.iterator(); iterator.hasNext();) { |
660 |
FGraphic fGraphic = (FGraphic) iterator.next(); |
661 |
getMapControl().getMapContext().getGraphicsLayer() |
662 |
.removeGraphic(fGraphic); |
663 |
} |
664 |
} |
665 |
if (getMapControl().getMapContext().getGraphicsLayer().getNumGraphics() == 0) |
666 |
getMapControl().getMapContext().getGraphicsLayer() |
667 |
.clearSymbolsGraphics(); |
668 |
} |
669 |
|
670 |
public ArrayList getROIs() { |
671 |
return new ArrayList(getRois().values()); |
672 |
} |
673 |
|
674 |
public void setPreviousTool() { |
675 |
if (previousTool != null) |
676 |
getMapControl().setTool(previousTool); |
677 |
} |
678 |
|
679 |
public void changeRoiName(String currentName, String newName) { |
680 |
getROI(currentName).setName(newName); |
681 |
getRois().put(newName, getRois().remove(currentName)); |
682 |
getRoiGraphics().put(newName, getRoiGraphics().remove(currentName)); |
683 |
} |
684 |
|
685 |
public void sortTable(){ |
686 |
|
687 |
} |
688 |
|
689 |
public GraphicLayer getGraphicLayer() {
|
690 |
return graphicLayer;
|
691 |
} |
692 |
} |