Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / 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 @ 41055

History | View | Annotate | Download (6.47 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl;
25

    
26
import org.gvsig.fmap.dal.exception.DataException;
27
import org.gvsig.fmap.dal.feature.Feature;
28
import org.gvsig.fmap.dal.feature.FeatureStore;
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.mapcontext.MapContextLocator;
31
import org.gvsig.fmap.mapcontext.MapContextManager;
32
import org.gvsig.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
33
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
34
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
35
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
37
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
38
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
39
import org.gvsig.tools.ToolsLocator;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42
import org.gvsig.tools.persistence.PersistentState;
43
import org.gvsig.tools.persistence.exception.PersistenceException;
44
import org.gvsig.tools.util.Callable;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
/**
49
 * Implements a legend composed by single symbols.
50
 * 
51
 * @author Vicente Caballero Navarro
52
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
53
 */
54
public class SingleSymbolLegend extends AbstractVectorialLegend implements
55
                ISingleSymbolLegend {
56

    
57
        final static private Logger LOG = LoggerFactory.getLogger(VectorialUniqueValueLegend.class);
58

    
59
        public static final String SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME =
60
                        "SimgleSymbolLegend";
61
        
62
        private ISymbol defaultSymbol;
63
    private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono
64

    
65
        /**
66
         * Constructor method, needed by persistence.
67
         */
68
        public SingleSymbolLegend() {
69
                super();
70
        }
71

    
72
        /**
73
         * Convenience fast constructor.
74
         *
75
         * @param style S?mbolo.
76
         */
77
        public SingleSymbolLegend(ISymbol style) {
78
                super();
79
                setDefaultSymbol(style);
80
        }
81

    
82

    
83
        public void setDefaultSymbol(ISymbol s) {
84
                if (s == null) throw new NullPointerException("Default symbol cannot be null");
85
                ISymbol old = defaultSymbol;
86
                defaultSymbol = s;
87
                fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
88
        }
89

    
90

    
91
        public ISymbol getSymbol(int recordIndex) {
92
                return defaultSymbol;
93
        }
94

    
95
        public ISymbol getDefaultSymbol() {
96
                if(defaultSymbol==null) {
97
                        defaultSymbol = getSymbolManager().createSymbol(shapeType);
98
                }
99
                return defaultSymbol;
100
        }
101

    
102

    
103

    
104
        public int getShapeType() {
105
                return shapeType;
106
        }
107

    
108
        public void setShapeType(int shapeType) {
109
                if (this.shapeType != shapeType) {
110
                        if(defaultSymbol==null || defaultSymbol.getSymbolType()!=shapeType){
111
                                defaultSymbol = getSymbolManager().createSymbol(shapeType);
112
                        }
113
                        this.shapeType = shapeType;
114
                }
115
        }
116

    
117
    public ISymbol getSymbolByFeature(Feature feat) {
118
        return getDefaultSymbol();
119
    }
120

    
121
        public void useDefaultSymbol(boolean b) {
122
                LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
123
        }
124

    
125
    public String[] getUsedFields() {
126
        return new String[0];
127
    }
128

    
129
    public boolean isUseDefaultSymbol() {
130
            return true;
131

    
132
    }
133

    
134

    
135
    public String getClassName() {
136
                return getClass().getName();
137
        }
138

    
139
    public boolean isSuitableForShapeType(int shapeType) {
140
                return getShapeType() == shapeType;
141
        }
142

    
143

    
144
        public void setFeatureStore(FeatureStore fs) throws DataException {
145
                LOG.warn("TODO: SingleSymbolLegend.useDefaultSymbol");
146
        }
147
        
148
        protected String[] getRequiredFeatureAttributeNames(
149
                        FeatureStore featureStore) throws DataException {
150
                // We only need the default Geometry to draw
151
                return new String[] { featureStore
152
                                .getDefaultFeatureType().getDefaultGeometryAttributeName() };
153
        }
154

    
155
        public Object clone() throws CloneNotSupportedException {
156
                SingleSymbolLegend clone = (SingleSymbolLegend) super.clone();
157

    
158
                // Clone default symbol
159
                if (defaultSymbol != null) {
160
                        clone.defaultSymbol = (ISymbol) defaultSymbol.clone();
161
                }
162

    
163
                return clone;
164
        }
165

    
166
        public void loadFromState(PersistentState state)
167
                        throws PersistenceException {
168
                // Set parent properties
169
                super.loadFromState(state);
170
                // LOG.warn("FIXME: SingleSymbolLegend.loadFromState");
171
        }
172

    
173
        public void saveToState(PersistentState state) throws PersistenceException {
174
                // Save parent properties
175
                super.saveToState(state);
176
                // LOG.warn("FIXME: SingleSymbolLegend.saveToState");
177
        }
178

    
179
        public static class RegisterPersistence implements Callable {
180

    
181
                public Object call() throws Exception {
182
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
183
                        if( manager.getDefinition(SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
184
                                DynStruct definition = manager.addDefinition(
185
                                                SingleSymbolLegend.class,
186
                                                SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME,
187
                                                SINGLE_SYMBOL_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
188
                                                null, 
189
                                                null
190
                                );
191
                                // Extend the Vectorial Legend base definition
192
                                definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME));
193
                        }
194
                        return Boolean.TRUE;
195
                }
196
                
197
        }
198

    
199
        public static class RegisterLegend implements Callable {
200

    
201
                public Object call() throws Exception {
202
                MapContextManager manager = MapContextLocator.getMapContextManager();
203

    
204
            manager.registerLegend(ISingleSymbolLegend.LEGEND_NAME,
205
                    SingleSymbolLegend.class);
206

    
207
                        return Boolean.TRUE;
208
                }
209
                
210
        }
211

    
212
}