Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.wmts / org.gvsig.wmts.provider.legend / src / main / java / org / gvsig / wmts / provider / legend / WMTSRasterGetColorTable.java @ 6532

History | View | Annotate | Download (4.99 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.wmts.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.ColorInterpretation;
34
import org.gvsig.raster.lib.legend.api.ColorTable;
35
import org.gvsig.raster.lib.legend.api.ColorTableClass;
36
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
37
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
38
import org.gvsig.wmts.provider.WMTSRasterProvider;
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 WMTSRasterGetColorTable implements DynMethod {
52

    
53
    final static private org.slf4j.Logger logger = LoggerFactory.getLogger(WMTSRasterGetColorInterpretation.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 WMTSRasterGetColorTable());
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
        WMTSRasterProvider provider = (WMTSRasterProvider)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
            //FIXME:
95
            List<ColorTableClass> colorTableClasses=new ArrayList<ColorTableClass>();
96
            double[] minMax={0d,255d}; //new double[2];
97

    
98
//        gdalBand.ComputeRasterMinMax(minMax);
99
            Double increment=1.0; //(minMax[1]-minMax[0])/256;
100

    
101

    
102
//        int i=0;
103
//        for(int r=0; r<=255; r+=32){
104
//            for(int g=0; g<=255; g+=32){
105
//                for(int b=0; b<=255; b+=64){
106
//                    String className=i+"";
107
//                    double value=i;
108
//                    double interpolation=50.0;
109
//                    Color color=new Color(r,g,b); //intARGB);
110
//                    ColorTableClass colorTableClass = rasterLegendManager.createColorTableClass(className, value, interpolation, color);
111
//                    colorTableClasses.add(colorTableClass);
112
//                    i++;
113
//                }
114
//            }
115
//        }
116

    
117
            for (int i=0;i<=255;i++){
118
                String className=i+"";
119
                double value=((minMax[0]+(i*increment)));
120
                double interpolation=50.0;
121
                int intARGB = ((i & 0xFF) << 24) | // alpha
122
                    ((i & 0xFF) << 16) | // red
123
                    ((i & 0xFF) << 8) | // green
124
                    ((i & 0xFF) << 0); // blue
125
                Color color=new Color(intARGB);
126
                ColorTableClass colorTableClass = rasterLegendManager.createColorTableClass(className, value, interpolation, color);
127
                colorTableClasses.add(colorTableClass);
128
            }
129
            colorTable = rasterLegendManager.createColorTable(WMTSRasterProvider.NAME+"_color_table",
130
                colorTableClasses, true);
131

    
132
            return colorTable;
133
        }
134

    
135
        return null;
136

    
137
    }
138

    
139
    @Override
140
    public Object clone() throws CloneNotSupportedException {
141
        return super.clone();
142
    }
143
}