gvsig-gdal / branches / org.gvsig.gdal-2018a / org.gvsig.gdal.prov / org.gvsig.gdal.raster / org.gvsig.gdal.raster.provider.legend / src / main / java / org / gvsig / raster / gdal / provider / legend / RasterGdalGetLegend.java @ 361
History | View | Annotate | Download (2.68 KB)
1 |
package org.gvsig.raster.gdal.provider.legend; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.raster.api.RasterStore; |
4 |
import org.gvsig.raster.gdal.provider.AbstractRasterGdalStoreProvider; |
5 |
import org.gvsig.raster.lib.legend.api.RasterLegend; |
6 |
import org.gvsig.raster.lib.legend.api.RasterLegendLocator; |
7 |
import org.gvsig.raster.lib.legend.api.RasterLegendManager; |
8 |
import org.gvsig.raster.lib.legend.api.colorinterpretation.ColorInterpretation; |
9 |
import org.gvsig.raster.lib.legend.api.colortable.ColorTable; |
10 |
import org.gvsig.tools.ToolsLocator; |
11 |
import org.gvsig.tools.dynobject.DynClass; |
12 |
import org.gvsig.tools.dynobject.DynMethod; |
13 |
import org.gvsig.tools.dynobject.DynObject; |
14 |
import org.gvsig.tools.dynobject.exception.DynMethodException; |
15 |
import org.gvsig.tools.dynobject.exception.DynMethodNotSupportedException; |
16 |
|
17 |
/**
|
18 |
* Dynamic method to add a get Legend funcionality
|
19 |
* @author dmartinezizquierdo
|
20 |
*
|
21 |
*/
|
22 |
public class RasterGdalGetLegend implements DynMethod { |
23 |
|
24 |
private static Integer code = null; |
25 |
|
26 |
|
27 |
static void register(DynClass storeClass) { |
28 |
if (code != null) { |
29 |
return;
|
30 |
} |
31 |
code = ToolsLocator.getDynObjectManager() |
32 |
.registerDynMethod(storeClass, new RasterGdalGetLegend());
|
33 |
|
34 |
} |
35 |
|
36 |
@Override
|
37 |
public int getCode() throws DynMethodNotSupportedException { |
38 |
return code;
|
39 |
} |
40 |
|
41 |
@Override
|
42 |
public String getDescription() { |
43 |
return "Raster GDAL Legend"; |
44 |
} |
45 |
|
46 |
@Override
|
47 |
public String getName() { |
48 |
return RasterStore.DYNMETHOD_GETLEGEND_NAME;
|
49 |
} |
50 |
|
51 |
@Override
|
52 |
public Object invoke(DynObject self, Object[] args) |
53 |
throws DynMethodException {
|
54 |
try {
|
55 |
AbstractRasterGdalStoreProvider rasterGdalProvider=(AbstractRasterGdalStoreProvider)self; |
56 |
RasterLegendManager legendManager=RasterLegendLocator.getRasterLegendManager(); |
57 |
|
58 |
ColorInterpretation colorInterpretation =(ColorInterpretation)rasterGdalProvider. |
59 |
invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORINTERPRETATION_NAME, null);
|
60 |
|
61 |
RasterLegend legend= legendManager.createLegend(colorInterpretation); |
62 |
// if ( !( colorInterpretation.isBGR() || colorInterpretation.isRGB() || colorInterpretation.isRGBA() ) ){
|
63 |
// ColorTable colorTable=(ColorTable)rasterGdalProvider.
|
64 |
// invokeDynMethod(RasterStore.DYNMETHOD_GETCOLORTABLE_NAME, null);
|
65 |
// legend.setColorTable(colorTable);
|
66 |
// }
|
67 |
|
68 |
return legend;
|
69 |
|
70 |
} catch (DynMethodNotSupportedException e) {
|
71 |
//FIXME
|
72 |
throw new RuntimeException(e); |
73 |
} |
74 |
} |
75 |
|
76 |
@Override
|
77 |
public Object clone() throws CloneNotSupportedException { |
78 |
return super.clone(); |
79 |
} |
80 |
} |