root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / geolocation / GeoLocationTocMenuEntry.java @ 17635
History | View | Annotate | Download (5.95 KB)
1 | 14137 | nbrodin | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2007 IVER T.I. 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 | package org.gvsig.rastertools.geolocation; |
||
20 | |||
21 | import java.beans.PropertyChangeEvent; |
||
22 | import java.beans.PropertyChangeListener; |
||
23 | |||
24 | import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
||
25 | import org.gvsig.fmap.raster.layers.IRasterLayerActions; |
||
26 | import org.gvsig.rastertools.geolocation.behavior.GeoRasterBehavior; |
||
27 | import org.gvsig.rastertools.geolocation.listener.GeorefPanListener; |
||
28 | import org.gvsig.rastertools.geolocation.ui.GeoLocationDialog; |
||
29 | |||
30 | import com.iver.andami.PluginServices; |
||
31 | import com.iver.andami.ui.mdiManager.IWindow; |
||
32 | import com.iver.cit.gvsig.fmap.MapControl; |
||
33 | import com.iver.cit.gvsig.fmap.layers.FLayer; |
||
34 | import com.iver.cit.gvsig.fmap.layers.FLayers; |
||
35 | import com.iver.cit.gvsig.fmap.tools.Behavior.Behavior; |
||
36 | import com.iver.cit.gvsig.fmap.tools.Behavior.MouseMovementBehavior; |
||
37 | import com.iver.cit.gvsig.project.documents.view.gui.IView; |
||
38 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
39 | import com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction; |
||
40 | import com.iver.cit.gvsig.project.documents.view.toc.ITocItem; |
||
41 | import com.iver.cit.gvsig.project.documents.view.toolListeners.StatusBarListener; |
||
42 | |||
43 | /**
|
||
44 | * Herramienta del men? contextual que carga el raster en el localizador para tener una visi?n general de
|
||
45 | * esta y carga el zoom del cursor para tener una selecci?n de precisi?n.
|
||
46 | *
|
||
47 | * 16-jun-2007
|
||
48 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
49 | */
|
||
50 | public class GeoLocationTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener { |
||
51 | |||
52 | private GeoRasterBehavior mb = null; |
||
53 | |||
54 | /*
|
||
55 | * (non-Javadoc)
|
||
56 | * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
|
||
57 | */
|
||
58 | public String getGroup() { |
||
59 | return "RasterTools"; |
||
60 | } |
||
61 | |||
62 | /*
|
||
63 | * (non-Javadoc)
|
||
64 | * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
|
||
65 | */
|
||
66 | public int getGroupOrder() { |
||
67 | return 55; |
||
68 | } |
||
69 | |||
70 | /*
|
||
71 | * (non-Javadoc)
|
||
72 | * @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
|
||
73 | */
|
||
74 | public int getOrder() { |
||
75 | return 4; |
||
76 | } |
||
77 | |||
78 | /*
|
||
79 | * (non-Javadoc)
|
||
80 | * @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
|
||
81 | */
|
||
82 | public String getText() { |
||
83 | return PluginServices.getText(this, "geolocation"); |
||
84 | } |
||
85 | |||
86 | /*
|
||
87 | * (non-Javadoc)
|
||
88 | * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isEnabled(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
||
89 | */
|
||
90 | public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
||
91 | return true; |
||
92 | } |
||
93 | |||
94 | /*
|
||
95 | * (non-Javadoc)
|
||
96 | * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#isVisible(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
||
97 | */
|
||
98 | public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
||
99 | if (isTocItemBranch(item))
|
||
100 | if(selectedItems == null || selectedItems.length != 1) |
||
101 | return false; |
||
102 | if (getNodeLayer(item) instanceof FLyrRasterSE && |
||
103 | ((FLyrRasterSE)getNodeLayer(item)).isActionEnabled(IRasterLayerActions.GEOLOCATION)) |
||
104 | return true; |
||
105 | return false; |
||
106 | } |
||
107 | |||
108 | /*
|
||
109 | * (non-Javadoc)
|
||
110 | * @see com.iver.cit.gvsig.project.documents.view.toc.AbstractTocContextMenuAction#execute(com.iver.cit.gvsig.project.documents.view.toc.ITocItem, com.iver.cit.gvsig.fmap.layers.FLayer[])
|
||
111 | */
|
||
112 | public void execute(ITocItem item, FLayer[] selectedItems) { |
||
113 | boolean isOpen = false; |
||
114 | |||
115 | View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
||
116 | MapControl mapCtrl = theView.getMapControl(); |
||
117 | |||
118 | // Listener de eventos de movimiento que pone las coordenadas del rat?n en
|
||
119 | // la barra de estado
|
||
120 | StatusBarListener sbl = new StatusBarListener(mapCtrl);
|
||
121 | |||
122 | //Comprobamos si no hay capas activas. En este caso no lanzamos la ventana ni activamos la tool
|
||
123 | IWindow[] win = PluginServices.getMDIManager().getAllWindows();
|
||
124 | for (int i = 0; i < win.length; i++) { |
||
125 | if (win[i] instanceof IView) { |
||
126 | FLayers lyrs = ((IView)win[i]).getMapControl().getMapContext().getLayers(); |
||
127 | FLayer[] actives = lyrs.getActives();
|
||
128 | if(actives == null || actives.length == 0) |
||
129 | return;
|
||
130 | } |
||
131 | if(win[i] instanceof GeoLocationDialog) |
||
132 | isOpen = true;
|
||
133 | } |
||
134 | |||
135 | if( selectedItems == null || |
||
136 | selectedItems.length != 1 ||
|
||
137 | !(selectedItems[0] instanceof FLyrRasterSE)) |
||
138 | return;
|
||
139 | |||
140 | FLyrRasterSE lyr = (FLyrRasterSE)selectedItems[0];
|
||
141 | 16326 | nbrodin | GeoLocationDialog gld = new GeoLocationDialog(lyr, mapCtrl.getViewPort());
|
142 | 14137 | nbrodin | if(!isOpen) {
|
143 | gld.calcPosition(); |
||
144 | PluginServices.getMDIManager().addWindow(gld); |
||
145 | } |
||
146 | |||
147 | gld.init(mapCtrl); |
||
148 | loadGeoPanListener(mapCtrl, sbl, gld, lyr); |
||
149 | mapCtrl.setTool("geoPan");
|
||
150 | } |
||
151 | |||
152 | /**
|
||
153 | * Carga el listener de selecci?n de raster en el MapControl.
|
||
154 | */
|
||
155 | private void loadGeoPanListener(MapControl mapCtrl, StatusBarListener sbl, GeoLocationDialog gld, FLyrRasterSE lyr) { |
||
156 | if (mapCtrl.getNamesMapTools().get("geoPan") == null) { |
||
157 | GeorefPanListener pl = new GeorefPanListener(mapCtrl);
|
||
158 | mb = new GeoRasterBehavior(pl, gld, lyr);
|
||
159 | mapCtrl.addMapTool("geoPan", new Behavior[]{mb, new MouseMovementBehavior(sbl)}); |
||
160 | |||
161 | } |
||
162 | |||
163 | if(mb != null) { |
||
164 | mb.setLayer(lyr); |
||
165 | mb.setITransformIO(gld); |
||
166 | } |
||
167 | } |
||
168 | |||
169 | public void propertyChange(PropertyChangeEvent evt) { |
||
170 | } |
||
171 | |||
172 | } |