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