Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster.2.4 / org.gvsig.raster.googlemaps / org.gvsig.raster.googlemaps.provider.legend / src / main / java / org / gvsig / raster / googlemaps / provider / legend / GoogleMapsRasterGetColorInterpretation.java @ 6903

History | View | Annotate | Download (4.71 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.googlemaps.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.googlemaps.provider.GoogleMapsRasterProvider;
35
import org.gvsig.raster.googlemaps.provider.GoogleMapsRasterProviderParameters;
36
import org.gvsig.raster.lib.legend.api.RasterLegendLocator;
37
import org.gvsig.raster.lib.legend.api.RasterLegendManager;
38
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation;
39
import org.gvsig.raster.lib.legend.api.colortable.ColorTable;
40
import org.gvsig.raster.lib.legend.api.colortable.colortableclass.ColorTableClass;
41
import org.gvsig.tools.ToolsLocator;
42
import org.gvsig.tools.dynobject.DynClass;
43
import org.gvsig.tools.dynobject.DynMethod;
44
import org.gvsig.tools.dynobject.DynObject;
45
import org.gvsig.tools.dynobject.exception.DynMethodException;
46
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException;
47

    
48
/**
49
 * @author dmartinezizquierdo
50
 *
51
 */
52
public class GoogleMapsRasterGetColorInterpretation implements DynMethod {
53

    
54
    final static private org.slf4j.Logger logger = LoggerFactory.getLogger(GoogleMapsRasterGetColorInterpretation.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 GoogleMapsRasterGetColorInterpretation());
64

    
65
    }
66

    
67
    @Override
68
    public int getCode() throws DynMethodNotSupportedException {
69
        return code;
70
    }
71

    
72
    @Override
73
    public String getDescription() {
74
        return "GoogleMaps Color Interpretation";
75
    }
76

    
77
    @Override
78
    public String getName() {
79
        return RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME;
80
    }
81

    
82
    @Override
83
    public Object invoke(DynObject self, Object[] args) throws DynMethodException {
84
        ColorInterpretation colorInterpretation = null;
85

    
86
        RasterLegendManager legendManager = RasterLegendLocator.getRasterLegendManager();
87

    
88
        GoogleMapsRasterProvider provider = (GoogleMapsRasterProvider)self;
89
        String format = (String) provider.getParameters().getDynValue(GoogleMapsRasterProviderParameters.GOOGLEMAPS_FORMAT_PARAMTER_NAME);
90
        if (format.equalsIgnoreCase("png32")){
91
            colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.ARGB);
92
        } else {
93
            colorInterpretation = legendManager.createColorInterpretation(ColorInterpretation.PALETTE);
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 = legendManager.createColorTableClass(className, value, interpolation, color);
111
                colorTableClasses.add(colorTableClass);
112
            }
113
            ColorTable colorTable = legendManager.createColorTable(GoogleMapsRasterProvider.NAME+"_color_table",
114
                colorTableClasses, true);
115

    
116
            colorInterpretation.setPalette(colorTable);
117
            colorInterpretation.setPaletteBand(0);
118
        }
119

    
120
        return colorInterpretation;
121
    }
122

    
123
    @Override
124
    public Object clone() throws CloneNotSupportedException {
125
        return super.clone();
126
    }
127
}