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 / analysisview / ViewRasterAnalysisTocMenuEntry.java @ 1174
History | View | Annotate | Download (7.19 KB)
1 |
/* 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.raster.tools.app.basic.tool.analysisview; |
20 |
|
21 |
import java.beans.PropertyChangeEvent; |
22 |
import java.beans.PropertyChangeListener; |
23 |
import java.io.File; |
24 |
import java.util.ArrayList; |
25 |
|
26 |
import javax.swing.Icon; |
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.andami.PluginServices; |
30 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
31 |
import org.gvsig.app.project.documents.view.MapOverview; |
32 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
33 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
34 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
35 |
import org.gvsig.fmap.mapcontext.exceptions.LoadLayerException; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
import org.gvsig.raster.fmap.layers.DefaultFLyrRaster; |
40 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
41 |
import org.gvsig.raster.fmap.layers.ILayerState; |
42 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
43 |
import org.gvsig.raster.tools.app.basic.raster.gui.IGenericToolBarMenuItem; |
44 |
import org.gvsig.raster.tools.app.basic.tool.pixelincrease.PixelIncreaseDialog; |
45 |
|
46 |
/**
|
47 |
* Herramienta del men? contextual que carga el raster en el localizador para tener una visi?n general de
|
48 |
* esta y carga el zoom del cursor para tener una selecci?n de precisi?n.
|
49 |
*
|
50 |
* 16-jun-2007
|
51 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
52 |
*/
|
53 |
public class ViewRasterAnalysisTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener, IGenericToolBarMenuItem { |
54 |
private boolean onView = false; |
55 |
private String rasterNameInLoc = ""; |
56 |
static private ViewRasterAnalysisTocMenuEntry singleton = null; |
57 |
|
58 |
/**
|
59 |
* Nadie puede crear una instancia a esta clase ?nica, hay que usar el
|
60 |
* getSingleton()
|
61 |
*/
|
62 |
private ViewRasterAnalysisTocMenuEntry() {}
|
63 |
|
64 |
/**
|
65 |
* Devuelve un objeto unico a dicha clase
|
66 |
* @return
|
67 |
*/
|
68 |
static public ViewRasterAnalysisTocMenuEntry getSingleton() { |
69 |
if (singleton == null) |
70 |
singleton = new ViewRasterAnalysisTocMenuEntry();
|
71 |
|
72 |
return singleton;
|
73 |
} |
74 |
|
75 |
/*
|
76 |
* (non-Javadoc)
|
77 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
|
78 |
*/
|
79 |
public String getGroup() { |
80 |
return "RasterLayer"; |
81 |
} |
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
|
86 |
*/
|
87 |
public int getGroupOrder() { |
88 |
return 10; |
89 |
} |
90 |
|
91 |
/*
|
92 |
* (non-Javadoc)
|
93 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
|
94 |
*/
|
95 |
public int getOrder() { |
96 |
return 80; |
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
* @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
|
102 |
*/
|
103 |
public String getText() { |
104 |
if (!onView)
|
105 |
return RasterToolsUtil.getText(this, "analysisview"); |
106 |
else
|
107 |
return RasterToolsUtil.getText(this, "closeanalysisview"); |
108 |
} |
109 |
|
110 |
/*
|
111 |
* (non-Javadoc)
|
112 |
* @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[])
|
113 |
*/
|
114 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
115 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
116 |
return false; |
117 |
|
118 |
if (!(selectedItems[0] instanceof ILayerState)) |
119 |
return false; |
120 |
|
121 |
if (!((ILayerState) selectedItems[0]).isOpen()) |
122 |
return false; |
123 |
return true; |
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
* @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[])
|
129 |
*/
|
130 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
131 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
132 |
return false; |
133 |
|
134 |
if (!(selectedItems[0] instanceof FLyrRaster)) |
135 |
return false; |
136 |
|
137 |
return true; |
138 |
} |
139 |
|
140 |
/*
|
141 |
* (non-Javadoc)
|
142 |
* @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[])
|
143 |
*/
|
144 |
@SuppressWarnings("unchecked") |
145 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
146 |
MapControl mcCurrentLoc = null;
|
147 |
ArrayList mapControlListLoc = new ArrayList(); |
148 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows();
|
149 |
IWindow activeWindow = PluginServices.getMDIManager().getActiveWindow(); |
150 |
FLayer lyr = selectedItems[0];
|
151 |
|
152 |
// Cerramos cualquier inspector de pixeles anterior que est? abierto y
|
153 |
// obtenemos el mapcontrol del localizador
|
154 |
for (int i = 0; i < w.length; i++) { |
155 |
if (w[i] instanceof PixelIncreaseDialog) |
156 |
RasterToolsUtil.closeWindow(w[i]); |
157 |
if (w[i] instanceof AbstractViewPanel && w[i].equals(activeWindow)) |
158 |
mcCurrentLoc = ((AbstractViewPanel) w[i]).getMapOverview(); |
159 |
if (w[i] instanceof AbstractViewPanel) |
160 |
mapControlListLoc.add(((AbstractViewPanel) w[i]).getMapOverview()); |
161 |
} |
162 |
|
163 |
if (!onView) {
|
164 |
// Abrimos el inspector de pixeles
|
165 |
PixelIncreaseDialog pIncrease = new PixelIncreaseDialog();
|
166 |
RasterToolsUtil.addWindow(pIncrease); |
167 |
|
168 |
// Cargamos el raster en el localizador
|
169 |
mcCurrentLoc.getMapContext().beginAtomicEvent(); |
170 |
|
171 |
String path = null; |
172 |
if (lyr instanceof FLyrRaster) |
173 |
path = ((FLyrRaster) lyr).getURI(); |
174 |
|
175 |
try {
|
176 |
File f = new File(path); |
177 |
if(!f.exists()) {
|
178 |
RasterToolsUtil.messageBoxError("error_file_not_found", PluginServices.getMDIManager().getActiveWindow());
|
179 |
return;
|
180 |
} |
181 |
lyr = DefaultFLyrRaster.createLayer(lyr.getName(), f); |
182 |
rasterNameInLoc = lyr.getName(); |
183 |
mcCurrentLoc.getMapContext().getLayers().addLayer(lyr); |
184 |
} catch (LoadLayerException e) {
|
185 |
JOptionPane.showMessageDialog(null, RasterToolsUtil.getText(this, "coordenadas_erroneas")); |
186 |
} |
187 |
mcCurrentLoc.getMapContext().endAtomicEvent(); |
188 |
} else {
|
189 |
for (int nViews = 0; nViews < mapControlListLoc.size(); nViews++) { |
190 |
MapControl mc = ((MapControl) mapControlListLoc.get(nViews)); |
191 |
FLayers lyrs = mc.getMapContext().getLayers(); |
192 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
193 |
if (lyrs.getLayer(i).getName().compareTo(rasterNameInLoc) == 0) |
194 |
lyrs.removeLayer(i); |
195 |
} |
196 |
if (mc instanceof MapOverview) |
197 |
((MapOverview) mc).refreshExtent(); |
198 |
} |
199 |
} |
200 |
onView = !onView; |
201 |
} |
202 |
|
203 |
/*
|
204 |
* (non-Javadoc)
|
205 |
* @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
|
206 |
*/
|
207 |
public Icon getIcon() { |
208 |
return RasterToolsUtil.getIcon("view-raster-analysis"); |
209 |
} |
210 |
|
211 |
public void propertyChange(PropertyChangeEvent evt) {} |
212 |
} |