Statistics
| Revision:

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

History | View | Annotate | Download (5.39 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.ISymbol;
50
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
51
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol;
52
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol;
53
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54
import com.iver.cit.gvsig.fmap.layers.XMLException;
55
import com.iver.utiles.XMLEntity;
56

    
57

    
58
/**
59
 * Leyenda se s?mbolo ?nico.
60
 * @author   Vicente Caballero Navarro
61
 */
62
public class SingleSymbolLegend implements IVectorialLegend {
63
        private ISymbol defaultSymbol;
64
    private int shapeType = FShape.POLYGON; // Por defecto, tipo pol?gono
65
        private ZSort zSort;
66

    
67

    
68
        public SingleSymbolLegend() {        }
69

    
70

    
71
        /**
72
         * Crea un nuevo SingleSymbolLegend.
73
         *
74
         * @param style S?mbolo.
75
         */
76
        public SingleSymbolLegend(ISymbol style) {
77
                defaultSymbol = style;
78
        }
79

    
80

    
81

    
82
        public void setDefaultSymbol(ISymbol s) {
83
                if (s == null) throw new NullPointerException("Default symbol cannot be null");
84
                setShapeType(s.getSymbolType());
85
                defaultSymbol = s;
86
        }
87

    
88

    
89
        public ISymbol getSymbol(int recordIndex) {
90
                return defaultSymbol;
91
        }
92

    
93
        public ISymbol getDefaultSymbol() {
94
                if(defaultSymbol==null)//mio
95
                        defaultSymbol=SymbologyFactory.createDefaultFillSymbol();//mio
96
                return defaultSymbol;
97
        }
98

    
99
        public String getSLDString(String layerName)
100
        {
101

    
102
                try{
103
                        XmlBuilder xmlBuilder = new XmlBuilder();
104
                        xmlBuilder.writeHeader();
105
                        xmlBuilder.openTag(SLDTags.SLD_ROOT, SLDTags.VERSION_ATTR, SLDTags.VERSION_1_0_0);
106
                        xmlBuilder.openTag(SLDTags.NAMEDLAYER);
107
                        xmlBuilder.writeTag(SLDTags.NAME,layerName);
108
                        xmlBuilder.openTag(SLDTags.USERSTYLE);
109
                        xmlBuilder.openTag(SLDTags.FEATURETYPESTYLE);
110
                        xmlBuilder.writeTag(SLDTags.FEATURETYPENAME,"FeatureTypeName");
111
                        xmlBuilder.openTag(SLDTags.RULE);
112
                        if (this.defaultSymbol instanceof ISLDCompatible)
113
                        {
114
                                ISLDCompatible symSLD = (ISLDCompatible) this.defaultSymbol;
115
                                xmlBuilder.writeRaw(symSLD.toSLD());
116
                        }
117
                        else
118
                                throw new RuntimeException("Cannot convert default Symbol " + this.defaultSymbol.getDescription() + " to SLD");
119

    
120
                        xmlBuilder.closeTag();
121
                        xmlBuilder.closeTag();
122
                        xmlBuilder.closeTag();
123
                        xmlBuilder.closeTag();
124
                        xmlBuilder.closeTag();
125
                        return xmlBuilder.getXML();
126
                }
127
                catch(Exception e)
128
                {
129
                        e.printStackTrace();
130
                        return null;
131
                }
132
        }
133

    
134
        public XMLEntity getXMLEntity() {
135
                XMLEntity xml = new XMLEntity();
136
                xml.putProperty("className",this.getClass().getName());
137
                xml.addChild(defaultSymbol.getXMLEntity());
138

    
139
                return xml;
140
        }
141

    
142
        public void setXMLEntity03(XMLEntity xml) {
143
                FSymbol auxSym = FSymbol.createFromXML03(xml.getChild(0));
144
                setDefaultSymbol(auxSym);
145
        }
146

    
147
        public void setXMLEntity(XMLEntity xml) {
148
        ISymbol auxSym = SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
149
                setDefaultSymbol(auxSym);
150
        }
151

    
152

    
153
        public ILegend cloneLegend() throws XMLException {
154
                return (ILegend) LegendFactory.createFromXML(getXMLEntity());
155
        }
156

    
157

    
158
        public void setDataSource(DataSource ds) {
159
                // No hacemos nada, no lo vamos a usar
160
        }
161

    
162
        public int getShapeType() {
163
                return shapeType;
164
        }
165

    
166
        public void setShapeType(int shapeType) {
167
                if (this.shapeType != shapeType) {
168
                        switch (shapeType) {
169
                                case FShape.POINT:
170
                                        defaultSymbol = new SimpleMarkerSymbol();
171
                                        break;
172

    
173
                                case FShape.LINE:
174
                                        defaultSymbol = new SimpleLineSymbol();
175

    
176
                                        break;
177

    
178
                                case FShape.POLYGON:
179
                                        defaultSymbol = new SimpleFillSymbol();
180

    
181
                                        break;
182
                        }
183

    
184
                        this.shapeType = shapeType;
185
                }
186
        }
187

    
188

    
189

    
190
    public ISymbol getSymbolByFeature(IFeature feat) {
191
        return defaultSymbol;
192
    }
193

    
194
        public void useDefaultSymbol(boolean b) {
195
                // TODO Auto-generated method stub
196
        }
197

    
198
    public String[] getUsedFields() {
199
        return new String[0];
200
    }
201

    
202
    public boolean isUseDefaultSymbol() {
203
            return true;
204

    
205
    }
206

    
207

    
208
    public ZSort getZSort() {
209
            return zSort;
210

    
211
    }
212
    public void setZSort(ZSort zSort) {
213
            this.zSort = zSort;
214
    }
215

    
216

    
217
        public String getClassName() {
218
                return getClass().getName();
219
        }
220

    
221

    
222
}