gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / infobypoint / InfoByRasterPointExtension.java @ 1169
History | View | Annotate | Download (5.47 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.tools.app.basic.tool.infobypoint; |
23 |
|
24 |
import java.awt.Component; |
25 |
|
26 |
import javax.swing.JOptionPane; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.documents.view.ViewDocument; |
32 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
33 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
36 |
import org.gvsig.fmap.mapcontrol.MapControl; |
37 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
38 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
39 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
40 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
41 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
42 |
import org.gvsig.raster.tools.app.basic.tool.infobypoint.gui.InfoByPointDataModel; |
43 |
import org.gvsig.raster.tools.app.basic.tool.infobypoint.viewtool.InfoByPixelPointViewTool; |
44 |
import org.gvsig.raster.tools.app.basic.tool.infobypoint.viewtool.PixelInspectorViewTool; |
45 |
|
46 |
/**
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
48 |
*/
|
49 |
public class InfoByRasterPointExtension extends Extension { |
50 |
private InfoByPixelPointViewTool lastTool = null; |
51 |
public static Behavior oldBehavior = null; |
52 |
|
53 |
/*
|
54 |
* (non-Javadoc)
|
55 |
* @see org.gvsig.andami.plugins.IExtension#execute(java.lang.String)
|
56 |
*/
|
57 |
public void execute(String actionCommand) { |
58 |
if(actionCommand.compareTo("INFO_BY_PIXEL") == 0) { |
59 |
MapControl mapCtrl = getMapControl(); |
60 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
61 |
|
62 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
63 |
for (int i = 0; i < wList.length; i++) { |
64 |
if(wList[i] instanceof MainInfoByPointDialog) { |
65 |
JOptionPane.showMessageDialog(
|
66 |
(Component)wList[i],
|
67 |
PluginServices.getText(this, "open_window"), |
68 |
PluginServices.getText(this, "Information"), |
69 |
JOptionPane.INFORMATION_MESSAGE);
|
70 |
mapCtrl.addBehavior("infoByRasterPoint",
|
71 |
new Behavior[]{new PointBehavior(lastTool), |
72 |
new MouseMovementBehavior(sbl)});
|
73 |
mapCtrl.setTool("infoByRasterPoint");
|
74 |
return;
|
75 |
} |
76 |
} |
77 |
MainInfoByPointDialog dialog = new MainInfoByPointDialog();
|
78 |
InfoByPointDataModel model = dialog.getInfoByPointDataModel(); |
79 |
model.addObserver(dialog.getMainPanel()); |
80 |
|
81 |
lastTool = new InfoByPixelPointViewTool(mapCtrl, model);
|
82 |
mapCtrl.addBehavior("infoByRasterPoint",
|
83 |
new Behavior[]{new PointBehavior(lastTool), |
84 |
new MouseMovementBehavior(sbl)});
|
85 |
mapCtrl.setTool("infoByRasterPoint");
|
86 |
oldBehavior = CompoundBehavior.getAllControlsBehavior(); |
87 |
CompoundBehavior.setAllControlsBehavior(new PixelInspectorViewTool(mapCtrl, model, dialog.getPixelInspector()));
|
88 |
|
89 |
model.notifyObservers(); |
90 |
PluginServices.getMDIManager().addWindow(dialog); |
91 |
} |
92 |
} |
93 |
|
94 |
private MapControl getMapControl() {
|
95 |
IWindow theView = PluginServices.getMDIManager().getActiveWindow(); |
96 |
if(!(theView instanceof AbstractViewPanel)) { |
97 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid")); |
98 |
return null; |
99 |
} |
100 |
return ((AbstractViewPanel)theView).getMapControl();
|
101 |
} |
102 |
|
103 |
/*
|
104 |
* (non-Javadoc)
|
105 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
106 |
*/
|
107 |
@SuppressWarnings("deprecation") |
108 |
public boolean isEnabled() { |
109 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
110 |
if (f == null) |
111 |
return false; |
112 |
if (f instanceof AbstractViewPanel) { |
113 |
AbstractViewPanel vista = (AbstractViewPanel) f; |
114 |
ViewDocument model = vista.getModel(); |
115 |
MapContext mapa = model.getMapContext(); |
116 |
FLayers layers = mapa.getLayers(); |
117 |
for (int i = 0; i < layers.getLayersCount(); i++) |
118 |
if (layers.getLayer(i) instanceof FLyrRaster) { |
119 |
FLyrRaster lyr = (FLyrRaster)layers.getLayer(i); |
120 |
if(lyr.isActive())
|
121 |
return true; |
122 |
} |
123 |
} |
124 |
return false; |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @see org.gvsig.andami.plugins.IExtension#isVisible()
|
130 |
*/
|
131 |
public boolean isVisible() { |
132 |
return isEnabled();
|
133 |
} |
134 |
|
135 |
/*
|
136 |
* (non-Javadoc)
|
137 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
138 |
*/
|
139 |
public void initialize() { |
140 |
registerIcons(); |
141 |
} |
142 |
|
143 |
private void registerIcons() { |
144 |
PluginServices.getIconTheme().registerDefault( |
145 |
"info-by-pixel",
|
146 |
getClass().getClassLoader().getResource("images/infoByRasterPoint.png")
|
147 |
); |
148 |
PluginServices.getIconTheme().registerDefault( |
149 |
"view-query-information",
|
150 |
getClass().getClassLoader().getResource("images/Identify.png")
|
151 |
); |
152 |
} |
153 |
} |