gvsig-raster / org.gvsig.raster.roimask / trunk / org.gvsig.raster.roimask / org.gvsig.raster.roimask.lib / org.gvsig.raster.roimask.lib.impl / src / main / java / org / gvsig / raster / roimask / lib / impl / regionalpha / RegionAlphaListManager.java @ 2341
History | View | Annotate | Download (4.49 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.roimask.lib.impl.regionalpha; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
32 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
33 |
|
34 |
public class RegionAlphaListManager extends AbstractRasterFilterManager { |
35 |
public static String ID = "RegionAlpha"; |
36 |
|
37 |
/**
|
38 |
* Default constructor. Sets the filter list.
|
39 |
* @param filterList
|
40 |
*/
|
41 |
public RegionAlphaListManager(RasterFilterList filterList) {
|
42 |
super(filterList);
|
43 |
} |
44 |
|
45 |
public static void register() { |
46 |
AbstractRasterFilterManager.register(ID, RegionAlphaListManager.class, RegionAlphaUI.class); |
47 |
} |
48 |
|
49 |
public String getManagerID() { |
50 |
return ID;
|
51 |
} |
52 |
|
53 |
public boolean isDataTypeSupported(int dataType) { |
54 |
return true; |
55 |
} |
56 |
|
57 |
public Class<?> getFilterClassByID(String id) { |
58 |
if( id.compareTo("regionalpha") == 0) |
59 |
return RegionAlphaFilter.class;
|
60 |
return null; |
61 |
} |
62 |
|
63 |
public void addRegionAlphaFilter(boolean[] selectedROI, int alpha, Boolean inverse) throws FilterTypeException { |
64 |
RasterFilter filter = new RegionAlphaByteFilter();
|
65 |
|
66 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
67 |
if (filter != null) { |
68 |
filter.addParam("inverse", inverse);
|
69 |
filter.addParam("alpha", Integer.valueOf(alpha)); |
70 |
filter.addParam("selected_roi", selectedROI);
|
71 |
getFilterList().add(filter); |
72 |
} |
73 |
} |
74 |
|
75 |
public List<Class<?>> getRasterFilterList() { |
76 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
77 |
filters.add(RegionAlphaFilter.class); |
78 |
return filters;
|
79 |
} |
80 |
|
81 |
public RasterFilter createFilter(Params params) {
|
82 |
boolean[] selectedROI = ((boolean[]) params.getParamById("selected_roi").getDefaultValue()); |
83 |
Boolean inverse = ((Boolean) params.getParamById("inverse").getDefaultValue()); |
84 |
Integer alpha = ((Integer) params.getParamById("Alpha").getDefaultValue()); |
85 |
|
86 |
RasterFilter filter = new RegionAlphaByteFilter();
|
87 |
filter.addParam("selected_roi", selectedROI);
|
88 |
filter.addParam("inverse", inverse);
|
89 |
filter.addParam("alpha", alpha);
|
90 |
return filter;
|
91 |
} |
92 |
|
93 |
public void addFilter(Params params) throws FilterTypeException { |
94 |
addFilter(RegionAlphaFilter.class, params); |
95 |
} |
96 |
|
97 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
98 |
if (classFilter.equals(RegionAlphaFilter.class)) {
|
99 |
boolean[] selectedROI = null; |
100 |
Boolean inverse = new Boolean(false); |
101 |
int alpha = 255; |
102 |
|
103 |
Params paramsUI = null;
|
104 |
for (int i = 0; i < params.getNumParams(); i++) { |
105 |
if (params.getParam(i).getId().equals("Panel") && |
106 |
params.getParam(i).getDefaultValue() instanceof RegistrableFilterListener) {
|
107 |
paramsUI = ((RegistrableFilterListener) params.getParam(i).getDefaultValue()).getParams(); |
108 |
} |
109 |
if (params.getParam(i).getId().equals("Alpha") && params.getParam(i).getDefaultValue() instanceof Integer) { |
110 |
alpha = ((Integer) params.getParam(i).getDefaultValue()).intValue();
|
111 |
} |
112 |
} |
113 |
|
114 |
if (paramsUI != null) { |
115 |
for (int i = 0; i < paramsUI.getNumParams(); i++) { |
116 |
if (paramsUI.getParam(i).getId().equals("selected_roi")) |
117 |
selectedROI = (boolean[]) paramsUI.getParam(i).getDefaultValue(); |
118 |
if (paramsUI.getParam(i).getId().equals("inverse")) |
119 |
inverse = (Boolean) paramsUI.getParam(i).getDefaultValue();
|
120 |
} |
121 |
} |
122 |
addRegionAlphaFilter(selectedROI, alpha, inverse); |
123 |
} |
124 |
} |
125 |
} |