root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / bands / ColorTableListManager.java @ 12567
History | View | Annotate | Download (7.08 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.grid.filter.bands; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.datastruct.ColorTable; |
25 |
import org.gvsig.raster.grid.GridPalette; |
26 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
27 |
import org.gvsig.raster.grid.filter.RasterFilter; |
28 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
29 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
30 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
32 |
|
33 |
/**
|
34 |
* Gestor del filtro de aplicaci?n de tablas de color sobre un raster.
|
35 |
*
|
36 |
* @version 06/06/2007
|
37 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
38 |
*
|
39 |
*/
|
40 |
public class ColorTableListManager implements IRasterFilterListManager { |
41 |
|
42 |
protected RasterFilterList filterList = null; |
43 |
private RasterFilterListManager filterListManager = null; |
44 |
|
45 |
public static void register() { |
46 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
47 |
extensionPoints.add("RasterFilter", "ColorTable", ColorTableListManager.class); |
48 |
} |
49 |
|
50 |
/**
|
51 |
* Constructor.
|
52 |
* Asigna la lista de filtros y el managener global.
|
53 |
*
|
54 |
* @param filterListManager
|
55 |
*/
|
56 |
public ColorTableListManager(RasterFilterListManager filterListManager) {
|
57 |
this.filterListManager = filterListManager;
|
58 |
this.filterList = filterListManager.getFilterList();
|
59 |
} |
60 |
|
61 |
/**
|
62 |
* A?ade un filtro de tabla de color a la pila de filtros.
|
63 |
* @param ladoVentana
|
64 |
*/
|
65 |
public void addColorTableFilter(GridPalette palette) { |
66 |
RasterFilter filter = new ColorTableByteFilter();
|
67 |
|
68 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
69 |
|
70 |
if (filter != null) { |
71 |
filter.addParam("colorTable", palette);
|
72 |
filterList.add(filter); |
73 |
} |
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
|
79 |
*/
|
80 |
public ArrayList getRasterFilterList() { |
81 |
ArrayList filters = new ArrayList(); |
82 |
filters.add(ColorTableFilter.class); |
83 |
return filters;
|
84 |
} |
85 |
|
86 |
public void addFilter(Class classFilter, Params params) { |
87 |
if (classFilter.equals(ColorTableFilter.class)) {
|
88 |
GridPalette colorTable = null;
|
89 |
for (int i = 0; i < params.getNumParams(); i++) { |
90 |
if (params.getParam(i).id.equals("colorTable")) |
91 |
colorTable = (GridPalette) params.getParam(i).defaultValue; |
92 |
} |
93 |
addColorTableFilter(colorTable); |
94 |
} |
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
100 |
*/
|
101 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) { |
102 |
if(fil.startsWith("filter.colortable.active")) { |
103 |
|
104 |
boolean exec = true; |
105 |
if((RasterFilterListManager.getValue(fil).equals("false"))) |
106 |
exec = false;
|
107 |
|
108 |
ColorTable colorTable = new ColorTable();
|
109 |
int lengthList = 0; |
110 |
|
111 |
filters.remove(0);
|
112 |
for(int prop = 0; prop < filters.size() ; prop++) { |
113 |
String elem = (String) filters.get(prop); |
114 |
|
115 |
if(elem.startsWith("filter.colortable.values")) { |
116 |
String[] listString = RasterFilterListManager.getValue(elem).split(" "); |
117 |
int[] listInt = new int[listString.length]; |
118 |
for(int i = 0; i < listString.length; i++) |
119 |
listInt[i] = Integer.parseInt(listString[i]);
|
120 |
colorTable.setColorTable(listInt); |
121 |
filters.remove(prop); |
122 |
prop--; |
123 |
} |
124 |
/*
|
125 |
if(elem.startsWith("filter.colortable.type")) {
|
126 |
colorTable.setType(Integer.parseInt(RasterFilterListManager.getValue(elem)));
|
127 |
filters.remove(prop);
|
128 |
prop--;
|
129 |
}
|
130 |
|
131 |
if(elem.startsWith("filter.colortable.range")) {
|
132 |
String[] listString = RasterFilterListManager.getValue(elem).split(" ");
|
133 |
lengthList = listString.length;
|
134 |
if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) {
|
135 |
int[] listInt = new int[listString.length];
|
136 |
for(int i = 0; i < listString.length; i++)
|
137 |
listInt[i] = Integer.parseInt(listString[i]);
|
138 |
colorTable.setIntRange(listInt);
|
139 |
} else {
|
140 |
double[] listDouble = new double[listString.length];
|
141 |
for(int i = 0; i < listString.length; i++)
|
142 |
listDouble[i] = Double.parseDouble(listString[i]);
|
143 |
colorTable.setDoubleRange(listDouble);
|
144 |
}
|
145 |
filters.remove(prop);
|
146 |
prop--;
|
147 |
}
|
148 |
*/
|
149 |
|
150 |
if(elem.startsWith("filter.colortable.names")) { |
151 |
String[] listString = RasterFilterListManager.getValue(elem).split(" "); |
152 |
if(listString.length == 0) { |
153 |
listString = new String[lengthList]; |
154 |
for(int i = 0; i < listString.length; i++) |
155 |
listString[i] = "";
|
156 |
} |
157 |
colorTable.setNameClass(listString); |
158 |
filters.remove(prop); |
159 |
prop--; |
160 |
} |
161 |
|
162 |
} |
163 |
filterList.remove(ColorTableFilter.class); |
164 |
addColorTableFilter(new GridPalette(colorTable));
|
165 |
|
166 |
ColorTableFilter ct = (ColorTableFilter)filterList.getFilterByBaseClass(ColorTableFilter.class); |
167 |
ct.setExec(exec); |
168 |
} |
169 |
return filteri;
|
170 |
} |
171 |
|
172 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
173 |
if(rf instanceof ColorTableFilter) { |
174 |
ColorTableFilter colorTableFilter = (ColorTableFilter)rf; |
175 |
ColorTable colorTable = (ColorTable)colorTableFilter.getParam("colorTable");
|
176 |
if (colorTable != null) { |
177 |
if (colorTableFilter.isExec())
|
178 |
filterList.add("filter.colortable.active=true");
|
179 |
else
|
180 |
filterList.add("filter.colortable.active=false");
|
181 |
/*
|
182 |
filterList.add("filter.colortable.type=" + colorTable.getType());
|
183 |
|
184 |
String range = "";
|
185 |
if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) {
|
186 |
for(int i = 0; i < colorTable.getIntRange().length; i++)
|
187 |
range += colorTable.getIntRange()[i] + " ";
|
188 |
} else {
|
189 |
for(int i = 0; i < colorTable.getDoubleRange().length; i++)
|
190 |
range += colorTable.getDoubleRange()[i] + " ";
|
191 |
}
|
192 |
filterList.add("filter.colortable.range=" + range);
|
193 |
|
194 |
String values = "";
|
195 |
for(int i = 0; i < colorTable.getColorTable().length; i++)
|
196 |
values += colorTable.getColorTable()[i] + " ";
|
197 |
filterList.add("filter.colortable.values=" + values);
|
198 |
*/
|
199 |
|
200 |
String names = ""; |
201 |
for(int i = 0; i < colorTable.getNameClass().length; i++) |
202 |
names += colorTable.getNameClass()[i] + " ";
|
203 |
filterList.add("filter.colortable.names=" + names);
|
204 |
} |
205 |
} |
206 |
return filterList;
|
207 |
} |
208 |
|
209 |
} |