gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster.wms2 / org.gvsig.raster.wms2.provider.legend / src / main / java / org / gvsig / raster / wms / provider / legend / WMSRasterGetColorTable.java @ 6904
History | View | Annotate | Download (4.34 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2016 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
|
24 |
package org.gvsig.raster.wms.provider.legend; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.util.ArrayList; |
28 |
import java.util.List; |
29 |
|
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
33 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
34 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
35 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
36 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
37 |
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
38 |
import org.gvsig.raster.wms.provider.WMSRasterProvider; |
39 |
import org.gvsig.tools.ToolsLocator; |
40 |
import org.gvsig.tools.dynobject.DynClass; |
41 |
import org.gvsig.tools.dynobject.DynMethod; |
42 |
import org.gvsig.tools.dynobject.DynObject; |
43 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
44 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
45 |
|
46 |
/**
|
47 |
* Dynamic method to add a get Color Table funcionality
|
48 |
* @author dmartinezizquierdo
|
49 |
*
|
50 |
*/
|
51 |
public class WMSRasterGetColorTable implements DynMethod { |
52 |
|
53 |
final static private org.slf4j.Logger logger = LoggerFactory.getLogger(WMSRasterGetColorInterpretation.class); |
54 |
|
55 |
private static Integer code = null; |
56 |
|
57 |
static void register(DynClass storeClass) { |
58 |
if (code != null) { |
59 |
return;
|
60 |
} |
61 |
code = ToolsLocator.getDynObjectManager() |
62 |
.registerDynMethod(storeClass, new WMSRasterGetColorTable());
|
63 |
|
64 |
} |
65 |
|
66 |
@Override
|
67 |
public int getCode() throws DynMethodNotSupportedException { |
68 |
return code;
|
69 |
} |
70 |
|
71 |
@Override
|
72 |
public String getDescription() { |
73 |
return "GoogleMaps Color Table"; |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public String getName() { |
78 |
return RasterStore.DYNMETHOD_GETCOLORTABLE_NAME;
|
79 |
} |
80 |
|
81 |
@Override
|
82 |
public Object invoke(DynObject self, Object[] args) |
83 |
throws DynMethodException {
|
84 |
RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
85 |
|
86 |
WMSRasterProvider provider = (WMSRasterProvider)self; |
87 |
|
88 |
ColorInterpretation colorInterpretation =(ColorInterpretation)provider. |
89 |
invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME, null);
|
90 |
|
91 |
if ( !( colorInterpretation.isBGR() || colorInterpretation.isRGB() || colorInterpretation.isRGBA() ) ){
|
92 |
ColorTable colorTable; |
93 |
|
94 |
List<ColorTableClass> colorTableClasses=new ArrayList<ColorTableClass>(); |
95 |
double[] minMax={0d,255d}; |
96 |
|
97 |
Double increment=1.0; |
98 |
|
99 |
for (int i=0;i<=255;i++){ |
100 |
String className=i+""; |
101 |
double value=((minMax[0]+(i*increment))); |
102 |
double interpolation=50.0; |
103 |
int intARGB = ((i & 0xFF) << 24) | // alpha |
104 |
((i & 0xFF) << 16) | // red |
105 |
((i & 0xFF) << 8) | // green |
106 |
((i & 0xFF) << 0); // blue |
107 |
Color color=new Color(intARGB); |
108 |
ColorTableClass colorTableClass = rasterLegendManager.createColorTableClass(className, value, interpolation, color); |
109 |
colorTableClasses.add(colorTableClass); |
110 |
} |
111 |
colorTable = rasterLegendManager.createColorTable(WMSRasterProvider.NAME+"_color_table",
|
112 |
colorTableClasses, true);
|
113 |
|
114 |
return colorTable;
|
115 |
} |
116 |
|
117 |
return null; |
118 |
|
119 |
} |
120 |
|
121 |
@Override
|
122 |
public Object clone() throws CloneNotSupportedException { |
123 |
return super.clone(); |
124 |
} |
125 |
} |