Revision 17939
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
4 |
<modelVersion>4.0.0</modelVersion> |
|
5 |
<artifactId>org.gvsig.raster.roimask.app</artifactId> |
|
6 |
<packaging>pom</packaging> |
|
7 |
<name>org.gvsig.raster.roimask.app</name> |
|
8 |
<description /> |
|
9 |
|
|
10 |
<parent> |
|
11 |
<groupId>org.gvsig</groupId> |
|
12 |
<artifactId>org.gvsig.raster.roimask</artifactId> |
|
13 |
<version>2.2.186</version> |
|
14 |
</parent> |
|
15 |
|
|
16 |
<scm> |
|
17 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app</connection> |
|
18 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app</developerConnection> |
|
19 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app</url> |
|
20 |
</scm> |
|
21 |
|
|
22 |
<developers> |
|
23 |
<developer> |
|
24 |
<id>nbrodin</id> |
|
25 |
<name>Nacho Brodin</name> |
|
26 |
<email>nachobrodin@gmail.com</email> |
|
27 |
<roles> |
|
28 |
<role>Architect</role> |
|
29 |
<role>Developer</role> |
|
30 |
</roles> |
|
31 |
</developer> |
|
32 |
</developers> |
|
33 |
<repositories> |
|
34 |
<repository> |
|
35 |
<id>gvsig-public-http-repository</id> |
|
36 |
<name>gvSIG maven public HTTP repository</name> |
|
37 |
<url>http://devel.gvsig.org/m2repo/j2se</url> |
|
38 |
<releases> |
|
39 |
<enabled>true</enabled> |
|
40 |
<updatePolicy>daily</updatePolicy> |
|
41 |
<checksumPolicy>warn</checksumPolicy> |
|
42 |
</releases> |
|
43 |
<snapshots> |
|
44 |
<enabled>true</enabled> |
|
45 |
<updatePolicy>daily</updatePolicy> |
|
46 |
<checksumPolicy>warn</checksumPolicy> |
|
47 |
</snapshots> |
|
48 |
</repository> |
|
49 |
</repositories> |
|
50 |
<dependencies> |
|
51 |
<dependency> |
|
52 |
<groupId>org.gvsig</groupId> |
|
53 |
<artifactId>org.gvsig.andami</artifactId> |
|
54 |
<scope>compile</scope> |
|
55 |
</dependency> |
|
56 |
<dependency> |
|
57 |
<groupId>org.gvsig</groupId> |
|
58 |
<artifactId>org.gvsig.i18n</artifactId> |
|
59 |
<scope>compile</scope> |
|
60 |
</dependency> |
|
61 |
<dependency> |
|
62 |
<groupId>org.gvsig</groupId> |
|
63 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
64 |
<scope>compile</scope> |
|
65 |
</dependency> |
|
66 |
<dependency> |
|
67 |
<groupId>org.slf4j</groupId> |
|
68 |
<artifactId>slf4j-api</artifactId> |
|
69 |
<scope>compile</scope> |
|
70 |
</dependency> |
|
71 |
<dependency> |
|
72 |
<groupId>org.slf4j</groupId> |
|
73 |
<artifactId>slf4j-log4j12</artifactId> |
|
74 |
<scope>runtime</scope> |
|
75 |
</dependency> |
|
76 |
</dependencies> |
|
77 |
<modules> |
|
78 |
<module>org.gvsig.raster.roimask.app.client</module> |
|
79 |
</modules> |
|
80 |
</project> |
|
0 | 81 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/buildNumber.properties | ||
---|---|---|
1 |
#Thu May 12 23:13:15 CEST 2022 |
|
2 |
buildNumber=194 |
|
0 | 3 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/assembly/gvsig-plugin-package.xml | ||
---|---|---|
1 |
<assembly> |
|
2 |
<id>gvsig-plugin-package</id> |
|
3 |
<formats> |
|
4 |
<format>zip</format> |
|
5 |
</formats> |
|
6 |
<baseDirectory>.</baseDirectory> |
|
7 |
<includeBaseDirectory>true</includeBaseDirectory> |
|
8 |
<files> |
|
9 |
<file> |
|
10 |
<source>target/${project.artifactId}-${project.version}.jar</source> |
|
11 |
<outputDirectory>${project.artifactId}/lib</outputDirectory> |
|
12 |
</file> |
|
13 |
<file> |
|
14 |
<source>target/package.info</source> |
|
15 |
<outputDirectory>${project.artifactId}</outputDirectory> |
|
16 |
</file> |
|
17 |
</files> |
|
18 |
|
|
19 |
<fileSets> |
|
20 |
<fileSet> |
|
21 |
<directory>src/main/resources-plugin</directory> |
|
22 |
<outputDirectory>${project.artifactId}</outputDirectory> |
|
23 |
</fileSet> |
|
24 |
</fileSets> |
|
25 |
|
|
26 |
|
|
27 |
<dependencySets> |
|
28 |
<dependencySet> |
|
29 |
<useProjectArtifact>false</useProjectArtifact> |
|
30 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
31 |
<outputDirectory>${project.artifactId}/lib</outputDirectory> |
|
32 |
<includes> |
|
33 |
<include>org.gvsig:org.gvsig.raster.roimask.app.client:jar</include> |
|
34 |
<include>org.gvsig:org.gvsig.raster.roimask.lib.api:jar</include> |
|
35 |
<include>org.gvsig:org.gvsig.raster.roimask.lib.impl:jar</include> |
|
36 |
<include>org.gvsig:org.gvsig.raster.roimask.swing.api:jar</include> |
|
37 |
<include>org.gvsig:org.gvsig.raster.roimask.swing.impl:jar</include> |
|
38 |
<include>org.gvsig:org.gvsig.raster.roimask.algorithm:jar</include> |
|
39 |
<include>org.gvsig:org.gvsig.raster.roimask.toolbox.algorithm:jar</include> |
|
40 |
</includes> |
|
41 |
</dependencySet> |
|
42 |
|
|
43 |
<!-- Copia el algoritmo de toolbox a install/files cuando se empaqueta para que el script de ant lo meta donde toca al instalar |
|
44 |
|
|
45 |
<dependencySet> |
|
46 |
<useProjectArtifact>false</useProjectArtifact> |
|
47 |
<useTransitiveDependencies>false</useTransitiveDependencies> |
|
48 |
<outputDirectory>${project.artifactId}/install/files</outputDirectory> |
|
49 |
<includes> |
|
50 |
<include>org.gvsig:org.gvsig.raster.roimask.toolbox.algorithm:jar</include> |
|
51 |
</includes> |
|
52 |
</dependencySet>--> |
|
53 |
</dependencySets> |
|
54 |
</assembly> |
|
0 | 55 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/ROIMaskExtension.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app; |
|
2 |
|
|
3 |
import java.awt.event.ActionEvent; |
|
4 |
import java.awt.event.ActionListener; |
|
5 |
import java.io.File; |
|
6 |
import java.util.HashMap; |
|
7 |
import java.util.List; |
|
8 |
|
|
9 |
import javax.swing.JComponent; |
|
10 |
import javax.swing.JPanel; |
|
11 |
|
|
12 |
import org.gvsig.andami.IconThemeHelper; |
|
13 |
import org.gvsig.andami.PluginServices; |
|
14 |
import org.gvsig.andami.plugins.Extension; |
|
15 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
16 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
17 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
|
18 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
19 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
20 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
21 |
import org.gvsig.fmap.dal.exception.ReadException; |
|
22 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
23 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
24 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
25 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
26 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
|
27 |
import org.gvsig.i18n.Messages; |
|
28 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
29 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
30 |
import org.gvsig.raster.algorithm.process.IProcessActions; |
|
31 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
32 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
33 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
|
34 |
import org.gvsig.raster.mainplugin.RasterMainPluginUtils; |
|
35 |
import org.gvsig.raster.roi.ROI; |
|
36 |
import org.gvsig.raster.roimask.algorithm.ROIMaskProcess; |
|
37 |
import org.gvsig.raster.roimask.app.toolbox.ToolboxROIMaskLoader; |
|
38 |
import org.gvsig.raster.roimask.swing.ROIMaskPanel; |
|
39 |
import org.gvsig.raster.roimask.swing.ROIMaskSwingLocator; |
|
40 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
41 |
import org.gvsig.raster.swing.RasterSwingLocator; |
|
42 |
import org.gvsig.raster.swing.newlayer.CreateNewLayerPanel; |
|
43 |
import org.gvsig.raster.swing.preview.PreviewPanel; |
|
44 |
import org.gvsig.raster.util.RasterNotLoadException; |
|
45 |
import org.gvsig.tools.ToolsLocator; |
|
46 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
47 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
48 |
import org.slf4j.Logger; |
|
49 |
import org.slf4j.LoggerFactory; |
|
50 |
|
|
51 |
public class ROIMaskExtension extends Extension implements ActionListener, |
|
52 |
IProcessActions { |
|
53 |
|
|
54 |
private int windowWidth = 600; |
|
55 |
|
|
56 |
private int windowHeight = 370; |
|
57 |
|
|
58 |
private IWindow window = null; |
|
59 |
|
|
60 |
private PreviewPanel previewPanel = null; |
|
61 |
|
|
62 |
private ROIMaskPreview processPreview = null; |
|
63 |
|
|
64 |
private ROIMaskPanel panel = null; |
|
65 |
|
|
66 |
private CreateNewLayerPanel newLayerPanel = null; |
|
67 |
|
|
68 |
private static final Logger logger = LoggerFactory |
|
69 |
.getLogger(ROIMaskExtension.class); |
|
70 |
|
|
71 |
public void initialize() { |
|
72 |
|
|
73 |
// Adds an entry to the TOC's floating menu to those layers defined in this |
|
74 |
// extension |
|
75 |
|
|
76 |
// ExtensionPoint exPoint = |
|
77 |
// ToolsLocator.getExtensionPointManager().add("My_TocActions"); |
|
78 |
// exPoint.append("MyMenuEntry", "", new ROIMaskTocMenuEntry()); |
|
79 |
|
|
80 |
// Adds a new tab to the "add layer" dialog |
|
81 |
|
|
82 |
// AddLayer.addWizard(ROIMaskWizard.class); |
|
83 |
|
|
84 |
// Adds a new button in the raster bar |
|
85 |
|
|
86 |
ExtensionPointManager extensionPoints = ToolsLocator |
|
87 |
.getExtensionPointManager(); |
|
88 |
ExtensionPoint point = extensionPoints.add("GenericToolBarMenu"); |
|
89 |
point.append("ROIMask", "", ROIMaskTocMenuEntry.getSingleton()); |
|
90 |
ROIMaskTocMenuEntry.setExtension(this); |
|
91 |
|
|
92 |
Messages.addResourceFamily("org.gvsig.raster.roimask.app.i18n.text", |
|
93 |
ROIMaskExtension.class.getClassLoader(), ROIMaskExtension.class |
|
94 |
.getClass().getName()); |
|
95 |
|
|
96 |
initilizeIcons(); |
|
97 |
} |
|
98 |
|
|
99 |
public void postInitialize() { |
|
100 |
new ToolboxROIMaskLoader().registerTool(); |
|
101 |
} |
|
102 |
|
|
103 |
public void execute(String actionCommand) { |
|
104 |
if (actionCommand.compareTo("ROIMask") == 0) { |
|
105 |
if (getSelectedLayer() == null) { |
|
106 |
RasterSwingLibrary.messageBoxError("layer_not_selected", null); |
|
107 |
return; |
|
108 |
} |
|
109 |
try { |
|
110 |
initializeMainPanel(); |
|
111 |
} |
|
112 |
catch (ReadException e) { |
|
113 |
logger.error("Error initializing the main panel", e); |
|
114 |
} |
|
115 |
catch (ROIException e) { |
|
116 |
logger.error("Error getting ROI", e); |
|
117 |
} |
|
118 |
} |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Creates and initializes the main panel |
|
123 |
* |
|
124 |
* @throws ReadException |
|
125 |
* @throws ROIException |
|
126 |
*/ |
|
127 |
private void initializeMainPanel() throws ReadException, ROIException { |
|
128 |
try { |
|
129 |
loadROIMaskPanel(); |
|
130 |
} |
|
131 |
catch (NotInitializeException e) { |
|
132 |
throw new ReadException("Error loading the table", e); |
|
133 |
} |
|
134 |
|
|
135 |
MainPanel mainPanel = new MainPanel(getROIMaskPanel().getComponent(), |
|
136 |
(JComponent) getNewLayerPanel()); |
|
137 |
|
|
138 |
window = new ROIMaskWindow(mainPanel, (JPanel) getPreviewPanel(), |
|
139 |
Messages.getText("roimask"), windowWidth, windowHeight, false, this); |
|
140 |
|
|
141 |
PluginServices.getMDIManager().addWindow(window); |
|
142 |
getPreviewPanel().previewInitializeSizes(); |
|
143 |
getPreviewPanel().refreshPreview(); |
|
144 |
} |
|
145 |
|
|
146 |
/** |
|
147 |
* Loads the main panel with the data |
|
148 |
* |
|
149 |
* @throws NotInitializeException |
|
150 |
* @throws ROIException |
|
151 |
*/ |
|
152 |
private void loadROIMaskPanel() throws NotInitializeException, ROIException { |
|
153 |
FLyrRaster lyr = getSelectedLayer(); |
|
154 |
LayerElement element = new LayerElement(lyr); |
|
155 |
getROIMaskPanel().getDataModel().setInputLayer(element); |
|
156 |
ColorInterpretation ci = lyr.getDataStore().getColorInterpretation(); |
|
157 |
|
|
158 |
if (ci.isRGB() || ci.isRGBA()) { |
|
159 |
getROIMaskPanel().activeSlider(true); |
|
160 |
} |
|
161 |
else |
|
162 |
getROIMaskPanel().activeSlider(false); |
|
163 |
|
|
164 |
if (lyr.getRois() == null || lyr.getRois().size() == 0) |
|
165 |
getROIMaskPanel().showWarning(true); |
|
166 |
else |
|
167 |
getROIMaskPanel().showWarning(false); |
|
168 |
|
|
169 |
getROIMaskPanel().getDataModel().clearROIs(); |
|
170 |
|
|
171 |
List<ROI> roisArray = lyr.getRois(); |
|
172 |
if (roisArray != null) { |
|
173 |
for (int i = 0; i < roisArray.size(); i++) { |
|
174 |
ROI roi = (ROI) roisArray.get(i); |
|
175 |
|
|
176 |
Object row[] = { "", "", "" }; |
|
177 |
|
|
178 |
boolean active = false; |
|
179 |
|
|
180 |
row[0] = new Boolean(active); |
|
181 |
row[1] = roi.getName(); |
|
182 |
row[2] = new Integer(i); |
|
183 |
getROIMaskPanel().getDataModel().addROI(row); |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
187 |
if (lyr != null) { |
|
188 |
switch (lyr.getDataStore().getDataType()[0]) { |
|
189 |
case Buffer.TYPE_BYTE: |
|
190 |
getROIMaskPanel().getDataModel().setValueNoData( |
|
191 |
RasterLibrary.defaultByteNoDataValue); |
|
192 |
break; |
|
193 |
case Buffer.TYPE_SHORT: |
|
194 |
getROIMaskPanel().getDataModel().setValueNoData( |
|
195 |
RasterLibrary.defaultShortNoDataValue); |
|
196 |
break; |
|
197 |
case Buffer.TYPE_INT: |
|
198 |
getROIMaskPanel().getDataModel().setValueNoData( |
|
199 |
RasterLibrary.defaultIntegerNoDataValue); |
|
200 |
break; |
|
201 |
case Buffer.TYPE_FLOAT: |
|
202 |
getROIMaskPanel().getDataModel().setValueNoData( |
|
203 |
RasterLibrary.defaultFloatNoDataValue); |
|
204 |
break; |
|
205 |
case Buffer.TYPE_DOUBLE: |
|
206 |
getROIMaskPanel().getDataModel().setValueNoData( |
|
207 |
RasterLibrary.defaultDoubleNoDataValue); |
|
208 |
break; |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Gets the list of layers from the gvSIG view |
|
215 |
* |
|
216 |
* @return |
|
217 |
*/ |
|
218 |
private FLayers getLayers() { |
|
219 |
MapControl mapControl = null; |
|
220 |
IWindow[] windowList = PluginServices.getMDIManager().getOrderedWindows(); |
|
221 |
for (int i = 0; i < windowList.length; i++) { |
|
222 |
if (windowList[i] instanceof AbstractViewPanel) { |
|
223 |
mapControl = ((AbstractViewPanel) windowList[i]).getMapControl(); |
|
224 |
break; |
|
225 |
} |
|
226 |
} |
|
227 |
if (mapControl != null) return mapControl.getMapContext().getLayers(); |
|
228 |
return null; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Gets the selected layer |
|
233 |
* |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
private FLyrRaster getSelectedLayer() { |
|
237 |
FLayers lyrs = getLayers(); |
|
238 |
if (lyrs != null) { |
|
239 |
for (int i = 0; i < lyrs.getLayersCount(); i++) { |
|
240 |
FLayer lyr = lyrs.getLayer(i); |
|
241 |
if (lyr.isActive() && lyr instanceof FLyrRaster) |
|
242 |
return (FLyrRaster) lyr; |
|
243 |
} |
|
244 |
} |
|
245 |
return null; |
|
246 |
} |
|
247 |
|
|
248 |
public boolean isEnabled() { |
|
249 |
FLyrRaster selectedLayer = getSelectedLayer(); |
|
250 |
if (selectedLayer == null) return false; |
|
251 |
|
|
252 |
if (selectedLayer != null && selectedLayer.isActive() |
|
253 |
&& selectedLayer instanceof FLyrRaster) { |
|
254 |
return true; |
|
255 |
} |
|
256 |
return false; |
|
257 |
} |
|
258 |
|
|
259 |
public boolean isVisible() { |
|
260 |
FLyrRaster selectedLayer = getSelectedLayer(); |
|
261 |
if (selectedLayer == null) |
|
262 |
return false; |
|
263 |
|
|
264 |
if (!(selectedLayer instanceof IRasterLayerActions)) |
|
265 |
return false; |
|
266 |
|
|
267 |
return ((IRasterLayerActions) selectedLayer).isActionEnabled(IRasterLayerActions.ENHANCED); |
|
268 |
} |
|
269 |
|
|
270 |
void initilizeIcons() { |
|
271 |
IconThemeHelper.registerIcon(null, "gvsig-icon", this); |
|
272 |
IconThemeHelper.registerIcon(null, "mask-icon", this); |
|
273 |
IconThemeHelper.registerIcon(null, "gvsig-icon16x16", this); |
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Gets the {@link ROIMaskPanel} |
|
278 |
* |
|
279 |
* @return {@link ROIMaskPanel} |
|
280 |
*/ |
|
281 |
private CreateNewLayerPanel getNewLayerPanel() { |
|
282 |
if (newLayerPanel == null) |
|
283 |
newLayerPanel = RasterSwingLocator.getSwingManager().createNewLayerPanel( |
|
284 |
Messages.getText("create_output_layer")); |
|
285 |
return newLayerPanel; |
|
286 |
} |
|
287 |
|
|
288 |
/** |
|
289 |
* Gets the {@link PreviewPanel} |
|
290 |
* |
|
291 |
* @return {@link PreviewPanel} |
|
292 |
*/ |
|
293 |
private PreviewPanel getPreviewPanel() { |
|
294 |
if (previewPanel == null) |
|
295 |
previewPanel = RasterSwingLocator.getSwingManager() |
|
296 |
.createSinglePreviewPanel(null, getDataSourcePreview()); |
|
297 |
return previewPanel; |
|
298 |
} |
|
299 |
|
|
300 |
/** |
|
301 |
* Gets the {@link ROIMaskPreview} |
|
302 |
* |
|
303 |
* @return {@link ROIMaskPreview} |
|
304 |
*/ |
|
305 |
private ROIMaskPreview getDataSourcePreview() { |
|
306 |
if (processPreview == null) { |
|
307 |
processPreview = new ROIMaskPreview(); |
|
308 |
} |
|
309 |
processPreview.setData(getROIMaskPanel().getDataModel()); |
|
310 |
return processPreview; |
|
311 |
} |
|
312 |
|
|
313 |
/** |
|
314 |
* Gets the {@link ROIMaskPanel} |
|
315 |
* |
|
316 |
* @return {@link ROIMaskPanel} |
|
317 |
*/ |
|
318 |
private ROIMaskPanel getROIMaskPanel() { |
|
319 |
if (panel == null) { |
|
320 |
panel = ROIMaskSwingLocator.getSwingManager().createROIMaskPanel(); |
|
321 |
panel.addListener(this); |
|
322 |
} |
|
323 |
return panel; |
|
324 |
} |
|
325 |
|
|
326 |
public void actionPerformed(ActionEvent e) { |
|
327 |
if (window != null |
|
328 |
&& (e.getSource() == ((ROIMaskWindow) window).getButtonsPanel() |
|
329 |
.getButton(ButtonsPanel.BUTTON_ACCEPT) || e.getSource() == ((ROIMaskWindow) window) |
|
330 |
.getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY))) { |
|
331 |
DataProcess task = null; |
|
332 |
try { |
|
333 |
task = RasterBaseAlgorithmLibrary.getManager().createRasterTask( |
|
334 |
"ROIMaskProcess"); |
|
335 |
} |
|
336 |
catch (ProcessException e1) { |
|
337 |
RasterSwingLibrary.messageBoxError("error_processing_layer", null, e1); |
|
338 |
} |
|
339 |
task.setActions(this); |
|
340 |
try { |
|
341 |
getDataSourcePreview().addParams(task, |
|
342 |
getNewLayerPanel().getDirectorySelected(), |
|
343 |
getNewLayerPanel().getFileSelected()); |
|
344 |
} |
|
345 |
catch (ROIException e1) { |
|
346 |
RasterSwingLibrary.messageBoxError("error_processing_layer", null, e1); |
|
347 |
} |
|
348 |
task.start(); |
|
349 |
return; |
|
350 |
} |
|
351 |
|
|
352 |
getPreviewPanel().refreshPreview(); |
|
353 |
} |
|
354 |
|
|
355 |
@SuppressWarnings("unchecked") |
|
356 |
public void end(Object params) { |
|
357 |
if (params instanceof HashMap<?, ?>) { |
|
358 |
HashMap<String, Object> map = (HashMap<String, Object>) params; |
|
359 |
String fName = (String) map.get(ROIMaskProcess.FILENAME); |
|
360 |
long milis = (Long) map.get(ROIMaskProcess.TIME); |
|
361 |
processFinalize(fName, milis); |
|
362 |
RasterSwingLocator.getSwingManager().showSummaryProcessDialog(fName, |
|
363 |
milis); |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
private void processFinalize(String fileName, long milis) { |
|
368 |
if (!new File(fileName).exists()) return; |
|
369 |
|
|
370 |
String viewName = getViewName(); |
|
371 |
if (viewName != null) { |
|
372 |
if (RasterSwingLibrary.messageBoxYesOrNot("cargar_toc", this)) { |
|
373 |
try { |
|
374 |
RasterMainPluginUtils.loadLayer(viewName, fileName, null); |
|
375 |
} |
|
376 |
catch (RasterNotLoadException e) { |
|
377 |
RasterSwingLibrary.messageBoxError("error_load_layer", null, e); |
|
378 |
} |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
|
|
383 |
private String getViewName() { |
|
384 |
FLyrRaster lyrRaster = getSelectedLayer(); |
|
385 |
IWindow[] w = PluginServices.getMDIManager().getAllWindows(); |
|
386 |
for (int i = 0; i < w.length; i++) { |
|
387 |
if (w[i] instanceof AbstractViewPanel) { |
|
388 |
FLayers lyrs = ((AbstractViewPanel) w[i]).getMapControl() |
|
389 |
.getMapContext().getLayers(); |
|
390 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
|
391 |
FLayer lyr = lyrs.getLayer(j); |
|
392 |
if (lyrRaster == lyr) { |
|
393 |
return PluginServices.getMDIManager() |
|
394 |
.getWindowInfo((AbstractViewPanel) w[i]).getTitle(); |
|
395 |
} |
|
396 |
} |
|
397 |
} |
|
398 |
} |
|
399 |
return null; |
|
400 |
} |
|
401 |
|
|
402 |
public void interrupted() { |
|
403 |
|
|
404 |
} |
|
405 |
|
|
406 |
public class LayerElement { |
|
407 |
|
|
408 |
private FLayer lyr = null; |
|
409 |
|
|
410 |
public LayerElement(FLayer lyr) { |
|
411 |
this.lyr = lyr; |
|
412 |
} |
|
413 |
|
|
414 |
public FLayer getLayer() { |
|
415 |
return lyr; |
|
416 |
} |
|
417 |
|
|
418 |
public String toString() { |
|
419 |
return lyr.getName(); |
|
420 |
} |
|
421 |
|
|
422 |
public int getNumOfElements() { |
|
423 |
if (lyr instanceof FLyrRaster) |
|
424 |
return ((FLyrRaster) lyr).getDataStore().getBandCount(); |
|
425 |
return 0; |
|
426 |
} |
|
427 |
} |
|
428 |
|
|
429 |
public void updateProgress(int current, int total) { |
|
430 |
// TODO Auto-generated method stub |
|
431 |
|
|
432 |
} |
|
433 |
} |
|
0 | 434 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/ROIMaskTocMenuEntry.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app; |
|
2 |
|
|
3 |
import javax.swing.Icon; |
|
4 |
|
|
5 |
import org.gvsig.andami.IconThemeHelper; |
|
6 |
import org.gvsig.andami.plugins.Extension; |
|
7 |
import org.gvsig.app.project.documents.view.toc.AbstractTocContextMenuAction; |
|
8 |
import org.gvsig.app.project.documents.view.toc.ITocItem; |
|
9 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
10 |
import org.gvsig.i18n.Messages; |
|
11 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
12 |
import org.gvsig.raster.fmap.layers.IRasterLayerActions; |
|
13 |
import org.gvsig.raster.mainplugin.toolbar.IGenericToolBarMenuItem; |
|
14 |
|
|
15 |
public class ROIMaskTocMenuEntry extends AbstractTocContextMenuAction implements IGenericToolBarMenuItem { |
|
16 |
static private ROIMaskTocMenuEntry singleton = null; |
|
17 |
private static Extension extension = null; |
|
18 |
|
|
19 |
|
|
20 |
public static void setExtension(Extension ext) { |
|
21 |
extension = ext; |
|
22 |
} |
|
23 |
|
|
24 |
private ROIMaskTocMenuEntry() {} |
|
25 |
|
|
26 |
static public ROIMaskTocMenuEntry getSingleton() { |
|
27 |
if (singleton == null) |
|
28 |
singleton = new ROIMaskTocMenuEntry(); |
|
29 |
return singleton; |
|
30 |
} |
|
31 |
|
|
32 |
public String getGroup() { |
|
33 |
return "Enhanced"; |
|
34 |
} |
|
35 |
|
|
36 |
public int getGroupOrder() { |
|
37 |
return 55; |
|
38 |
} |
|
39 |
|
|
40 |
public int getOrder() { |
|
41 |
return 0; |
|
42 |
} |
|
43 |
|
|
44 |
public String getText() { |
|
45 |
return Messages.getText("roimask"); |
|
46 |
} |
|
47 |
|
|
48 |
public boolean isEnabled(ITocItem item, FLayer[] selectedItems) { |
|
49 |
if(selectedItems == null || selectedItems.length == 0) |
|
50 |
return false; |
|
51 |
for (int i = 0; i < selectedItems.length; i++) { |
|
52 |
if(selectedItems[i] != null && |
|
53 |
selectedItems[i].isActive() && |
|
54 |
selectedItems[i] instanceof FLyrRaster) |
|
55 |
return true; |
|
56 |
} |
|
57 |
return false; |
|
58 |
} |
|
59 |
|
|
60 |
public boolean isVisible(ITocItem item, FLayer[] selectedItems) { |
|
61 |
if ((selectedItems == null) || (selectedItems.length != 1)) |
|
62 |
return false; |
|
63 |
|
|
64 |
if (!(selectedItems[0] instanceof IRasterLayerActions)) |
|
65 |
return false; |
|
66 |
|
|
67 |
return ((IRasterLayerActions) selectedItems[0]).isActionEnabled(IRasterLayerActions.ENHANCED); |
|
68 |
} |
|
69 |
|
|
70 |
public void execute(ITocItem item, FLayer[] selectedItems) { |
|
71 |
extension.execute("ROIMask"); |
|
72 |
} |
|
73 |
|
|
74 |
public Icon getIcon() { |
|
75 |
return IconThemeHelper.getImageIcon("mask-icon"); |
|
76 |
} |
|
77 |
} |
|
0 | 78 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/MainPanel.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app; |
|
2 |
|
|
3 |
import java.awt.GridBagConstraints; |
|
4 |
import java.awt.GridBagLayout; |
|
5 |
|
|
6 |
import javax.swing.JComponent; |
|
7 |
import javax.swing.JPanel; |
|
8 |
|
|
9 |
public class MainPanel extends JPanel { |
|
10 |
private static final long serialVersionUID = 1L; |
|
11 |
|
|
12 |
public MainPanel(JComponent panel, JComponent createLayer) { |
|
13 |
setLayout(new GridBagLayout()); |
|
14 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
15 |
gbc.anchor = GridBagConstraints.WEST; |
|
16 |
gbc.fill = GridBagConstraints.BOTH; |
|
17 |
gbc.weightx = 1; |
|
18 |
gbc.weighty = 1; |
|
19 |
gbc.gridy = 0; |
|
20 |
add(panel, gbc); |
|
21 |
|
|
22 |
gbc.fill = GridBagConstraints.HORIZONTAL; |
|
23 |
gbc.weightx = 1; |
|
24 |
gbc.weighty = 0; |
|
25 |
gbc.gridy = 1; |
|
26 |
|
|
27 |
add(createLayer, gbc); |
|
28 |
} |
|
29 |
} |
|
0 | 30 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/toolbox/ToolboxROIMaskLoader.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app.toolbox; |
|
2 |
|
|
3 |
import java.lang.reflect.Constructor; |
|
4 |
import java.lang.reflect.InvocationTargetException; |
|
5 |
|
|
6 |
import org.slf4j.Logger; |
|
7 |
import org.slf4j.LoggerFactory; |
|
8 |
|
|
9 |
/** |
|
10 |
* Loader for this tool in the toolbox dialog |
|
11 |
* |
|
12 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
13 |
*/ |
|
14 |
public class ToolboxROIMaskLoader { |
|
15 |
private Logger log = LoggerFactory.getLogger(ToolboxROIMaskLoader.class); |
|
16 |
private String errorMsg = "The tool ROIMask are not been added in the toolbox"; |
|
17 |
|
|
18 |
public void registerTool() { |
|
19 |
try { |
|
20 |
Class<?> c = Class.forName("org.gvsig.raster.roimask.app.toolbox.ROIMaskToolboxAction"); |
|
21 |
Constructor<?> constructor = c.getConstructor(); |
|
22 |
constructor.newInstance(); |
|
23 |
} catch (ClassNotFoundException e) { |
|
24 |
log.info(errorMsg, e); |
|
25 |
} catch (SecurityException e) { |
|
26 |
log.info(errorMsg, e); |
|
27 |
} catch (NoSuchMethodException e) { |
|
28 |
log.info(errorMsg, e); |
|
29 |
} catch (IllegalArgumentException e) { |
|
30 |
log.info(errorMsg, e); |
|
31 |
} catch (InstantiationException e) { |
|
32 |
log.info(errorMsg, e); |
|
33 |
} catch (IllegalAccessException e) { |
|
34 |
log.info(errorMsg, e); |
|
35 |
} catch (InvocationTargetException e) { |
|
36 |
log.info(errorMsg, e); |
|
37 |
} catch (NoClassDefFoundError e) { |
|
38 |
log.info("Geoprocess are not installed." + errorMsg, e); |
|
39 |
} |
|
40 |
} |
|
41 |
|
|
42 |
} |
|
0 | 43 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/toolbox/AbstractToolboxAction.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
package org.gvsig.raster.roimask.app.toolbox; |
|
26 |
|
|
27 |
import org.gvsig.andami.PluginServices; |
|
28 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
29 |
import org.gvsig.app.project.documents.view.gui.AbstractViewPanel; |
|
30 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
31 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
32 |
import org.gvsig.geoprocess.lib.sextante.dataObjects.FLyrRasterIRasterLayer; |
|
33 |
import org.gvsig.i18n.Messages; |
|
34 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
35 |
import org.gvsig.raster.swing.RasterSwingLibrary; |
|
36 |
|
|
37 |
import es.unex.sextante.dataObjects.IRasterLayer; |
|
38 |
import es.unex.sextante.gui.core.SextanteGUI; |
|
39 |
import es.unex.sextante.gui.core.ToolboxAction; |
|
40 |
|
|
41 |
/** |
|
42 |
* Base class for toolBox actions |
|
43 |
* |
|
44 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
45 |
*/ |
|
46 |
public abstract class AbstractToolboxAction extends ToolboxAction { |
|
47 |
protected FLyrRaster lyr = null; |
|
48 |
|
|
49 |
@Override |
|
50 |
public String getGroup() { |
|
51 |
return Messages.getText("group_tools"); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
@Override |
|
56 |
public boolean isActive() { |
|
57 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows(); |
|
58 |
for (int i = 0; i < windows.length; i++) { |
|
59 |
if(windows[i] instanceof AbstractViewPanel) { |
|
60 |
FLayers lyrs = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext().getLayers(); |
|
61 |
for (int j = 0; j < lyrs.getLayersCount(); j++) { |
|
62 |
if(lyrs.getLayer(j) instanceof FLyrRaster) |
|
63 |
return true; |
|
64 |
} |
|
65 |
} |
|
66 |
} |
|
67 |
return false; |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Returns true if the plugin which gives the functionality is installed |
|
72 |
* in gvSIG |
|
73 |
* @return |
|
74 |
*/ |
|
75 |
public abstract boolean isPluginInstalled(); |
|
76 |
|
|
77 |
/** |
|
78 |
* Loads the raster layer for the tool |
|
79 |
* @return |
|
80 |
*/ |
|
81 |
public boolean loadLayer() { |
|
82 |
if(!isPluginInstalled()) { |
|
83 |
RasterSwingLibrary.messageBoxError(Messages.getText("plugin_not_installed"), null); |
|
84 |
return false; |
|
85 |
} |
|
86 |
|
|
87 |
if(!isActive()) { |
|
88 |
RasterSwingLibrary.messageBoxError(Messages.getText("layer_not_valid"), null); |
|
89 |
return false; |
|
90 |
} |
|
91 |
|
|
92 |
boolean existsRasterButNotActive = false; |
|
93 |
lyr = null; |
|
94 |
IWindow[] windows = PluginServices.getMDIManager().getOrderedWindows(); |
|
95 |
MapContext mapCtx = null; |
|
96 |
for (int i = 0; i < windows.length; i++) { |
|
97 |
if(windows[i] instanceof AbstractViewPanel) { |
|
98 |
mapCtx = ((AbstractViewPanel)windows[i]).getMapControl().getMapContext(); |
|
99 |
break; |
|
100 |
} |
|
101 |
} |
|
102 |
|
|
103 |
IRasterLayer[] layers = SextanteGUI.getInputFactory().getRasterLayers(); |
|
104 |
for (int i = 0; i < layers.length; i++) { |
|
105 |
FLyrRaster l = (FLyrRaster)((FLyrRasterIRasterLayer)layers[i]).getBaseDataObject(); |
|
106 |
existsRasterButNotActive = true; |
|
107 |
if(l.isActive() && mapCtx == l.getMapContext()) { |
|
108 |
existsRasterButNotActive = false; |
|
109 |
lyr = l; |
|
110 |
break; |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
if(existsRasterButNotActive) { |
|
115 |
RasterSwingLibrary.messageBoxError(Messages.getText("raster_layer_not_active"), null); |
|
116 |
return false; |
|
117 |
} |
|
118 |
|
|
119 |
return true; |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
0 | 123 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/toolbox/ROIMaskToolboxAction.java | ||
---|---|---|
1 |
/** |
|
2 |
* gvSIG. Desktop Geographic Information System. |
|
3 |
* |
|
4 |
* Copyright (C) 2007-2012 gvSIG Association. |
|
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 |
* For any additional information, do not hesitate to contact us |
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com. |
|
23 |
*/ |
|
24 |
|
|
25 |
|
|
26 |
package org.gvsig.raster.roimask.app.toolbox; |
|
27 |
|
|
28 |
import javax.swing.ImageIcon; |
|
29 |
|
|
30 |
import org.gvsig.andami.IconThemeHelper; |
|
31 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
32 |
import org.gvsig.geoprocess.sextante.gui.core.GUIFactory; |
|
33 |
import org.gvsig.i18n.Messages; |
|
34 |
import org.gvsig.raster.roimask.app.ROIMaskTocMenuEntry; |
|
35 |
|
|
36 |
/** |
|
37 |
* Input in Sextante framework for clip tool |
|
38 |
* |
|
39 |
* @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a> |
|
40 |
*/ |
|
41 |
public class ROIMaskToolboxAction extends AbstractToolboxAction { |
|
42 |
|
|
43 |
public ROIMaskToolboxAction() { |
|
44 |
ImageIcon ico = IconThemeHelper.getImageIcon("gvsig-icon16x16"); |
|
45 |
GUIFactory.registerExternalTool(Messages.getText("gv_tools"), ico, this); |
|
46 |
} |
|
47 |
|
|
48 |
@Override |
|
49 |
public void execute() { |
|
50 |
if(!super.loadLayer()) |
|
51 |
return; |
|
52 |
|
|
53 |
ROIMaskTocMenuEntry.getSingleton().execute(null, new FLayer[]{lyr}); |
|
54 |
} |
|
55 |
|
|
56 |
@Override |
|
57 |
public String getName() { |
|
58 |
return Messages.getText("roimask"); |
|
59 |
} |
|
60 |
|
|
61 |
public ImageIcon getIcon() { |
|
62 |
return (ImageIcon)ROIMaskTocMenuEntry.getSingleton().getIcon(); |
|
63 |
} |
|
64 |
|
|
65 |
public boolean isPluginInstalled() { |
|
66 |
try { |
|
67 |
ROIMaskTocMenuEntry.getSingleton(); |
|
68 |
} catch(Exception e) { |
|
69 |
return false; |
|
70 |
} catch(Error e) { |
|
71 |
return false; |
|
72 |
} |
|
73 |
return true; |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
0 | 77 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/ROIMaskPreview.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app; |
|
2 |
|
|
3 |
import java.awt.Graphics2D; |
|
4 |
import java.awt.geom.Rectangle2D; |
|
5 |
import java.awt.image.BufferedImage; |
|
6 |
import java.io.File; |
|
7 |
import java.util.ArrayList; |
|
8 |
import java.util.HashMap; |
|
9 |
import java.util.List; |
|
10 |
|
|
11 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
12 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
13 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
14 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
|
15 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
|
16 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
17 |
import org.gvsig.fmap.dal.coverage.exception.ROIException; |
|
18 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
|
19 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
|
20 |
import org.gvsig.fmap.dal.coverage.grid.render.ImageDrawer; |
|
21 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
22 |
import org.gvsig.fmap.dal.coverage.store.props.Transparency; |
|
23 |
import org.gvsig.gui.beans.imagenavigator.ImageUnavailableException; |
|
24 |
import org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary; |
|
25 |
import org.gvsig.raster.algorithm.process.DataProcess; |
|
26 |
import org.gvsig.raster.algorithm.process.ProcessException; |
|
27 |
import org.gvsig.raster.algorithm.process.ProcessParamsManagement; |
|
28 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
|
29 |
import org.gvsig.raster.roi.ROI; |
|
30 |
import org.gvsig.raster.roimask.algorithm.ROIMaskProcess; |
|
31 |
import org.gvsig.raster.roimask.app.ROIMaskExtension.LayerElement; |
|
32 |
import org.gvsig.raster.roimask.swing.ROIMaskData; |
|
33 |
import org.gvsig.raster.swing.preview.DataSourcePreview; |
|
34 |
import org.gvsig.tools.task.Cancellable; |
|
35 |
import org.slf4j.Logger; |
|
36 |
import org.slf4j.LoggerFactory; |
|
37 |
|
|
38 |
@SuppressWarnings("deprecation") |
|
39 |
public class ROIMaskPreview implements DataSourcePreview { |
|
40 |
private FLyrRaster inputLyr = null; |
|
41 |
private Extent bbox = null; |
|
42 |
private ROIMaskData data = null; |
|
43 |
private static final Logger logger = LoggerFactory.getLogger(ROIMaskPreview.class); |
|
44 |
|
|
45 |
|
|
46 |
public void setData(ROIMaskData data) { |
|
47 |
this.data = data; |
|
48 |
loadLayers(); |
|
49 |
} |
|
50 |
|
|
51 |
private void loadLayers() { |
|
52 |
if(data == null) |
|
53 |
return; |
|
54 |
Object obj = data.getInputLayer(); |
|
55 |
if(obj != null) |
|
56 |
inputLyr = (FLyrRaster)((LayerElement)data.getInputLayer()).getLayer(); |
|
57 |
if(inputLyr != null) |
|
58 |
bbox = inputLyr.getFullRasterExtent(); |
|
59 |
} |
|
60 |
|
|
61 |
public void closePreviewLayer() { |
|
62 |
|
|
63 |
} |
|
64 |
|
|
65 |
public double getCellSize() { |
|
66 |
if(inputLyr != null) |
|
67 |
return inputLyr.getDataStore().getCellSize(); |
|
68 |
return 1; |
|
69 |
} |
|
70 |
|
|
71 |
public DataSourcePreview cloneDataSourcePreview() { |
|
72 |
return this; |
|
73 |
} |
|
74 |
|
|
75 |
public void popStatus() { |
|
76 |
} |
|
77 |
|
|
78 |
public void pushStatus() { |
|
79 |
} |
|
80 |
|
|
81 |
public void draw(BufferedImage image, Graphics2D g, double[] coords, int w, int h, Cancellable cancel, double scale) throws ImageUnavailableException { |
|
82 |
//Posici?n de inicio dibujado dentro del Graphics |
|
83 |
int x = 0; |
|
84 |
int y = 0; |
|
85 |
//Coordenadas de la petici?n |
|
86 |
double iniX = coords[0]; |
|
87 |
double iniY = coords[1]; |
|
88 |
double endX = coords[2]; |
|
89 |
double endY = coords[3]; |
|
90 |
|
|
91 |
//Se ajustan las coordenadas de petici?n, ancho y alto en coordenadas p?xel, |
|
92 |
//as? como la coordenada de inicio de dibujado |
|
93 |
if(bbox.getULX() > coords[0]) { |
|
94 |
iniX = bbox.getULX(); |
|
95 |
x = (int)(((iniX - coords[0]) * w) / Math.abs(coords[2] - coords[0])); |
|
96 |
} |
|
97 |
|
|
98 |
if(bbox.getULY() < coords[1]) { |
|
99 |
iniY = bbox.getULY(); |
|
100 |
y = (int)(((coords[1] - iniY) * h) / Math.abs(coords[3] - coords[1])); |
|
101 |
} |
|
102 |
|
|
103 |
if(bbox.getLRX() < coords[2]) |
|
104 |
endX = bbox.getLRX(); |
|
105 |
|
|
106 |
if(bbox.getLRY() > coords[3]) |
|
107 |
endY = bbox.getLRY(); |
|
108 |
|
|
109 |
if(iniX != coords[0] || endX != coords[2]) { |
|
110 |
w = (int)((Math.abs(endX - iniX) * w) / Math.abs(coords[2] - coords[0])); |
|
111 |
} |
|
112 |
|
|
113 |
if(iniY != coords[1] || endY != coords[3]) { |
|
114 |
h = (int)((Math.abs(iniY - endY) * h) / Math.abs(coords[3] - coords[1])); |
|
115 |
} |
|
116 |
|
|
117 |
Extent ext = RasterLocator.getManager().getDataStructFactory().createExtent(iniX, iniY, endX, endY); |
|
118 |
BufferedImage img = throwProcess(ext, w, h); |
|
119 |
g.drawImage(img, x, y, null); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Throws the process sequentially. Since the preview is small, |
|
124 |
* it should not taken a lot of time |
|
125 |
* is small |
|
126 |
* @param ext |
|
127 |
* @param w |
|
128 |
* @param h |
|
129 |
* @return |
|
130 |
*/ |
|
131 |
private BufferedImage throwProcess(Extent ext, int w, int h) { |
|
132 |
loadLayers(); |
|
133 |
|
|
134 |
DataProcess task; |
|
135 |
try { |
|
136 |
task = RasterBaseAlgorithmLibrary.getManager().createRasterTask("ROIMaskProcess"); |
|
137 |
task.addParam(ROIMaskProcess.RASTER_STORE1, inputLyr.getDataStore()); |
|
138 |
|
|
139 |
task.addParam(ProcessParamsManagement.PREVIEW, true); |
|
140 |
task.addParam(ProcessParamsManagement.WINDOW, ext); |
|
141 |
task.addParam(ProcessParamsManagement.OUTPUT_WIDTH, w); |
|
142 |
task.addParam(ProcessParamsManagement.OUTPUT_HEIGHT, h); |
|
143 |
|
|
144 |
task.addParam(ROIMaskProcess.ROIS, getROIsSelected()); |
|
145 |
task.addParam(ROIMaskProcess.ALPHA, data.getAlpha()); |
|
146 |
task.addParam(ROIMaskProcess.INVERSE, data.isInverse()); |
|
147 |
task.addParam(ROIMaskProcess.NODATA, getNoDataSelected()); |
|
148 |
} catch (ProcessException e1) { |
|
149 |
logger.debug("Error creating task", e1); |
|
150 |
return null; |
|
151 |
} catch (ROIException e) { |
|
152 |
logger.debug("Error creating task", e); |
|
153 |
return null; |
|
154 |
} |
|
155 |
|
|
156 |
task.init(); |
|
157 |
try { |
|
158 |
task.process(); |
|
159 |
} catch (ProcessInterruptedException e1) { |
|
160 |
return null; |
|
161 |
} catch (ProcessException e) { |
|
162 |
logger.debug("Error in process"); |
|
163 |
return null; |
|
164 |
} |
|
165 |
|
|
166 |
HashMap<String, Object> map = (HashMap<String, Object>)task.getResult(); |
|
167 |
Buffer buf = (Buffer)map.get(ROIMaskProcess.BUFFER); |
|
168 |
buf.setDataExtent(ext.toRectangle2D()); |
|
169 |
|
|
170 |
ColorInterpretation ci = inputLyr.getDataStore().getColorInterpretation(); |
|
171 |
Transparency transparency = null; |
|
172 |
if(ci.isRGB() || ci.isRGBA()) { |
|
173 |
Integer alphaBandNumber = (Integer)map.get(ROIMaskProcess.ALPHA_BAND); |
|
174 |
transparency = RasterLocator.getManager().getDataStructFactory().createTransparency(buf.getBandCount()); |
|
175 |
transparency.setTransparencyBand(alphaBandNumber); |
|
176 |
transparency.activeTransparency(); |
|
177 |
} |
|
178 |
|
|
179 |
ImageDrawer drawer = RasterLocator.getManager().createImageDrawerService(); |
|
180 |
drawer.setBuffer(buf); |
|
181 |
drawer.setLastTransparency(transparency); |
|
182 |
try { |
|
183 |
applyFiltersToPreview(drawer); |
|
184 |
|
|
185 |
return (BufferedImage)drawer.drawBufferOverImageObject(); |
|
186 |
} catch (ProcessInterruptedException e) { |
|
187 |
return null; |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
/** |
|
192 |
* Adds filters to the preview. If the original render has a color table |
|
193 |
* , a generic enhanced will be added. |
|
194 |
* @param drawer |
|
195 |
*/ |
|
196 |
private void applyFiltersToPreview(ImageDrawer drawer) { |
|
197 |
RasterFilterList filterList = inputLyr.getRender().getFilterList(); |
|
198 |
List<RasterFilter> list = new ArrayList<RasterFilter>(); |
|
199 |
if(filterList.lenght() > 0) { |
|
200 |
for (int i = 0; i < filterList.lenght(); i++) { |
|
201 |
RasterFilter rf = filterList.get(i); |
|
202 |
if(rf.getName().equals("colortable")) { |
|
203 |
drawer.addEnhanced(inputLyr.getDataStore().getStatistics(), true, 0.2); |
|
204 |
return; |
|
205 |
} |
|
206 |
list.add(rf); |
|
207 |
} |
|
208 |
} |
|
209 |
try { |
|
210 |
drawer.addFilters(inputLyr.getDataStore().getStatistics(), list); |
|
211 |
} catch (FilterTypeException e) { |
|
212 |
logger.debug("Tirando sin filtros", e); |
|
213 |
} |
|
214 |
} |
|
215 |
|
|
216 |
private NoData getNoDataSelected() { |
|
217 |
NoData nodata = RasterLocator.getManager().getDataStructFactory().createDefaultNoData( |
|
218 |
inputLyr.getDataStore().getBandCount(), inputLyr.getDataStore().getDataType()[0]); |
|
219 |
nodata.setValue(data.getValueNoData()); |
|
220 |
return nodata; |
|
221 |
} |
|
222 |
|
|
223 |
private ROI[] getROIsSelected() throws ROIException { |
|
224 |
List<ROI> roi = inputLyr.getRois(); |
|
225 |
boolean[] roisSelected = data.getROIsSelected(); |
|
226 |
List<ROI> roisToDraw = new ArrayList<ROI>(); |
|
227 |
for (int i = 0; i < roisSelected.length; i++) { |
|
228 |
if(roisSelected[i]) |
|
229 |
roisToDraw.add(roi.get(i)); |
|
230 |
} |
|
231 |
return roisToDraw.toArray(new ROI[0]); |
|
232 |
} |
|
233 |
|
|
234 |
public Object getSource() { |
|
235 |
return null; |
|
236 |
} |
|
237 |
|
|
238 |
public Rectangle2D getBBoxRectangle() { |
|
239 |
if(inputLyr != null) |
|
240 |
return inputLyr.getFullRasterExtent().toRectangle2D(); |
|
241 |
return new Rectangle2D.Double(); |
|
242 |
} |
|
243 |
|
|
244 |
public void addParams(DataProcess task, String path, String fileName) throws ROIException { |
|
245 |
if(!fileName.matches("([*]\\.[???])")) { |
|
246 |
fileName += ".tif"; |
|
247 |
} |
|
248 |
task.addParam(ROIMaskProcess.PATH, path + File.separator + fileName); |
|
249 |
task.addParam(ROIMaskProcess.RASTER_STORE1, inputLyr.getDataStore()); |
|
250 |
task.addParam(ROIMaskProcess.ROIS, getROIsSelected()); |
|
251 |
task.addParam(ROIMaskProcess.ALPHA, data.getAlpha()); |
|
252 |
task.addParam(ROIMaskProcess.INVERSE, data.isInverse()); |
|
253 |
task.addParam(ROIMaskProcess.NODATA, getNoDataSelected()); |
|
254 |
} |
|
255 |
} |
|
0 | 256 |
org.gvsig.raster.roimask/tags/org.gvsig.raster.roimask-2.2.186/org.gvsig.raster.roimask.app/org.gvsig.raster.roimask.app.client/src/main/java/org/gvsig/raster/roimask/app/ROIMaskWindow.java | ||
---|---|---|
1 |
package org.gvsig.raster.roimask.app; |
|
2 |
|
|
3 |
import java.awt.BorderLayout; |
|
4 |
import java.awt.GridBagConstraints; |
|
5 |
import java.awt.GridBagLayout; |
|
6 |
import java.awt.event.ActionEvent; |
|
7 |
import java.awt.event.ActionListener; |
|
8 |
|
|
9 |
import javax.swing.JComponent; |
|
10 |
import javax.swing.JPanel; |
|
11 |
import javax.swing.JSplitPane; |
|
12 |
import javax.swing.border.Border; |
|
13 |
import javax.swing.plaf.basic.BasicSplitPaneDivider; |
|
14 |
import javax.swing.plaf.basic.BasicSplitPaneUI; |
|
15 |
|
|
16 |
import org.gvsig.andami.PluginServices; |
|
17 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
18 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
|
19 |
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel; |
|
20 |
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel; |
|
21 |
|
|
22 |
public class ROIMaskWindow extends DefaultButtonsPanel implements IWindow, ActionListener { |
|
23 |
|
|
24 |
private static final long serialVersionUID = -4401123724140025094L; |
|
25 |
private ActionListener listener = null; |
|
26 |
private WindowInfo info = null; |
|
27 |
|
|
28 |
private Object profile = WindowInfo.EDITOR_PROFILE; |
|
29 |
|
|
30 |
public ROIMaskWindow(JComponent panel, |
|
31 |
JComponent preview, |
|
32 |
String title, |
|
33 |
int w, |
|
34 |
int h, |
|
35 |
boolean fixedPreview, |
|
36 |
ActionListener actionListener) { |
|
37 |
this.listener = actionListener; |
|
38 |
|
|
39 |
if(fixedPreview) |
|
40 |
fixedPreview(panel, preview); |
|
41 |
else |
|
42 |
redimPreview(panel, preview); |
|
43 |
|
|
44 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT).addActionListener(this); |
|
45 |
//Se elimina el bot?n aplicar pq la ventana es modal. Lo que ocurre es que al terminar el proceso se |
|
46 |
//lanza el dialogo de cargar la capa en el TOC que tambi?n es modal. Esto provoca una excepci?n. El bot?n |
|
47 |
//de aceptar no da problemas pq este cierra antes la ventana inferior. |
|
48 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).setVisible(false); |
|
49 |
//getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY).addActionListener(this); |
|
50 |
getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL).addActionListener(this); |
|
51 |
|
|
52 |
info = new WindowInfo(WindowInfo.PALETTE | WindowInfo.RESIZABLE); |
|
53 |
info.setTitle(title); |
|
54 |
info.setWidth(w); |
|
55 |
info.setHeight(h); |
|
56 |
} |
|
57 |
|
|
58 |
private void fixedPreview(JComponent panel, JComponent preview) { |
|
59 |
setLayout(new GridBagLayout()); |
|
60 |
GridBagConstraints gbc = new GridBagConstraints(); |
|
61 |
gbc.fill = GridBagConstraints.BOTH; |
|
62 |
gbc.weightx = 1; |
|
63 |
gbc.weighty = 1; |
|
64 |
add(panel, gbc); |
|
65 |
|
|
66 |
if(preview != null) { |
|
67 |
gbc.anchor = GridBagConstraints.NORTH; |
|
68 |
gbc.fill = GridBagConstraints.NONE; |
|
69 |
gbc.weightx = 0; |
|
70 |
gbc.weighty = 0; |
|
71 |
gbc.gridx = 1; |
|
72 |
add(preview, gbc); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
private void redimPreview(JComponent panel, JComponent preview) { |
|
77 |
setLayout(new BorderLayout()); |
|
78 |
JSplitPane splitPane = new JSplitPane(); |
|
79 |
splitPane.setLeftComponent(panel); |
|
80 |
splitPane.setRightComponent(getPreviewForRedimPreviewPanel(preview)); |
|
81 |
splitPane.setResizeWeight(1.0); |
|
82 |
splitPane.setContinuousLayout(true); |
|
83 |
splitPane.setOneTouchExpandable(true); |
|
84 |
splitPane.setUI(new BasicSplitPaneUI() { |
|
85 |
public BasicSplitPaneDivider createDefaultDivider() { |
|
86 |
return new BasicSplitPaneDivider(this) { |
|
87 |
private static final long serialVersionUID = 1L; |
|
88 |
|
|
89 |
public void setBorder(Border b) { |
|
90 |
} |
|
91 |
}; |
|
92 |
} |
|
93 |
}); |
|
94 |
splitPane.setBorder(null); |
|
95 |
add(splitPane, BorderLayout.CENTER); |
|
96 |
} |
|
97 |
|
|
98 |
private JSplitPane getPreviewForRedimPreviewPanel(JComponent preview) { |
|
99 |
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); |
|
100 |
splitPane.setTopComponent(preview); |
|
101 |
splitPane.setBottomComponent(new JPanel()); |
|
102 |
splitPane.setResizeWeight(0); |
|
103 |
splitPane.setContinuousLayout(true); |
|
104 |
splitPane.setOneTouchExpandable(true); |
|
105 |
splitPane.setUI(new BasicSplitPaneUI() { |
|
106 |
public BasicSplitPaneDivider createDefaultDivider() { |
|
107 |
return new BasicSplitPaneDivider(this) { |
|
108 |
private static final long serialVersionUID = 1L; |
|
109 |
|
|
110 |
public void setBorder(Border b) { |
|
111 |
} |
|
112 |
}; |
|
113 |
} |
|
114 |
}); |
|
115 |
splitPane.setBorder(null); |
|
116 |
return splitPane; |
|
117 |
} |
|
118 |
|
|
119 |
public WindowInfo getWindowInfo() { |
|
120 |
return info; |
|
121 |
} |
|
122 |
|
|
123 |
public Object getWindowProfile() { |
|
124 |
return profile; |
|
125 |
} |
|
126 |
|
|
127 |
public void actionPerformed(ActionEvent e) { |
|
128 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_ACCEPT)) { |
|
129 |
listener.actionPerformed(e); |
|
130 |
PluginServices.getMDIManager().closeWindow(this); |
|
131 |
} |
|
132 |
|
|
133 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_APPLY)) { |
|
134 |
listener.actionPerformed(e); |
|
135 |
} |
|
136 |
|
|
137 |
if(e.getSource() == getButtonsPanel().getButton(ButtonsPanel.BUTTON_CANCEL)) { |
|
138 |
PluginServices.getMDIManager().closeWindow(this); |
|
139 |
} |
|
140 |
} |
|
141 |
} |
|
0 | 142 |
Also available in: Unified diff