Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / SingleSymbolLegend.java @ 34294

History | View | Annotate | Download (7.05 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl;
42

    
43
import org.gvsig.fmap.dal.exception.DataException;
44
import org.gvsig.fmap.dal.feature.Feature;
45
import org.gvsig.fmap.dal.feature.FeatureStore;
46
import org.gvsig.fmap.geom.Geometry;
47
import org.gvsig.fmap.mapcontext.MapContextLocator;
48
import org.gvsig.fmap.mapcontext.MapContextManager;
49
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
50
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
51
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
52
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
54
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
56
import org.gvsig.tools.ToolsLocator;
57
import org.gvsig.tools.dynobject.DynStruct;
58
import org.gvsig.tools.persistence.PersistenceManager;
59
import org.gvsig.tools.persistence.PersistentState;
60
import org.gvsig.tools.persistence.exception.PersistenceException;
61
import org.gvsig.tools.util.Callable;
62
import org.slf4j.Logger;
63
import org.slf4j.LoggerFactory;
64

    
65
/**
66
 * Implements a legend composed by single symbols.
67
 * 
68
 * @author Vicente Caballero Navarro
69
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
70
 */
71
public class SingleSymbolLegend extends AbstractVectorialLegend implements
72
                ISingleSymbolLegend {
73

    
74
        final static private Logger LOG = LoggerFactory.getLogger(VectorialUniqueValueLegend.class);
75

    
76
        public static final String SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME =
77
                        "SimgleSymbolLegend";
78
        
79
        private ISymbol defaultSymbol;
80
    private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono
81

    
82
        /**
83
         * Constructor method, needed by persistence.
84
         */
85
        public SingleSymbolLegend() {
86
                super();
87
        }
88

    
89
        /**
90
         * Convenience fast constructor.
91
         *
92
         * @param style S?mbolo.
93
         */
94
        public SingleSymbolLegend(ISymbol style) {
95
                super();
96
                defaultSymbol = style;
97

    
98
                if (style instanceof MultiShapeSymbol) {
99
                        shapeType = Geometry.TYPES.GEOMETRY;
100
                } else if (style instanceof IMarkerSymbol) {
101
                        shapeType = Geometry.TYPES.POINT;
102
                } else if (style instanceof ILineSymbol) {
103
                        shapeType = Geometry.TYPES.CURVE;
104
                } else if (style instanceof IFillSymbol) {
105
                        shapeType = Geometry.TYPES.SURFACE;
106
                }
107
        }
108

    
109

    
110
        public void setDefaultSymbol(ISymbol s) {
111
                if (s == null) throw new NullPointerException("Default symbol cannot be null");
112
                setShapeType(s.getSymbolType());
113
                ISymbol old = defaultSymbol;
114
                defaultSymbol = s;
115
                fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
116
        }
117

    
118

    
119
        public ISymbol getSymbol(int recordIndex) {
120
                return defaultSymbol;
121
        }
122

    
123
        public ISymbol getDefaultSymbol() {
124
                if(defaultSymbol==null) {
125
                        defaultSymbol =
126
                                        getSymbolManager().createSymbol(IFillSymbol.SYMBOL_NAME);
127
                }
128
                return defaultSymbol;
129
        }
130

    
131

    
132

    
133
        public int getShapeType() {
134
                return shapeType;
135
        }
136

    
137
        public void setShapeType(int shapeType) {
138
                if (this.shapeType != shapeType) {
139
                        defaultSymbol = getSymbolManager().createSymbol(shapeType);
140
                        this.shapeType = shapeType;
141
                }
142
        }
143

    
144
    public ISymbol getSymbolByFeature(Feature feat) {
145
        return defaultSymbol;
146
    }
147

    
148
        public void useDefaultSymbol(boolean b) {
149
                LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
150
        }
151

    
152
    public String[] getUsedFields() {
153
        return new String[0];
154
    }
155

    
156
    public boolean isUseDefaultSymbol() {
157
            return true;
158

    
159
    }
160

    
161

    
162
    public String getClassName() {
163
                return getClass().getName();
164
        }
165

    
166
    public boolean isSuitableForShapeType(int shapeType) {
167
                return getShapeType() == shapeType;
168
        }
169

    
170

    
171
        public void setFeatureStore(FeatureStore fs) throws DataException {
172
                LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
173
        }
174
        
175
        protected String[] getRequiredFeatureAttributeNames(
176
                        FeatureStore featureStore) throws DataException {
177
                // We only need the default Geometry to draw
178
                return new String[] { featureStore
179
                                .getDefaultFeatureType().getDefaultGeometryAttributeName() };
180
        }
181

    
182
        public Object clone() throws CloneNotSupportedException {
183
                SingleSymbolLegend clone = (SingleSymbolLegend) super.clone();
184

    
185
                // Clone default symbol
186
                if (defaultSymbol != null) {
187
                        clone.defaultSymbol = (ISymbol) defaultSymbol.clone();
188
                }
189

    
190
                return clone;
191
        }
192

    
193
        public void loadFromState(PersistentState state)
194
                        throws PersistenceException {
195
                // Set parent properties
196
                super.loadFromState(state);
197
                LOG.warn("FIXME: SingleSymbolLegend.loadFromState");
198
        }
199

    
200
        public void saveToState(PersistentState state) throws PersistenceException {
201
                // Save parent properties
202
                super.saveToState(state);
203
                LOG.warn("FIXME: SingleSymbolLegend.saveToState");
204
        }
205

    
206
        public static class RegisterPersistence implements Callable {
207

    
208
                public Object call() throws Exception {
209
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
210
                        if( manager.getDefinition(SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
211
                                DynStruct definition = manager.addDefinition(
212
                                                SingleSymbolLegend.class,
213
                                                SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME,
214
                                                SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
215
                                                null, 
216
                                                null
217
                                );
218
                                // Extend the Vectorial Legend base definition
219
                                definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME));
220
                        }
221
                        return Boolean.TRUE;
222
                }
223
                
224
        }
225

    
226
        public static class RegisterLegend implements Callable {
227

    
228
                public Object call() throws Exception {
229
                MapContextManager manager = MapContextLocator.getMapContextManager();
230

    
231
            manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME,
232
                    SingleSymbolLegend.class);
233

    
234
                        return Boolean.TRUE;
235
                }
236
                
237
        }
238

    
239
}