root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / roi / ui / ROIManagerPanel.java @ 13945
History | View | Annotate | Download (13 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.Image; |
48 |
import java.awt.Point; |
49 |
import java.awt.Toolkit; |
50 |
import java.util.HashMap; |
51 |
|
52 |
import javax.swing.ImageIcon; |
53 |
import javax.swing.JButton; |
54 |
import javax.swing.JMenu; |
55 |
import javax.swing.JMenuBar; |
56 |
import javax.swing.JMenuItem; |
57 |
import javax.swing.JPanel; |
58 |
import javax.swing.JToggleButton; |
59 |
import javax.swing.border.EmptyBorder; |
60 |
import javax.swing.border.LineBorder; |
61 |
|
62 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
63 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
64 |
import org.gvsig.gui.beans.table.TableContainer; |
65 |
import org.gvsig.raster.buffer.BufferFactory; |
66 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
67 |
import org.gvsig.raster.grid.Grid; |
68 |
import org.gvsig.rastertools.roi.ui.listener.DrawMouseViewListener; |
69 |
import org.gvsig.rastertools.roi.ui.listener.ROIManagerPanelListener; |
70 |
|
71 |
import com.iver.andami.PluginServices; |
72 |
import com.iver.cit.gvsig.fmap.MapControl; |
73 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
74 |
import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
75 |
import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
76 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PointBehavior; |
77 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolygonBehavior; |
78 |
import com.iver.cit.gvsig.fmap.tools.Behavior.PolylineBehavior; |
79 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
80 |
import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
81 |
|
82 |
/**
|
83 |
* Iterfazde usuario para la gesti?n de ROIs.
|
84 |
*
|
85 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
86 |
*
|
87 |
*/
|
88 |
public class ROIManagerPanel extends DefaultButtonsPanel { |
89 |
private static final long serialVersionUID = 2138437448356198224L; |
90 |
|
91 |
private ROIManagerDialog roiManagerDialog = null; |
92 |
private JMenuBar menuBar = null; |
93 |
private JPanel tablePanel = null; |
94 |
private JPanel controlPanel = null; |
95 |
private JPanel tableButtonsPanel = null; |
96 |
private JPanel toolsPanel = null; |
97 |
private TableContainer table = null; |
98 |
private JButton newButton = null; |
99 |
private JButton deleteButton = null; |
100 |
private JToggleButton pointToolButton = null; |
101 |
private JToggleButton lineToolButton = null; |
102 |
private JToggleButton polygonToolButton = null; |
103 |
private JMenuItem closeMenuItem = null; |
104 |
private JMenuItem saveMenuItem = null; |
105 |
private JMenuItem loadMenuItem = null; |
106 |
private JMenuItem exportMenuItem = null; |
107 |
private JMenuItem helpMenuItem = null; |
108 |
private JMenuItem preferencesMenuItem = null; |
109 |
private FLayer fLayer = null; |
110 |
private MapControl mapControl = null; |
111 |
private String viewName = null; |
112 |
private HashMap rois = null; |
113 |
private Grid grid = null; |
114 |
private String pathToImages = "images/"; |
115 |
private Cursor cursor = null; |
116 |
|
117 |
public ROIManagerPanel(ROIManagerDialog roiManagerDialog) {
|
118 |
super();
|
119 |
this.roiManagerDialog = roiManagerDialog;
|
120 |
initialize(); |
121 |
|
122 |
|
123 |
} |
124 |
|
125 |
private void initialize() { |
126 |
setLayout(new BorderLayout(5,5)); |
127 |
setBorder(new EmptyBorder(0,15,11,15)); |
128 |
add(getMenuBar(),BorderLayout.NORTH);
|
129 |
add(getTablePanel(),BorderLayout.CENTER);
|
130 |
|
131 |
ROIManagerPanelListener listener = new ROIManagerPanelListener(this); |
132 |
getCloseMenuItem().addActionListener(listener); |
133 |
getNewButton().addActionListener(listener); |
134 |
getDeleteButton().addActionListener(listener); |
135 |
getPointToolButton().addActionListener(listener); |
136 |
getLineToolButton().addActionListener(listener); |
137 |
getPolygonToolButton().addActionListener(listener); |
138 |
getTable().getTable().getJTable().getSelectionModel().addListSelectionListener(listener); |
139 |
|
140 |
getPolygonToolButton().setSelected(true);
|
141 |
setToolsEnabled(false);
|
142 |
} |
143 |
|
144 |
public void setToolsEnabled(boolean b) { |
145 |
getPointToolButton().setEnabled(b); |
146 |
getLineToolButton().setEnabled(b); |
147 |
getPolygonToolButton().setEnabled(b); |
148 |
} |
149 |
|
150 |
public JMenuBar getMenuBar() { |
151 |
if (menuBar==null){ |
152 |
menuBar = new JMenuBar(); |
153 |
menuBar.setBorder(new EmptyBorder(0,0,0,0)); |
154 |
JMenu fileMenu = new JMenu(PluginServices.getText(this, "archivo")); |
155 |
JMenu optionsMenu = new JMenu(PluginServices.getText(this, "opciones")); |
156 |
JMenu helpMenu = new JMenu(PluginServices.getText(this, "help")); |
157 |
|
158 |
fileMenu.add(getSaveMenuItem()); |
159 |
fileMenu.add(getLoadMenuItem()); |
160 |
fileMenu.add(getExportMenuItem()); |
161 |
fileMenu.add(getCloseMenuItem()); |
162 |
helpMenu.add(getHelpMenuItem()); |
163 |
optionsMenu.add(getPreferencesMenuItem()); |
164 |
menuBar.add(fileMenu); |
165 |
menuBar.add(optionsMenu); |
166 |
menuBar.add(helpMenu); |
167 |
} |
168 |
return menuBar;
|
169 |
} |
170 |
|
171 |
public TableContainer getTable(){
|
172 |
if (table == null){ |
173 |
String[] columnNames = {PluginServices.getText(this, "nombre"), |
174 |
PluginServices.getText(this, "poligonos"), |
175 |
PluginServices.getText(this, "lineas"), |
176 |
PluginServices.getText(this, "puntos"), |
177 |
PluginServices.getText(this, "color")}; |
178 |
int[] columnWidths = {70,30,30,30, 110}; |
179 |
table = new TableContainer(columnNames, columnWidths);
|
180 |
table.initialize(); |
181 |
table.setControlVisible(false);
|
182 |
table.setBorder(new EmptyBorder(5,5,0,5)); |
183 |
} |
184 |
return table;
|
185 |
} |
186 |
|
187 |
public JPanel getTablePanel() { |
188 |
if (tablePanel == null){ |
189 |
tablePanel = new JPanel(); |
190 |
tablePanel.setBorder(new LineBorder(Color.GRAY)); |
191 |
tablePanel.setLayout(new BorderLayout()); |
192 |
tablePanel.add(getTable(),BorderLayout.CENTER);
|
193 |
tablePanel.add(getControlPanel(),BorderLayout.SOUTH);
|
194 |
} |
195 |
return tablePanel;
|
196 |
} |
197 |
|
198 |
public JPanel getControlPanel() { |
199 |
if (controlPanel == null){ |
200 |
controlPanel = new JPanel(); |
201 |
controlPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
202 |
|
203 |
controlPanel.add(getTableButtonsPanel()); |
204 |
|
205 |
controlPanel.add(getToolsPanel()); |
206 |
//controlPanel.add(getToolBar());
|
207 |
} |
208 |
return controlPanel;
|
209 |
} |
210 |
|
211 |
public JButton getDeleteButton() { |
212 |
if (deleteButton == null){ |
213 |
deleteButton = new JButton(PluginServices.getText(this, "borrar")); |
214 |
} |
215 |
return deleteButton;
|
216 |
} |
217 |
|
218 |
public JButton getNewButton() { |
219 |
if (newButton == null){ |
220 |
newButton = new JButton(PluginServices.getText(this, "nuevo")); |
221 |
} |
222 |
return newButton;
|
223 |
} |
224 |
|
225 |
public JMenuItem getCloseMenuItem() { |
226 |
if (closeMenuItem == null){ |
227 |
closeMenuItem = new JMenuItem(PluginServices.getText(this, "cerrar")); |
228 |
} |
229 |
return closeMenuItem;
|
230 |
} |
231 |
|
232 |
public ROIManagerDialog getRoiManagerDialog() {
|
233 |
return roiManagerDialog;
|
234 |
} |
235 |
|
236 |
public JMenuItem getExportMenuItem() { |
237 |
if (helpMenuItem == null){ |
238 |
exportMenuItem = new JMenuItem(PluginServices.getText(this, "exportar")); |
239 |
} |
240 |
return exportMenuItem;
|
241 |
} |
242 |
|
243 |
public JMenuItem getHelpMenuItem() { |
244 |
if (helpMenuItem == null){ |
245 |
helpMenuItem = new JMenuItem(PluginServices.getText(this, "help")); |
246 |
} |
247 |
return helpMenuItem;
|
248 |
} |
249 |
|
250 |
public JMenuItem getLoadMenuItem() { |
251 |
if (loadMenuItem == null){ |
252 |
loadMenuItem = new JMenuItem(PluginServices.getText(this, "cargar")); |
253 |
} |
254 |
return loadMenuItem;
|
255 |
} |
256 |
|
257 |
public JMenuItem getSaveMenuItem() { |
258 |
if (saveMenuItem == null){ |
259 |
saveMenuItem = new JMenuItem(PluginServices.getText(this, "salvar")); |
260 |
} |
261 |
return saveMenuItem;
|
262 |
} |
263 |
|
264 |
public JMenuItem getPreferencesMenuItem() { |
265 |
if (preferencesMenuItem == null){ |
266 |
preferencesMenuItem = new JMenuItem(PluginServices.getText(this, "preferencias")); |
267 |
} |
268 |
return preferencesMenuItem;
|
269 |
} |
270 |
|
271 |
public FLayer getFLayer() {
|
272 |
return fLayer;
|
273 |
} |
274 |
|
275 |
public void setFLayer(FLayer layer) { |
276 |
fLayer = layer; |
277 |
FLyrRasterSE rasterLayer = (FLyrRasterSE)layer; |
278 |
|
279 |
BufferFactory dataSource = rasterLayer.getBufferFactory(); |
280 |
|
281 |
int bands[]=null; |
282 |
bands = new int [rasterLayer.getBandCount()]; |
283 |
for(int i=0; i<rasterLayer.getBandCount();i++) |
284 |
bands[i]=i; |
285 |
try {
|
286 |
grid = new Grid(dataSource, bands);
|
287 |
} catch (RasterBufferInvalidException e) {
|
288 |
e.printStackTrace(); |
289 |
} |
290 |
|
291 |
View view = (View) PluginServices.getMDIManager().getActiveWindow(); |
292 |
viewName = PluginServices.getMDIManager().getWindowInfo(view).getTitle(); |
293 |
mapControl = view.getMapControl(); |
294 |
|
295 |
// Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
296 |
// la barra de estado
|
297 |
StatusBarListener sbl = new StatusBarListener(mapControl);
|
298 |
|
299 |
DrawMouseViewListener drawMouseViewListener = new DrawMouseViewListener(this); |
300 |
mapControl.addMapTool("drawPolygonROI", new Behavior[] { |
301 |
new PolygonBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
302 |
} |
303 |
); |
304 |
mapControl.addMapTool("drawLineROI", new Behavior[] { |
305 |
new PolylineBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
306 |
} |
307 |
); |
308 |
mapControl.addMapTool("drawPointROI", new Behavior[] { |
309 |
new PointBehavior(drawMouseViewListener), new MouseMovementBehavior(sbl) |
310 |
} |
311 |
); |
312 |
} |
313 |
|
314 |
public MapControl getMapControl() {
|
315 |
return mapControl;
|
316 |
} |
317 |
|
318 |
public void selectDrawRoiTool(){ |
319 |
/*// seleccionamos la vista de gvSIG
|
320 |
com.iver.cit.gvsig.project.documents.view.gui.View theView = null;
|
321 |
try {
|
322 |
IWindow[] allViews = PluginServices.getMDIManager().getAllWindows();
|
323 |
for (int i = 0; i < allViews.length; i++) {
|
324 |
if (allViews[i] instanceof com.iver.cit.gvsig.project.documents.view.gui.View
|
325 |
&& PluginServices.getMDIManager().getWindowInfo((View) allViews[i])
|
326 |
.getTitle().equals(viewName))
|
327 |
theView = (com.iver.cit.gvsig.project.documents.view.gui.View) allViews[i];
|
328 |
}
|
329 |
if (theView == null)
|
330 |
return;
|
331 |
} catch (ClassCastException ex) {
|
332 |
// logger.error(PluginServices.getText(this, "cant_get_view "), ex);
|
333 |
return;
|
334 |
}
|
335 |
MapControl m_MapControl = theView.getMapControl();
|
336 |
*/
|
337 |
if (mapControl!=null) |
338 |
if (getPolygonToolButton().isSelected()){
|
339 |
Image img = new ImageIcon(getClass().getResource("images/PoligonCursor.png")).getImage(); |
340 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
341 |
mapControl.setTool("drawPolygonROI");
|
342 |
} |
343 |
else if (getLineToolButton().isSelected()){ |
344 |
Image img = new ImageIcon(getClass().getResource("images/LineCursor.png")).getImage(); |
345 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
346 |
mapControl.setTool("drawLineROI");
|
347 |
} |
348 |
else if (getPointToolButton().isSelected()){ |
349 |
Image img = new ImageIcon(getClass().getResource("images/PointCursor.png")).getImage(); |
350 |
cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(16, 16), ""); |
351 |
mapControl.setTool("drawPointROI");
|
352 |
} |
353 |
} |
354 |
|
355 |
public Grid getGrid() {
|
356 |
return grid;
|
357 |
} |
358 |
|
359 |
public HashMap getRois() { |
360 |
if (rois == null) |
361 |
rois = new HashMap(); |
362 |
return rois;
|
363 |
} |
364 |
|
365 |
public JPanel getToolsPanel() { |
366 |
if (toolsPanel==null){ |
367 |
toolsPanel = new JPanel(); |
368 |
toolsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
369 |
toolsPanel.add(getPointToolButton()); |
370 |
toolsPanel.add(getLineToolButton()); |
371 |
toolsPanel.add(getPolygonToolButton()); |
372 |
} |
373 |
return toolsPanel;
|
374 |
} |
375 |
|
376 |
public JPanel getTableButtonsPanel() { |
377 |
if (tableButtonsPanel == null){ |
378 |
tableButtonsPanel = new JPanel(); |
379 |
tableButtonsPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); |
380 |
|
381 |
tableButtonsPanel.add(getNewButton()); |
382 |
|
383 |
tableButtonsPanel.add(getDeleteButton()); |
384 |
} |
385 |
return tableButtonsPanel;
|
386 |
} |
387 |
|
388 |
public JToggleButton getPointToolButton() { |
389 |
if (pointToolButton==null){ |
390 |
pointToolButton = new JToggleButton(); |
391 |
pointToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Point.png"))); |
392 |
} |
393 |
return pointToolButton;
|
394 |
} |
395 |
|
396 |
public JToggleButton getLineToolButton() { |
397 |
if (lineToolButton==null){ |
398 |
lineToolButton = new JToggleButton(); |
399 |
lineToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Line.png"))); |
400 |
} |
401 |
return lineToolButton;
|
402 |
} |
403 |
|
404 |
public JToggleButton getPolygonToolButton() { |
405 |
if (polygonToolButton ==null){ |
406 |
polygonToolButton = new JToggleButton(); |
407 |
polygonToolButton.setIcon(new ImageIcon(getClass().getResource(pathToImages + "Poligon.png"))); |
408 |
} |
409 |
return polygonToolButton;
|
410 |
} |
411 |
|
412 |
public Cursor getToolCursor(){ |
413 |
return cursor;
|
414 |
} |
415 |
} |