root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / bands / ColorTableListManager.java @ 12504
History | View | Annotate | Download (7.12 KB)
1 | 12066 | nacho | /* 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 | 12220 | nacho | import org.gvsig.raster.dataset.IBuffer; |
24 | 12066 | nacho | import org.gvsig.raster.dataset.Params; |
25 | 12383 | nacho | import org.gvsig.raster.datastruct.ColorTable; |
26 | 12066 | nacho | 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 | 12333 | bsanchez | *
|
37 | 12066 | nacho | * @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 | 12122 | bsanchez | |
46 | public static void register() { |
||
47 | 12066 | nacho | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
48 | extensionPoints.add("RasterFilter", "ColorTable", ColorTableListManager.class); |
||
49 | } |
||
50 | 12122 | bsanchez | |
51 | 12066 | nacho | /**
|
52 | * Constructor.
|
||
53 | * Asigna la lista de filtros y el managener global.
|
||
54 | 12333 | bsanchez | *
|
55 | 12066 | nacho | * @param filterListManager
|
56 | */
|
||
57 | public ColorTableListManager(RasterFilterListManager filterListManager) {
|
||
58 | this.filterListManager = filterListManager;
|
||
59 | this.filterList = filterListManager.getFilterList();
|
||
60 | } |
||
61 | 12122 | bsanchez | |
62 | 12066 | nacho | /**
|
63 | * A?ade un filtro de tabla de color a la pila de filtros.
|
||
64 | * @param ladoVentana
|
||
65 | */
|
||
66 | 12166 | bsanchez | public void addColorTableFilter(GridPalette palette) { |
67 | RasterFilter filter = new ColorTableByteFilter();
|
||
68 | 12066 | nacho | |
69 | //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
||
70 | |||
71 | 12166 | bsanchez | if (filter != null) { |
72 | filter.addParam("colorTable", palette);
|
||
73 | filterList.add(filter); |
||
74 | 12066 | nacho | } |
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 | 12122 | bsanchez | |
87 | 12066 | nacho | public void addFilter(Class classFilter, Params params) { |
88 | 12333 | bsanchez | 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 | 12066 | nacho | } |
97 | |||
98 | 12220 | nacho | /*
|
99 | * (non-Javadoc)
|
||
100 | * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
||
101 | */
|
||
102 | 12066 | nacho | public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) { |
103 | 12220 | nacho | if(fil.startsWith("filter.colortable.active")) { |
104 | 12333 | bsanchez | |
105 | 12220 | nacho | boolean exec = true; |
106 | if((RasterFilterListManager.getValue(fil).equals("false"))) |
||
107 | exec = false;
|
||
108 | 12333 | bsanchez | |
109 | ColorTable colorTable = new ColorTable();
|
||
110 | 12220 | nacho | int lengthList = 0; |
111 | 12333 | bsanchez | |
112 | 12220 | nacho | filters.remove(0);
|
113 | 12333 | bsanchez | for(int prop = 0; prop < filters.size() ; prop++) { |
114 | 12220 | nacho | String elem = (String) filters.get(prop); |
115 | 12333 | bsanchez | |
116 | 12220 | nacho | 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 | 12504 | bsanchez | /*
|
126 | if(elem.startsWith("filter.colortable.type")) {
|
||
127 | colorTable.setType(Integer.parseInt(RasterFilterListManager.getValue(elem)));
|
||
128 | filters.remove(prop);
|
||
129 | prop--;
|
||
130 | }
|
||
131 | 12333 | bsanchez | |
132 | 12220 | nacho | 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 | 12333 | bsanchez | listInt[i] = Integer.parseInt(listString[i]);
|
139 | 12220 | nacho | colorTable.setIntRange(listInt);
|
140 | } else {
|
||
141 | double[] listDouble = new double[listString.length];
|
||
142 | for(int i = 0; i < listString.length; i++)
|
||
143 | 12333 | bsanchez | listDouble[i] = Double.parseDouble(listString[i]);
|
144 | 12220 | nacho | colorTable.setDoubleRange(listDouble);
|
145 | }
|
||
146 | filters.remove(prop);
|
||
147 | prop--;
|
||
148 | }
|
||
149 | 12504 | bsanchez | */
|
150 | 12333 | bsanchez | |
151 | 12220 | nacho | 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 | 12333 | bsanchez | |
163 | } |
||
164 | 12220 | nacho | filterList.remove(ColorTableFilter.class); |
165 | 12333 | bsanchez | addColorTableFilter(new GridPalette(colorTable));
|
166 | |||
167 | 12220 | nacho | ColorTableFilter ct = (ColorTableFilter)filterList.getFilterByBaseClass(ColorTableFilter.class); |
168 | ct.setExec(exec); |
||
169 | } |
||
170 | return filteri;
|
||
171 | 12066 | nacho | } |
172 | |||
173 | public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
||
174 | 12218 | nacho | 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 | 12504 | bsanchez | /*
|
183 | 12218 | nacho | filterList.add("filter.colortable.type=" + colorTable.getType());
|
184 | 12333 | bsanchez | |
185 | 12218 | nacho | String range = "";
|
186 | 12220 | nacho | if(colorTable.getType() == IBuffer.TYPE_BYTE || colorTable.getType() == IBuffer.TYPE_SHORT || colorTable.getType() == IBuffer.TYPE_INT) {
|
187 | 12218 | nacho | 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 | 12333 | bsanchez | |
195 | 12218 | nacho | 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 | 12504 | bsanchez | */
|
200 | 12333 | bsanchez | |
201 | 12218 | nacho | 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 | 12066 | nacho | } |
209 | |||
210 | } |