Statistics
| Revision:

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

History | View | Annotate | Download (7.9 KB)

1
/* gvSIG 3D extension for gvSIG
2
 *
3
 * Copyright (C) 2012 Prodevelop.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *   Prodevelop, S.L.
22
 *   Pza. Don Juan de Villarrasa, 14 - 5
23
 *   46001 Valencia
24
 *   Spain
25
 *
26
 *   +34 963 510 612
27
 *   +34 963 510 968
28
 *   prode@prodevelop.es
29
 *   http://www.prodevelop.es
30
 */
31
/*
32
 * AUTHORS:
33
 * 2012 AI2 - Instituto Universitario de Automatica e Informatica Industrial.
34
 * Universitat Politecnica de Valencia (UPV)
35
 * http://www.ai2.upv.es
36
 */
37

    
38

    
39
package org.gvsig.gvsig3d.impl.legend3d;
40

    
41
import java.awt.Color;
42
import java.util.ArrayList;
43
import java.util.List;
44
import java.util.Map;
45

    
46
import org.gvsig.fmap.dal.feature.Feature;
47
import org.gvsig.fmap.mapcontext.MapContextException;
48
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
50
import org.gvsig.gvsig3d.impl.symbology3d.extrusion.impl.BaseExtrusionSymbol;
51
import org.gvsig.gvsig3d.impl.symbology3d.extrusion.impl.ExtrusionPolygonSymbol;
52
import org.gvsig.gvsig3d.impl.symbology3d.fill.impl.SimpleFill3DSymbol;
53
import org.gvsig.gvsig3d.impl.symbology3d.line.impl.SimpleLine3DSymbol;
54
import org.gvsig.gvsig3d.impl.symbology3d.marker.impl.SimpleMarker3DSymbol;
55
import org.gvsig.osgvp.terrain.Terrain;
56
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractClassifiedVectorLegend;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractLegend;
58
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.AbstractVectorialLegend;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl.VectorialUniqueValueLegend;
60
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl.SimpleFillSymbol;
62
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.AbstractSymbol;
63
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
64
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.impl.SimpleLineSymbol;
65
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
66
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.SimpleMarkerSymbol;
67
import org.gvsig.tools.ToolsLocator;
68
import org.gvsig.tools.dynobject.DynStruct;
69
import org.gvsig.tools.persistence.PersistenceManager;
70
import org.gvsig.tools.persistence.PersistentState;
71
import org.gvsig.tools.persistence.exception.PersistenceException;
72
import org.gvsig.tools.util.Callable;
73
import org.gvsig.tools.util.Caller;
74
import org.gvsig.tools.util.impl.DefaultCaller;
75

    
76
//import ucar.nc2.constants._Coordinate;
77

    
78
/**
79
 * @author Jesus Zarzoso- jzarzoso@ai2.upv.es
80
 * @version $Id$
81
 * 
82
 */
