Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / SingleSymbolLegend.java @ 18878

History | View | Annotate | Download (5.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 com.iver.cit.gvsig.fmap.rendering;
42

    
43
import com.hardcode.gdbms.engine.data.DataSource;
44
import com.iver.cit.gvsig.fmap.core.FShape;
45
import com.iver.cit.gvsig.fmap.core.IFeature;
46
import com.iver.cit.gvsig.fmap.core.ISLDCompatible;
47
import com.iver.cit.gvsig.fmap.core.SLDTags;
48
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
49
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
50
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
51
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
52
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
53
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol;
54
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
55
import com.iver.cit.gvsig.fmap.layers.XMLException;
56
import com.iver.utiles.XMLEntity;
57

    
58

    
59
/**
60
 * Implements a legend composed by single symbols.
61
 * 
62
 * @author   Vicente Caballero Navarro
63
 */
64
public class SingleSymbolLegend extends AbstractLegend implements IVectorLegend {
65
        private ISymbol defaultSymbol;
66
    private int shapeType = FShape.POLYGON; // Por defecto, tipo pol?gono
67
        private ZSort zSort;
68

    
69
        /**
70
         * Constructor method 
71
         */
72
        public SingleSymbolLegend() {        }
73

    
74

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

    
83
                if (style instanceof MultiShapeSymbol) {
84
                        shapeType = FShape.MULTI;
85
                } else if (style instanceof IMarkerSymbol) {
86
                        shapeType = FShape.POINT;
87
                } else if (style instanceof ILineSymbol) {
88
                        shapeType = FShape.LINE;
89
                } else if (style instanceof IFillSymbol) {
90
                        shapeType = FShape.POLYGON;
91
                }
92
        }
93

    
94

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

    
103

    
104
        public ISymbol getSymbol(int recordIndex) {
105
                return defaultSymbol;
106
        }
107

    
108
        public ISymbol getDefaultSymbol() {
109
                if(defaultSymbol==null)
110
                        defaultSymbol=SymbologyFactory.createDefaultFillSymbol();
111
                return defaultSymbol;
112
        }
113

    
114

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

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

    
128
        public void setXMLEntity03(XMLEntity xml) {
129
                FSymbol auxSym = FSymbol.createFromXML03(xml.getChild(0));
130
                setDefaultSymbol(auxSym);
131
        }
132

    
133
        public void setXMLEntity(XMLEntity xml) {
134
        ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
135
                setDefaultSymbol(auxSym);
136
                
137
                XMLEntity zSortXML = xml.firstChild("id", "zSort");
138
                if (zSortXML != null) {
139
                        zSort = new ZSort(this);
140
                        zSort.setXMLEntity(zSortXML);
141
                }
142
        }
143

    
144

    
145
        public ILegend cloneLegend() throws XMLException {
146
                return (ILegend) LegendFactory.createFromXML(getXMLEntity());
147
        }
148

    
149

    
150
        public void setDataSource(DataSource ds) {
151
                // No hacemos nada, no lo vamos a usar
152
        }
153

    
154
        public int getShapeType() {
155
                return shapeType;
156
        }
157

    
158
        public void setShapeType(int shapeType) {
159
                if (this.shapeType != shapeType) {
160
                        defaultSymbol = SymbologyFactory.createDefaultSymbolByShapeType(shapeType);
161
                        this.shapeType = shapeType;
162
                }
163
        }
164

    
165

    
166

    
167
    public ISymbol getSymbolByFeature(IFeature feat) {
168
        return defaultSymbol;
169
    }
170

    
171
        public void useDefaultSymbol(boolean b) {
172
                // TODO Auto-generated method stub
173
        }
174

    
175
    public String[] getUsedFields() {
176
        return new String[0];
177
    }
178

    
179
    public boolean isUseDefaultSymbol() {
180
            return true;
181

    
182
    }
183

    
184

    
185
    public ZSort getZSort() {
186
            return zSort;
187

    
188
    }
189

    
190
        public void setZSort(ZSort zSort) {
191
                if (zSort == null) {
192
                        removeLegendListener(this.zSort);
193
                }
194
                this.zSort = zSort;
195
                addLegendListener(zSort);
196
        }
197

    
198

    
199

    
200
        public String getClassName() {
201
                return getClass().getName();
202
        }
203

    
204

    
205
}