Statistics
| Revision:

gvsig-3d / 2.0 / trunk / org.gvsig.gvsig3d / org.gvsig.gvsig3d.lib / org.gvsig.gvsig3d.lib.impl / src / main / java / org / gvsig / gvsig3d / impl / legend3d / ExtrusionLegend.java @ 370

History | View | Annotate | Download (7.15 KB)

1
package org.gvsig.gvsig3d.impl.legend3d;
2

    
3
import java.awt.Color;
4
import java.util.ArrayList;
5
import java.util.List;
6
import java.util.Map;
7

    
8
import org.gvsig.fmap.dal.feature.Feature;
9
import org.gvsig.fmap.mapcontext.MapContextException;
10
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
11
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
12
import org.gvsig.gvsig3d.impl.symbology3d.extrusion.impl.BaseExtrusionSymbol;
13
import org.gvsig.gvsig3d.impl.symbology3d.extrusion.impl.ExtrusionPolygonSymbol;
14
import org.gvsig.gvsig3d.impl.symbology3d.fill.impl.SimpleFill3DSymbol;
15
import org.gvsig.gvsig3d.impl.symbology3d.line.impl.SimpleLine3DSymbol;
16
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.SimpleMarker3DSymbol;
17
import org.gvsig.osgvp.terrain.Terrain;
18
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
19
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractLegend;
20
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
21
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
22
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
23
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
24
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
25
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
26
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
27
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
28
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
29
import org.gvsig.tools.ToolsLocator;
30
import org.gvsig.tools.dynobject.DynStruct;
31
import org.gvsig.tools.persistence.PersistenceManager;
32
import org.gvsig.tools.persistence.PersistentState;
33
import org.gvsig.tools.persistence.exception.PersistenceException;
34
import org.gvsig.tools.util.Callable;
35
import org.gvsig.tools.util.Caller;
36
import org.gvsig.tools.util.impl.DefaultCaller;
37

    
38
import ucar.nc2.constants._Coordinate;
39

    
40
/**
41
 * @author AI2
42
 * @version $Id$
43
 * 
44
 */