83
public class ExtrusionLegend extends VectorialUniqueValueLegend {
84

    
85
        public static final String EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME = "ExtrusionLegend";
86

    
87
        private ExtrusionPolygonSymbol defaultSymbolEx;
88
        private double extrusionFactor = 1.0;
89
        int shapeType = 0;
90
        int coordType = Terrain.CoordinateSystemType.PROJECTED;
91

    
92
        public ExtrusionLegend() {
93
                super(9);
94
                this.shapeType = 9;
95
        }
96

    
97
        public ExtrusionLegend(int shapeType) {
98
                super(shapeType);
99
                this.shapeType = shapeType;
100
        }
101

    
102
        // public ISymbol getSymbolByFeature(Feature feat) {
103
        // try {
104
        // return super.getSymbolByFeature(feat);
105
        // } catch (MapContextException e) {
106
        // // TODO Auto-generated catch block
107
        // e.printStackTrace();
108
        // }
109
        // return null;
110
        // }
111
        //
112
        public ISymbol getSymbolByValue(Object key) {
113
                ISymbol theSymbol = super.getSymbolByValue(key);
114

    
115
                if (theSymbol == null)
116
                        return null;
117

    
118
                return theSymbol;
119
        }
120

    
121
        public ISymbol getDefaultSymbol() {
122

    
123
                return new ExtrusionPolygonSymbol(1.0f);
124

    
125
        }
126

    
127
        //
128
        // public String getClassName() {
129
        // return getClass().getName();
130
        // }
131

    
132
        public double getExtrusionFactor() {
133
                return extrusionFactor;
134
        }
135

    
136
        public void setExtrusionFactor(double extrusionFactor) {
137
                this.extrusionFactor = extrusionFactor;
138
        }
139

    
140
        // public XMLEntity getXMLEntity() {
141
        // XMLEntity xml = super.getXMLEntity();
142
        // xml.putProperty("extrusionFactor", this.extrusionFactor);
143
        // return xml;
144
        //
145
        // }
146
        //
147
        // public void setXMLEntity(XMLEntity xml) {
148
        // // TODO: It is necessary to insert here all the properties to load with
149
        // the extrusion legend.
150
        // super.setXMLEntity(xml);
151
        // if (xml.contains("extrusionFactor"))
152
        // extrusionFactor = xml.getDoubleProperty("extrusionFactor");
153
        // }
154

    
155
        public void setCoordinateSystemType(int coordType) {
156

    
157
                this.coordType = coordType;
158

    
159
        }
160

    
161
        @SuppressWarnings({ "unchecked", "rawtypes" })
162
        public void loadFromState(PersistentState state)
163
                        throws PersistenceException {
164
                super.loadFromState(state);
165
                extrusionFactor = state.getDouble("extrusionFactor");
166
                shapeType = state.getInt("shapeType");
167
                coordType = state.getInt("coordType");
168
        }
169

    
170
        public void saveToState(PersistentState state) throws PersistenceException {
171
                super.saveToState(state);
172
                state.set("extrusionFactor", extrusionFactor);
173
                state.set("shapeType", shapeType);
174
                state.set("coordType", coordType);
175
        }
176

    
177
        public static class RegisterPersistence implements Callable {
178

    
179
                public Object call() throws Exception {
180
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
181

    
182
                        if (manager.getDefinition("Legend") == null) {
183
                                Caller caller = new DefaultCaller();
184
                                caller.add(new AbstractLegend.RegisterPersistence());
185
                                caller.call();
186
                        }
187

    
188
                        if (manager.getDefinition("VectorialLegend") == null) {
189
                                Caller caller = new DefaultCaller();
190
                                caller.add(new AbstractVectorialLegend.RegisterPersistence());
191
                                caller.call();
192
                        }
193

    
194
                        if (manager.getDefinition("ClassifiedVectorLegend") == null) {
195
                                Caller caller = new DefaultCaller();
196
                                caller.add(new AbstractClassifiedVectorLegend.RegisterPersistence());
197
                                caller.call();
198
                        }
199

    
200
                        if (manager.getDefinition("VectorialUniqueValueLegend") == null) {
201
                                Caller caller = new DefaultCaller();
202
                                caller.add(new VectorialUniqueValueLegend.RegisterPersistence());
203
                                caller.call();
204
                        }
205

    
206
                        if (manager
207
                                        .getDefinition(EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME) == null) {
208
                                DynStruct definition = manager.addDefinition(
209
                                                ExtrusionLegend.class,
210
                                                EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME,
211
                                                EXTRUSION_LEGEND_PERSISTENCE_DEFINITION_NAME
212
                                                                + " Persistence definition", null, null);
213
                                // Extend the Classified Vector Legend base definition
214
                                definition
215
                                                .extend(manager
216
                                                                .getDefinition(VECTORIAL_UNIQUE_VALUE_LEGEND_PERSISTENCE_DEFINITION_NAME));
217

    
218
                                // Keys
219
                                definition.addDynFieldDouble("extrusionFactor").setMandatory(
220
                                                true);
221
                                definition.addDynFieldInt("shapeType").setMandatory(true);
222
                                definition.addDynFieldInt("coordType").setMandatory(true);
223
                                // // Null interval symbol
224
                                // definition.addDynFieldObject(FIELD_NULL_VALUE_SYMBOL).setClassOfValue(ISymbol.class);
225
                                // // Selected colors
226
                                // definition.addDynFieldList(FIELD_SELECTED_COLORS).setClassOfItems(Color.class);
227
                                // // Symbols
228
                                // definition.addDynFieldMap(FIELD_SYMBOLS).setClassOfItems(ISymbol.class);
229
                                // // Use default symbol?
230
                                // definition.addDynFieldBoolean(FIELD_USE_DEFAULT_SYMBOL);
231
                        }
232
                        return Boolean.TRUE;
233
                }
234

    
235
        }
236

    
237
}