gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / infobypoint / InfoByWMSPointExtension.java @ 2484
History | View | Annotate | Download (5.39 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.wms.app.wmsclient.infobypoint; |
23 |
|
24 |
import java.awt.Component; |
25 |
import java.util.Observable; |
26 |
import java.util.Observer; |
27 |
|
28 |
import javax.swing.JOptionPane; |
29 |
|
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.PluginsLocator; |
32 |
import org.gvsig.andami.actioninfo.ActionInfoManager; |
33 |
import org.gvsig.andami.plugins.Extension; |
34 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
35 |
import org.gvsig.app.project.documents.view.ViewDocument; |
36 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
37 |
import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
38 |
import org.gvsig.fmap.mapcontext.MapContext; |
39 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
40 |
import org.gvsig.fmap.mapcontrol.MapControl; |
41 |
import org.gvsig.fmap.mapcontrol.tools.CompoundBehavior; |
42 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
43 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
44 |
import org.gvsig.fmap.mapcontrol.tools.Behavior.PointBehavior; |
45 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
46 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
47 |
import org.gvsig.raster.swing.infobypoint.InfoByPointDataModel; |
48 |
import org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool.InfoByPixelPointViewTool; |
49 |
import org.gvsig.raster.wms.app.wmsclient.infobypoint.viewtool.PixelInspectorViewTool; |
50 |
import org.gvsig.raster.wms.app.wmsclient.layer.FLyrWMS; |
51 |
|
52 |
/**
|
53 |
* Plugin for the information by point of a raster layer
|
54 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
55 |
*/
|
56 |
public class InfoByWMSPointExtension extends Extension { |
57 |
private InfoByPixelPointViewTool lastTool = null; |
58 |
public static Behavior oldBehavior = null; |
59 |
|
60 |
public void execute(String actionCommand) { |
61 |
if(actionCommand.compareTo("INFO_BY_PIXEL") == 0) { |
62 |
MapControl mapCtrl = getMapControl(); |
63 |
StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
64 |
|
65 |
IWindow[] wList = PluginServices.getMDIManager().getAllWindows();
|
66 |
for (int i = 0; i < wList.length; i++) { |
67 |
if(wList[i] instanceof MainInfoByPointDialog) { |
68 |
JOptionPane.showMessageDialog(
|
69 |
(Component)wList[i],
|
70 |
PluginServices.getText(this, "open_window"), |
71 |
PluginServices.getText(this, "Information"), |
72 |
JOptionPane.INFORMATION_MESSAGE);
|
73 |
mapCtrl.addBehavior("infoByRasterPoint",
|
74 |
new Behavior[]{new PointBehavior(lastTool), |
75 |
new MouseMovementBehavior(sbl)});
|
76 |
mapCtrl.setTool("infoByRasterPoint");
|
77 |
return;
|
78 |
} |
79 |
} |
80 |
MainInfoByPointDialog dialog = new MainInfoByPointDialog();
|
81 |
InfoByPointDataModel model = dialog.getInfoByPointDataModel(); |
82 |
((Observable)model).addObserver((Observer)dialog.getMainPanel()); |
83 |
|
84 |
lastTool = new InfoByPixelPointViewTool(mapCtrl, model, dialog);
|
85 |
mapCtrl.addBehavior("infoByRasterPoint",
|
86 |
new Behavior[]{new PointBehavior(lastTool), |
87 |
new MouseMovementBehavior(sbl)});
|
88 |
mapCtrl.setTool("infoByRasterPoint");
|
89 |
oldBehavior = CompoundBehavior.getAllControlsBehavior(); |
90 |
CompoundBehavior.setAllControlsBehavior(new PixelInspectorViewTool(mapCtrl, model, dialog.getPixelInspector()));
|
91 |
|
92 |
model.notifyObservers(); |
93 |
PluginServices.getMDIManager().addWindow(dialog); |
94 |
} |
95 |
} |
96 |
|
97 |
private MapControl getMapControl() {
|
98 |
IWindow theView = PluginServices.getMDIManager().getActiveWindow(); |
99 |
if(!(theView instanceof AbstractViewPanel)) { |
100 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), PluginServices.getText(this.getClass(), "window_not_valid")); |
101 |
return null; |
102 |
} |
103 |
return ((AbstractViewPanel)theView).getMapControl();
|
104 |
} |
105 |
|
106 |
@SuppressWarnings("deprecation") |
107 |
public boolean isEnabled() { |
108 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
109 |
if (f == null) |
110 |
return false; |
111 |
if (f instanceof AbstractViewPanel) { |
112 |
AbstractViewPanel vista = (AbstractViewPanel) f; |
113 |
ViewDocument model = vista.getModel(); |
114 |
MapContext mapa = model.getMapContext(); |
115 |
FLayers layers = mapa.getLayers(); |
116 |
for (int i = 0; i < layers.getLayersCount(); i++) |
117 |
if (layers.getLayer(i) instanceof FLyrWMS) { |
118 |
FLyrRaster lyr = (FLyrRaster)layers.getLayer(i); |
119 |
if(lyr.isActive())
|
120 |
return true; |
121 |
} |
122 |
} |
123 |
return false; |
124 |
} |
125 |
|
126 |
public boolean isVisible() { |
127 |
return isEnabled();
|
128 |
} |
129 |
|
130 |
public void initialize() { |
131 |
} |
132 |
|
133 |
@Override
|
134 |
public void postInitialize() { |
135 |
super.postInitialize();
|
136 |
try {
|
137 |
ActionInfoManager manager = PluginsLocator.getActionInfoManager(); |
138 |
manager.redirect("layer-info-by-raster-point", "layer-info-by-wms-point"); |
139 |
} catch (IllegalArgumentException e) { |
140 |
RasterSwingLibrary.messageBoxError("infobypoint_not_available", null); |
141 |
} |
142 |
} |
143 |
} |