45
public class ExtrusionLegend extends VectorialUniqueValueLegend {
46

    
47
        public static final String EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME = "ExtrusionLegend";
48

    
49
        private ExtrusionPolygonSymbol defaultSymbolEx;
50
        private double extrusionFactor = 1.0;
51
        int shapeType = 0;
52
        int coordType = Terrain.CoordinateSystemType.PROJECTED;
53

    
54
        public ExtrusionLegend(){
55
                super(9);
56
                this.shapeType = 9;                        
57
        }
58
        
59
        
60
        public ExtrusionLegend(int shapeType) {
61
                super(shapeType);
62
                this.shapeType = shapeType;
63
        }
64

    
65
        // public ISymbol getSymbolByFeature(Feature feat) {
66
        // try {
67
        // return super.getSymbolByFeature(feat);
68
        // } catch (MapContextException e) {
69
        // // TODO Auto-generated catch block
70
        // e.printStackTrace();
71
        // }
72
        // return null;
73
        // }
74
        //
75
        public ISymbol getSymbolByValue(Object key) {
76
                ISymbol theSymbol = super.getSymbolByValue(key);
77

    
78
                if (theSymbol == null)
79
                        return null;
80

    
81
                return theSymbol;
82
        }
83

    
84
        public ISymbol getDefaultSymbol() {
85

    
86
                return new ExtrusionPolygonSymbol(1.0f);
87

    
88
        }
89

    
90
        //
91
        // public String getClassName() {
92
        // return getClass().getName();
93
        // }
94

    
95
        public double getExtrusionFactor() {
96
                return extrusionFactor;
97
        }
98

    
99
        public void setExtrusionFactor(double extrusionFactor) {
100
                this.extrusionFactor = extrusionFactor;
101
        }
102

    
103
        // public XMLEntity getXMLEntity() {
104
        // XMLEntity xml = super.getXMLEntity();
105
        // xml.putProperty("extrusionFactor", this.extrusionFactor);
106
        // return xml;
107
        //
108
        // }
109
        //
110
        // public void setXMLEntity(XMLEntity xml) {
111
        // // TODO: It is necessary to insert here all the properties to load with
112
        // the extrusion legend.
113
        // super.setXMLEntity(xml);
114
        // if (xml.contains("extrusionFactor"))
115
        // extrusionFactor = xml.getDoubleProperty("extrusionFactor");
116
        // }
117

    
118
        public void setCoordinateSystemType(int coordType) {
119

    
120
                this.coordType = coordType;
121

    
122
        }
123

    
124
        @SuppressWarnings({ "unchecked", "rawtypes" })
125
        public void loadFromState(PersistentState state)
126
                        throws PersistenceException {
127
                // Set parent properties
128
                super.loadFromState(state);
129
                
130
                extrusionFactor = state.getDouble("extrusionFactor");
131
                // nullValueSymbol = (ISymbol) state.get(FIELD_NULL_VALUE_SYMBOL);
132
                // selectedColors =
133
                // (Color[]) state.getArray(FIELD_SELECTED_COLORS, Color.class);
134
                // Map persistedSymbolMap = (Map) state.get(FIELD_SYMBOLS);
135
                // if (persistedSymbolMap != null) {
136
                // symbols.putAll(persistedSymbolMap);
137
                // }
138
                // useDefaultSymbol(state.getBoolean(FIELD_USE_DEFAULT_SYMBOL));
139
        }
140

    
141
        public void saveToState(PersistentState state) throws PersistenceException {
142
                // Save parent properties
143
                super.saveToState(state);
144
                // Save own properties
145
                state.set("extrusionFactor", extrusionFactor);
146
                // state.set(FIELD_KEYS, keys);
147
                // state.set(FIELD_NULL_VALUE_SYMBOL, nullValueSymbol);
148
                // state.set(FIELD_SELECTED_COLORS, selectedColors);
149
                // state.set(FIELD_USE_DEFAULT_SYMBOL, isUseDefaultSymbol());
150
                // state.set(FIELD_SYMBOLS, symbols);
151
        }
152

    
153
        public static class RegisterPersistence implements Callable {
154

    
155
                public Object call() throws Exception {
156
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
157

    
158
                        if (manager.getDefinition("Legend") == null) {
159
                                Caller caller = new DefaultCaller();
160
                                caller.add(new AbstractLegend.RegisterPersistence());
161
                                caller.call();
162
                        }
163
                        
164
                        if (manager.getDefinition("VectorialLegend") == null) {
165
                                Caller caller = new DefaultCaller();
166
                                caller.add(new AbstractVectorialLegend.RegisterPersistence());
167
                                caller.call();
168
                        }                
169
                        
170
                        
171
                        if (manager.getDefinition("ClassifiedVectorLegend") == null) {
172
                                Caller caller = new DefaultCaller();
173
                                caller.add(new AbstractClassifiedVectorLegend.RegisterPersistence());
174
                                caller.call();
175
                        }
176
                        
177
                        if (manager.getDefinition("VectorialUniqueValueLegend") == null) {
178
                                Caller caller = new DefaultCaller();
179
                                caller.add(new VectorialUniqueValueLegend.RegisterPersistence());
180
                                caller.call();
181
                        }
182

    
183
                        if (manager
184
                                        .getDefinition(EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
185
                                DynStruct definition = manager.addDefinition(
186
                                                ExtrusionLegend.class,
187
                                                EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
188
                                                EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME
189
                                                                + " Persistence definition", null, null);
190
                                // Extend the Classified Vector Legend base definition
191
                                definition
192
                                                .extend(manager
193
                                                                .getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
194

    
195
                                // Keys
196
                                definition.addDynFieldDouble("extrusionFactor").setMandatory(true);
197
                                // // Null interval symbol
198
                                // definition.addDynFieldObject(FIELD_NULL_VALUE_SYMBOL).setClassOfValue(ISymbol.class);
199
                                // // Selected colors
200
                                // definition.addDynFieldList(FIELD_SELECTED_COLORS).setClassOfItems(Color.class);
201
                                // // Symbols
202
                                // definition.addDynFieldMap(FIELD_SYMBOLS).setClassOfItems(ISymbol.class);
203
                                // // Use default symbol?
204
                                // definition.addDynFieldBoolean(FIELD_USE_DEFAULT_SYMBOL);
205
                        }
206
                        return Boolean.TRUE;
207
                }
208

    
209
        }
210

    
211
}