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