svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / roi / ui / ROIManagerPanel.java @ 14321
History | View | Annotate | Download (18 KB)
1 | 13221 | dguerrero | /* 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 | 13945 | dguerrero | import java.awt.Cursor; |
46 | 13221 | dguerrero | import java.awt.FlowLayout; |
47 | 14102 | gsdiego | import java.awt.Graphics2D; |
48 | 13945 | dguerrero | import java.awt.Image; |
49 | import java.awt.Point; |
||
50 | import java.awt.Toolkit; |
||
51 | 14102 | gsdiego | import java.awt.image.BufferedImage; |
52 | 14129 | gsdiego | import java.util.ArrayList; |
53 | 13918 | dguerrero | import java.util.HashMap; |
54 | 14102 | gsdiego | import java.util.Iterator; |
55 | 13221 | dguerrero | |
56 | 13918 | dguerrero | import javax.swing.ImageIcon; |
57 | 13221 | dguerrero | 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 | 13918 | dguerrero | import javax.swing.JToggleButton; |
63 | 13221 | dguerrero | import javax.swing.border.EmptyBorder; |
64 | import javax.swing.border.LineBorder; |
||
65 | 14223 | gsdiego | import javax.swing.table.DefaultTableModel; |
66 | 13221 | dguerrero | |
67 | 14102 | gsdiego | import org.gvsig.fmap.raster.grid.roi.VectorialROI; |
68 | 13918 | dguerrero | import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
69 | 13221 | dguerrero | import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
70 | import org.gvsig.gui.beans.table.TableContainer; |
||
71 | 14102 | gsdiego | import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
72 | 14223 | gsdiego | import org.gvsig.gui.beans.table.models.IModel; |
73 | 13918 | dguerrero | import org.gvsig.raster.buffer.BufferFactory; |
74 | import org.gvsig.raster.buffer.RasterBufferInvalidException; |
||
75 | import org.gvsig.raster.grid.Grid; |
||
76 | 14321 | gsdiego | import org.gvsig.raster.grid.roi.ROI; |
77 | 13339 | dguerrero | import org.gvsig.rastertools.roi.ui.listener.DrawMouseViewListener; |
78 | 13221 | dguerrero | import org.gvsig.rastertools.roi.ui.listener.ROIManagerPanelListener; |
79 | |||
80 | import com.iver.andami.PluginServices; |
||
81 | 13339 | dguerrero | import com.iver.cit.gvsig.fmap.MapControl; |
82 | 14102 | gsdiego | import com.iver.cit.gvsig.fmap.ViewPort; |
83 | 14223 | gsdiego | import com.iver.cit.gvsig.fmap.core.FShape; |
84 | 14102 | gsdiego | import com.iver.cit.gvsig.fmap.core.IGeometry; |
85 | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
||
86 | 14223 | gsdiego | 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 | 14102 | gsdiego | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
90 | 13221 | dguerrero | import com.iver.cit.gvsig.fmap.layers.FLayer; |
91 | 14223 | gsdiego | import com.iver.cit.gvsig.fmap.layers.GraphicLayer; |
92 | 14129 | gsdiego | import com.iver.cit.gvsig.fmap.rendering.FGraphic; |
93 | 13339 | dguerrero | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
94 | import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
||
95 | 13938 | dguerrero | import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
96 | 13339 | dguerrero | import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
97 | 13938 | dguerrero | import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
98 | 13339 | dguerrero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
99 | import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
||
100 | 13221 | dguerrero | |
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 | 14102 | gsdiego | private ROIManagerPanelListener listener = null; |
112 | 13221 | dguerrero | private JMenuBar menuBar = null; |
113 | private JPanel tablePanel = null; |
||
114 | private JPanel controlPanel = null; |
||
115 | 13918 | dguerrero | private JPanel tableButtonsPanel = null; |
116 | private JPanel toolsPanel = null; |
||
117 | 14102 | gsdiego | private TableContainer tableContainer = null; |
118 | 13221 | dguerrero | private JButton newButton = null; |
119 | private JButton deleteButton = null; |
||
120 | 13918 | dguerrero | private JToggleButton pointToolButton = null; |
121 | private JToggleButton lineToolButton = null; |
||
122 | private JToggleButton polygonToolButton = null; |
||
123 | 13221 | dguerrero | 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 | 13339 | dguerrero | private MapControl mapControl = null; |
131 | 14102 | gsdiego | private View view = null; |
132 | 14321 | gsdiego | private HashMap rois = null; |
133 | 14129 | gsdiego | private HashMap roiGraphics = null; |
134 | 13918 | dguerrero | private Grid grid = null; |
135 | private String pathToImages = "images/"; |
||
136 | 13945 | dguerrero | private Cursor cursor = null; |
137 | 13221 | dguerrero | |
138 | public ROIManagerPanel(ROIManagerDialog roiManagerDialog) {
|
||
139 | super();
|
||
140 | this.roiManagerDialog = roiManagerDialog;
|
||
141 | initialize(); |
||
142 | |||
143 | 13918 | dguerrero | |
144 | 13221 | dguerrero | } |
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 | 13918 | dguerrero | |
152 | 14102 | gsdiego | listener = new ROIManagerPanelListener(this); |
153 | 13918 | dguerrero | 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 | 14131 | gsdiego | getTable().getTable().getJTable().getModel().addTableModelListener(listener); |
161 | 13918 | dguerrero | |
162 | getPolygonToolButton().setSelected(true);
|
||
163 | setToolsEnabled(false);
|
||
164 | 13221 | dguerrero | } |
165 | |||
166 | 13918 | dguerrero | public void setToolsEnabled(boolean b) { |
167 | getPointToolButton().setEnabled(b); |
||
168 | getLineToolButton().setEnabled(b); |
||
169 | getPolygonToolButton().setEnabled(b); |
||
170 | } |
||
171 | |||
172 | 13221 | dguerrero | 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 | 13918 | dguerrero | public TableContainer getTable(){
|
194 | 14102 | gsdiego | if (tableContainer == null){ |
195 | 13221 | dguerrero | String[] columnNames = {PluginServices.getText(this, "nombre"), |
196 | 13938 | dguerrero | PluginServices.getText(this, "poligonos"), |
197 | PluginServices.getText(this, "lineas"), |
||
198 | PluginServices.getText(this, "puntos"), |
||
199 | 13221 | dguerrero | PluginServices.getText(this, "color")}; |
200 | 13938 | dguerrero | int[] columnWidths = {70,30,30,30, 110}; |
201 | 14102 | gsdiego | 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 | 13221 | dguerrero | } |
207 | 14102 | gsdiego | return tableContainer;
|
208 | 13221 | dguerrero | } |
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 | 13918 | dguerrero | tablePanel.add(getTable(),BorderLayout.CENTER);
|
216 | 13221 | dguerrero | 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 | 13918 | dguerrero | controlPanel.add(getTableButtonsPanel()); |
227 | 13221 | dguerrero | |
228 | 13918 | dguerrero | controlPanel.add(getToolsPanel()); |
229 | //controlPanel.add(getToolBar());
|
||
230 | 13221 | dguerrero | } |
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 | 13918 | dguerrero | FLyrRasterSE rasterLayer = (FLyrRasterSE)layer; |
301 | 13339 | dguerrero | |
302 | 13918 | dguerrero | 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 | 14102 | gsdiego | view = (View) PluginServices.getMDIManager().getActiveWindow();
|
315 | 13339 | dguerrero | 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 | 13918 | dguerrero | DrawMouseViewListener drawMouseViewListener = new DrawMouseViewListener(this); |
322 | 13938 | dguerrero | mapControl.addMapTool("drawPolygonROI", new Behavior[] { |
323 | 13339 | dguerrero | new PolygonBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
324 | } |
||
325 | ); |
||
326 | 13938 | dguerrero | 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 | 14102 | gsdiego | mapControl.getMapContext().addLayerDrawingListener(listener); |
335 | 14223 | gsdiego | /*
|
336 | * Caragar las ROIs asociadas a la capa, si las hay:
|
||
337 | */
|
||
338 | 14243 | gsdiego | clearROIs(); |
339 | 14223 | gsdiego | loadROIs(); |
340 | 13221 | dguerrero | } |
341 | 13339 | dguerrero | |
342 | 14243 | gsdiego | 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 | 14321 | gsdiego | getRois().clear(); |
351 | 14243 | gsdiego | } |
352 | |||
353 | 14223 | gsdiego | /**
|
354 | * Cargar las Capas asociadas a la capa, si las hay.
|
||
355 | *
|
||
356 | */
|
||
357 | private void loadROIs() { |
||
358 | 14321 | gsdiego | ArrayList roisArray = ((FLyrRasterSE)fLayer).getRois();
|
359 | if (roisArray != null){ |
||
360 | 14223 | gsdiego | GraphicLayer graphicLayer = getMapControl().getMapContext().getGraphicsLayer(); |
361 | ISymbol symbol = null;
|
||
362 | FGraphic fGraphic = null;
|
||
363 | int nPoints, nPolygons, nLines;
|
||
364 | |||
365 | 14321 | gsdiego | for (Iterator iter = roisArray.iterator(); iter.hasNext();) { |
366 | 14223 | gsdiego | nPoints = 0; nPolygons = 0; nLines = 0; |
367 | |||
368 | 14321 | gsdiego | ROI roi = (ROI) iter.next(); |
369 | 14223 | gsdiego | |
370 | Object row [] = ((IModel)getTable().getModel()).getNewLine(); |
||
371 | 14321 | gsdiego | row[0]= roi.getName();
|
372 | row[4]= roi.getColor();
|
||
373 | 14223 | gsdiego | |
374 | 14321 | gsdiego | addROI(roi); |
375 | VectorialROI vectorialROI = (VectorialROI)roi; |
||
376 | 14223 | gsdiego | 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 | 14321 | gsdiego | ((IMarkerSymbol)symbol).setColor(roi.getColor()); |
382 | 14223 | gsdiego | nPoints++; |
383 | break;
|
||
384 | case FShape.POLYGON:
|
||
385 | symbol =SymbologyFactory.createDefaultFillSymbol(); |
||
386 | 14321 | gsdiego | ((IFillSymbol)symbol).setFillColor(roi.getColor()); |
387 | 14223 | gsdiego | nPolygons++; |
388 | break;
|
||
389 | case FShape.LINE:
|
||
390 | symbol =SymbologyFactory.createDefaultLineSymbol(); |
||
391 | 14321 | gsdiego | ((ILineSymbol)symbol).setLineColor(roi.getColor()); |
392 | 14223 | gsdiego | nLines++; |
393 | break;
|
||
394 | } |
||
395 | fGraphic = new FGraphic(geometry,graphicLayer.addSymbol(symbol));
|
||
396 | graphicLayer.addGraphic(fGraphic); |
||
397 | 14321 | gsdiego | getRoiGraphics(roi.getName()).add(fGraphic); |
398 | 14223 | gsdiego | } |
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 | 13339 | dguerrero | public MapControl getMapControl() {
|
409 | return mapControl;
|
||
410 | } |
||
411 | |||
412 | public void selectDrawRoiTool(){ |
||
413 | 13918 | dguerrero | if (mapControl!=null) |
414 | 13945 | dguerrero | 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 | 13938 | dguerrero | mapControl.setTool("drawPolygonROI");
|
418 | 13945 | dguerrero | } |
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 | 13938 | dguerrero | mapControl.setTool("drawLineROI");
|
423 | 13945 | dguerrero | } |
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 | 13938 | dguerrero | mapControl.setTool("drawPointROI");
|
428 | 13945 | dguerrero | } |
429 | 13339 | dguerrero | } |
430 | 13945 | dguerrero | |
431 | 13918 | dguerrero | public Grid getGrid() {
|
432 | return grid;
|
||
433 | } |
||
434 | 14223 | gsdiego | |
435 | 14321 | gsdiego | private HashMap getRois() { |
436 | if (rois == null) |
||
437 | rois = new HashMap(); |
||
438 | return rois;
|
||
439 | 13918 | dguerrero | } |
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 | 13945 | dguerrero | |
488 | public Cursor getToolCursor(){ |
||
489 | return cursor;
|
||
490 | } |
||
491 | 14102 | gsdiego | |
492 | public View getView() { |
||
493 | return view;
|
||
494 | } |
||
495 | |||
496 | 14223 | gsdiego | /**
|
497 | * Dibuja en la vista las ROIs que aparecen en la tabla.
|
||
498 | *
|
||
499 | */
|
||
500 | 14102 | gsdiego | 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 | 14321 | gsdiego | VectorialROI vROI = (VectorialROI)getRois().get(getTable().getTable().getJTable().getValueAt(i, 0));
|
510 | 14102 | gsdiego | |
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 | 14129 | gsdiego | |
525 | private HashMap getRoiGraphics() { |
||
526 | if (roiGraphics == null) |
||
527 | roiGraphics = new HashMap(); |
||
528 | return roiGraphics;
|
||
529 | } |
||
530 | |||
531 | 14321 | gsdiego | public void addROI(ROI roi) { |
532 | getRois().put(roi.getName(), roi); |
||
533 | getRoiGraphics().put(roi.getName(), new ArrayList()); |
||
534 | 14129 | gsdiego | } |
535 | |||
536 | 14321 | gsdiego | public ROI getROI(String roiName){ |
537 | 14167 | gsdiego | |
538 | 14321 | gsdiego | return (ROI)getRois().get(roiName);
|
539 | 14129 | gsdiego | } |
540 | |||
541 | public void removeROI(String roiName){ |
||
542 | 14321 | gsdiego | getRois().remove(roiName); |
543 | 14225 | gsdiego | 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 | 14129 | gsdiego | } |
551 | |||
552 | public ArrayList getRoiGraphics(String roiName){ |
||
553 | return (ArrayList)getRoiGraphics().get(roiName); |
||
554 | } |
||
555 | 14167 | gsdiego | |
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 | 14223 | gsdiego | |
574 | public ArrayList getROIs() { |
||
575 | 14321 | gsdiego | return new ArrayList(getRois().values()); |
576 | 14223 | gsdiego | } |
577 | 13221 | dguerrero | } |