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 / overview / OverviewsTocMenuEntry.java @ 1174
History | View | Annotate | Download (6.28 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.tools.app.basic.tool.overview; |
23 |
|
24 |
import java.beans.PropertyChangeEvent; |
25 |
import java.beans.PropertyChangeListener; |
26 |
|
27 |
import javax.swing.Icon; |
28 |
|
29 |
import org.gvsig.andami.IconThemeHelper; |
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
32 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
33 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
34 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
35 |
import org.gvsig.fmap.mapcontext.exceptions.ReloadLayerException; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLyrDefault; |
38 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
39 |
import org.gvsig.raster.fmap.layers.ILayerState; |
40 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
41 |
import org.gvsig.raster.tools.app.basic.RasterToolsUtil; |
42 |
import org.gvsig.raster.tools.app.basic.raster.gui.IGenericToolBarMenuItem; |
43 |
import org.gvsig.raster.tools.app.basic.raster.process.IProcessActions; |
44 |
import org.gvsig.raster.tools.app.basic.raster.process.OverviewsProcess; |
45 |
import org.gvsig.raster.tools.app.basic.raster.process.RasterProcess; |
46 |
|
47 |
/**
|
48 |
* Herramienta del men? contextual para la generaci?n de overviews.
|
49 |
*
|
50 |
* 10-dic-2007
|
51 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
52 |
*/
|
53 |
public class OverviewsTocMenuEntry extends AbstractTocContextMenuAction implements PropertyChangeListener, IGenericToolBarMenuItem, IProcessActions { |
54 |
static private OverviewsTocMenuEntry singleton = null; |
55 |
|
56 |
/**
|
57 |
* Nadie puede crear una instancia a esta clase ?nica, hay que usar el
|
58 |
* getSingleton()
|
59 |
*/
|
60 |
private OverviewsTocMenuEntry() {}
|
61 |
|
62 |
/**
|
63 |
* Devuelve un objeto unico a dicha clase
|
64 |
* @return
|
65 |
*/
|
66 |
static public OverviewsTocMenuEntry getSingleton() { |
67 |
if (singleton == null) |
68 |
singleton = new OverviewsTocMenuEntry();
|
69 |
return singleton;
|
70 |
} |
71 |
|
72 |
/*
|
73 |
* (non-Javadoc)
|
74 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroup()
|
75 |
*/
|
76 |
public String getGroup() { |
77 |
return "RasterLayer"; |
78 |
} |
79 |
|
80 |
/*
|
81 |
* (non-Javadoc)
|
82 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getGroupOrder()
|
83 |
*/
|
84 |
public int getGroupOrder() { |
85 |
return 10; |
86 |
} |
87 |
|
88 |
/*
|
89 |
* (non-Javadoc)
|
90 |
* @see com.iver.cit.gvsig.project.documents.contextMenu.AbstractContextMenuAction#getOrder()
|
91 |
*/
|
92 |
public int getOrder() { |
93 |
return 70; |
94 |
} |
95 |
|
96 |
/*
|
97 |
* (non-Javadoc)
|
98 |
* @see com.iver.cit.gvsig.project.documents.IContextMenuAction#getText()
|
99 |
*/
|
100 |
public String getText() { |
101 |
return PluginServices.getText(this, "generar_overviews"); |
102 |
} |
103 |
|
104 |
/*
|
105 |
* (non-Javadoc)
|
106 |
* @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[])
|
107 |
*/
|
108 |
public boolean isEnabled(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 |
if (!((ILayerState) selectedItems[0]).isOpen()) |
116 |
return false; |
117 |
|
118 |
if (!((FLyrRaster) selectedItems[0]).getDataStore().overviewsSupport()) |
119 |
return false; |
120 |
|
121 |
if (!((FLyrRaster) selectedItems[0]).getDataStore().overviewsSupport()) |
122 |
return false; |
123 |
|
124 |
return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.CREATEOVERVIEWS); |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @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[])
|
130 |
*/
|
131 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
132 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
133 |
return false; |
134 |
|
135 |
if (!(selectedItems[0] instanceof FLyrRaster)) |
136 |
return false; |
137 |
|
138 |
return true; |
139 |
} |
140 |
|
141 |
/*
|
142 |
* (non-Javadoc)
|
143 |
* @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[])
|
144 |
*/
|
145 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
146 |
FLayer lyr = selectedItems[0];
|
147 |
if (lyr instanceof FLyrRaster) { |
148 |
if (RasterToolsUtil.messageBoxYesOrNot("sobreescribir_datos_overview", this)) { |
149 |
|
150 |
try {
|
151 |
if (((FLyrRaster) lyr).getDataStore().getOverviewCount(0) > 0) { |
152 |
if (!RasterToolsUtil.messageBoxYesOrNot("sobreescribir_overviews", this)) |
153 |
return;
|
154 |
} |
155 |
} catch (BandAccessException e) {
|
156 |
// Actuamos como si no tubiera overviews pero salvamos un Log
|
157 |
RasterToolsUtil.debug("Error accediendo a la banda en getOverViewCount", this, e); |
158 |
|
159 |
} catch (RasterDriverException e) {
|
160 |
// Actuamos como si no tubiera overviews pero salvamos un Log
|
161 |
RasterToolsUtil.debug("Error en getOverViewCount", this, e); |
162 |
} |
163 |
|
164 |
RasterProcess process = new OverviewsProcess();
|
165 |
process.addParam("layer", (FLyrRaster) lyr);
|
166 |
process.setCancelable(false);
|
167 |
process.setActions(this);
|
168 |
process.start(); |
169 |
} |
170 |
} |
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
* @see org.gvsig.rastertools.generictoolbar.IGenericToolBarMenuItem#getIcon()
|
176 |
*/
|
177 |
public Icon getIcon() { |
178 |
return IconThemeHelper.getImageIcon("layer-modify-overviews"); |
179 |
} |
180 |
|
181 |
/*
|
182 |
* (non-Javadoc)
|
183 |
* @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
|
184 |
*/
|
185 |
public void end(Object param) { |
186 |
try {
|
187 |
((FLyrDefault) param).reload(); |
188 |
} catch (ReloadLayerException e) {
|
189 |
} |
190 |
} |
191 |
|
192 |
public void propertyChange(PropertyChangeEvent evt) {} |
193 |
public void interrupted() {} |
194 |
} |