gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster.bingmaps / org.gvsig.raster.bingmaps.provider.legend / src / main / java / org / gvsig / raster / bingmaps / provider / legend / BingMapsRasterGetColorTable.java @ 8780
History | View | Annotate | Download (4.42 KB)
1 | 8780 | fdiaz | /* 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.bingmaps.provider.legend; |
||
25 | |||
26 | |||
27 | import java.awt.Color; |
||
28 | import java.util.ArrayList; |
||
29 | import java.util.List; |
||
30 | |||
31 | import org.slf4j.LoggerFactory; |
||
32 | |||
33 | import org.gvsig.fmap.dal.raster.api.RasterStore; |
||
34 | import org.gvsig.raster.bingmaps.provider.BingMapsRasterProvider; |
||
35 | import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
||
36 | import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
||
37 | import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
||
38 | import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
||
39 | import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass; |
||
40 | import org.gvsig.tools.ToolsLocator; |
||
41 | import org.gvsig.tools.dynobject.DynClass; |
||
42 | import org.gvsig.tools.dynobject.DynMethod; |
||
43 | import org.gvsig.tools.dynobject.DynObject; |
||
44 | import org.gvsig.tools.dynobject.exception.DynMethodException; |
||
45 | import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
||
46 | |||
47 | /**
|
||
48 | * Dynamic method to add a get Color Table funcionality
|
||
49 | * @author dmartinezizquierdo
|
||
50 | *
|
||
51 | */
|
||
52 | public class BingMapsRasterGetColorTable implements DynMethod { |
||
53 | |||
54 | final static private org.slf4j.Logger logger = LoggerFactory.getLogger(BingMapsRasterGetColorInterpretation.class); |
||
55 | |||
56 | private static Integer code = null; |
||
57 | |||
58 | static void register(DynClass storeClass) { |
||
59 | if (code != null) { |
||
60 | return;
|
||
61 | } |
||
62 | code = ToolsLocator.getDynObjectManager() |
||
63 | .registerDynMethod(storeClass, new BingMapsRasterGetColorTable());
|
||
64 | |||
65 | } |
||
66 | |||
67 | @Override
|
||
68 | public int getCode() throws DynMethodNotSupportedException { |
||
69 | return code;
|
||
70 | } |
||
71 | |||
72 | @Override
|
||
73 | public String getDescription() { |
||
74 | return "BingMaps Color Table"; |
||
75 | } |
||
76 | |||
77 | @Override
|
||
78 | public String getName() { |
||
79 | return RasterStore.DYNMETHOD_GETCOLORTABLE_NAME;
|
||
80 | } |
||
81 | |||
82 | @Override
|
||
83 | public Object invoke(DynObject self, Object[] args) |
||
84 | throws DynMethodException {
|
||
85 | RasterLegendManager rasterLegendManager = RasterLegendLocator.getRasterLegendManager(); |
||
86 | |||
87 | BingMapsRasterProvider provider = (BingMapsRasterProvider)self; |
||
88 | |||
89 | ColorInterpretation colorInterpretation =(ColorInterpretation)provider. |
||
90 | invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME, null);
|
||
91 | |||
92 | if ( !( colorInterpretation.isBGR() || colorInterpretation.isRGB() || colorInterpretation.isRGBA() ) ){
|
||
93 | ColorTable colorTable; |
||
94 | |||
95 | //FIXME:
|
||
96 | List<ColorTableClass> colorTableClasses=new ArrayList<ColorTableClass>(); |
||
97 | double[] minMax={0d,255d}; //new double[2]; |
||
98 | |||
99 | Double increment=1.0; |
||
100 | |||
101 | for (int i=0;i<=255;i++){ |
||
102 | String className=i+""; |
||
103 | double value=((minMax[0]+(i*increment))); |
||
104 | double interpolation=50.0; |
||
105 | int intARGB = ((i & 0xFF) << 24) | // alpha |
||
106 | ((i & 0xFF) << 16) | // red |
||
107 | ((i & 0xFF) << 8) | // green |
||
108 | ((i & 0xFF) << 0); // blue |
||
109 | Color color=new Color(intARGB); |
||
110 | ColorTableClass colorTableClass = rasterLegendManager.createColorTableClass(className, value, interpolation, color); |
||
111 | colorTableClasses.add(colorTableClass); |
||
112 | } |
||
113 | colorTable = rasterLegendManager.createColorTable(BingMapsRasterProvider.NAME+"_color_table",
|
||
114 | colorTableClasses, true);
|
||
115 | |||
116 | return colorTable;
|
||
117 | } |
||
118 | |||
119 | return null; |
||
120 | |||
121 | } |
||
122 | |||
123 | @Override
|
||
124 | public Object clone() throws CloneNotSupportedException { |
||
125 | return super.clone(); |
||
126 | } |
||
127 | } |