Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / SingleSymbolLegend.java @ 30053

History | View | Annotate | Download (5.49 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.rendering.legend.events.SymbolLegendEvent;
48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.symbology.fmap.mapcontext.rendering.legend.ISingleSymbolLegend;
50
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
51
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.MultiShapeSymbol;
52
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
53
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
54
import org.gvsig.utils.XMLEntity;
55
import org.gvsig.utils.XMLException;
56

    
57
/**
58
 * Implements a legend composed by single symbols.
59
 *
60
 * @author   Vicente Caballero Navarro
61
 */
62
public class SingleSymbolLegend extends AbstractVectorialLegend implements
63
                ISingleSymbolLegend {
64
        
65
        private ISymbol defaultSymbol;
66
    private int shapeType = Geometry.TYPES.SURFACE; // Por defecto, tipo pol?gono
67
        /**
68
         * Constructor method
69
         */
70
        public SingleSymbolLegend() {        }
71

    
72

    
73
        /**
74
         * Convenience fast constructor.
75
         *
76
         * @param style S?mbolo.
77
         */
78
        public SingleSymbolLegend(ISymbol style) {
79
                defaultSymbol = style;
80

    
81
                if (style instanceof MultiShapeSymbol) {
82
                        shapeType = Geometry.TYPES.GEOMETRY;
83
                } else if (style instanceof IMarkerSymbol) {
84
                        shapeType = Geometry.TYPES.POINT;
85
                } else if (style instanceof ILineSymbol) {
86
                        shapeType = Geometry.TYPES.CURVE;
87
                } else if (style instanceof IFillSymbol) {
88
                        shapeType = Geometry.TYPES.SURFACE;
89
                }
90
        }
91

    
92

    
93
        public void setDefaultSymbol(ISymbol s) {
94
                if (s == null) throw new NullPointerException("Default symbol cannot be null");
95
                setShapeType(s.getSymbolType());
96
                ISymbol old = defaultSymbol;
97
                defaultSymbol = s;
98
                fireDefaultSymbolChangedEvent(new SymbolLegendEvent(old, s));
99
        }
100

    
101

    
102
        public ISymbol getSymbol(int recordIndex) {
103
                return defaultSymbol;
104
        }
105

    
106
        public ISymbol getDefaultSymbol() {
107
                if(defaultSymbol==null) {
108
                        defaultSymbol= getManager().createSymbol(IFillSymbol.SYMBOL_NAME);
109
                }
110
                return defaultSymbol;
111
        }
112

    
113

    
114
        public XMLEntity getXMLEntity() throws XMLException {
115
                XMLEntity xml = new XMLEntity();
116
                xml.putProperty("className",this.getClass().getName());
117
                xml.addChild(defaultSymbol.getXMLEntity());
118

    
119
                if (zSort != null) {
120
                        XMLEntity zSortXML = zSort.getXMLEntity();
121
                        zSortXML.putProperty("id", "zSort");
122
                        xml.addChild(zSortXML);
123
                }
124
                return xml;
125
        }
126

    
127
        /**
128
         * TODO: replace with the new persistence API
129
         */
130
        public void setXMLEntity(XMLEntity xml) {
131
//        ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
132
//                setDefaultSymbol(auxSym);
133
//
134
//                XMLEntity zSortXML = xml.firstChild("id", "zSort");
135
//                if (zSortXML != null) {
136
//                        zSort = new ZSort(this);
137
//                        zSort.setXMLEntity(zSortXML);
138
//                }
139
        }
140

    
141

    
142
//        public ILegend cloneLegend() throws XMLException {
143
//                return (ILegend) LegendFactory.createFromXML(getXMLEntity());
144
//        }
145

    
146

    
147
        public int getShapeType() {
148
                return shapeType;
149
        }
150

    
151
        public void setShapeType(int shapeType) {
152
                if (this.shapeType != shapeType) {
153
                        defaultSymbol = getManager().createSymbol(shapeType);
154
                        this.shapeType = shapeType;
155
                }
156
        }
157

    
158
    public ISymbol getSymbolByFeature(Feature feat) {
159
        return defaultSymbol;
160
    }
161

    
162
        public void useDefaultSymbol(boolean b) {
163
                // TODO Auto-generated method stub
164
        }
165

    
166
    public String[] getUsedFields() {
167
        return new String[0];
168
    }
169

    
170
    public boolean isUseDefaultSymbol() {
171
            return true;
172

    
173
    }
174

    
175

    
176
    public String getClassName() {
177
                return getClass().getName();
178
        }
179

    
180
    public boolean isSuitableForShapeType(int shapeType) {
181
                return getShapeType() == shapeType;
182
        }
183

    
184

    
185
        public void setFeatureStore(FeatureStore fs) throws DataException {
186
                // TODO Auto-generated method stub
187

    
188
        }
189
        
190
        protected String[] getRequiredFeatureAttributeNames(
191
                        FeatureStore featureStore) throws DataException {
192
                // We only need the default Geometry to draw
193
                return new String[] { featureStore
194
                                .getDefaultFeatureType().getDefaultGeometryAttributeName() };
195
        }
196
}