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