Statistics
| Revision:

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

History | View | Annotate | Download (6.43 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

    
45
import com.iver.cit.gvsig.fmap.core.FShape;
46
import com.iver.cit.gvsig.fmap.core.IFeature;
47
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
48
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
49
import com.iver.cit.gvsig.fmap.layers.XMLException;
50
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
51

    
52
import com.iver.utiles.XMLEntity;
53

    
54

    
55
/**
56
 * Leyenda se s?mbolo ?nico.
57
 *
58
 * @author Vicente Caballero Navarro
59
 */
60
public class SingleSymbolLegend implements VectorialLegend, Legend {
61
        private FSymbol defaultSymbol;
62
        private String labelFieldName;
63
        private String labelFieldHeight;
64
        private String labelFieldRotation;
65
        private int shapeType = FShape.POLYGON; // Por defecto, tipo pol?gono
66
        // private boolean bWithHeightText;
67
        /**
68
         * Crea un nuevo SingleSymbolLegend.
69
         *
70
         * @param style S?mbolo.
71
         */
72
        public SingleSymbolLegend(FSymbol style) {
73
                defaultSymbol = style;
74
        }
75

    
76
        /**
77
         * Crea un nuevo SingleSymbolLegend.
78
         */
79
        public SingleSymbolLegend() {
80
                defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
81
        }
82

    
83
        /**
84
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(FSymbol)
85
         */
86
        public void setDefaultSymbol(FSymbol s) {
87
                setShapeType(s.getSymbolType());
88
                defaultSymbol = s;
89
        }
90

    
91
        /**
92
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelField()
93
         */
94
        public String getLabelField() {
95
                return labelFieldName;
96
        }
97

    
98
        /**
99
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setLabelField(int)
100
         */
101
        public void setLabelField(String fieldName) {
102
                labelFieldName = fieldName;
103
        }
104

    
105
        /**
106
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
107
         */
108
        public FSymbol getSymbol(int recordIndex) {
109
                return defaultSymbol;
110
        }
111

    
112
        /**
113
         * @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
114
         */
115
        public FSymbol getDefaultSymbol() {
116
                return defaultSymbol;
117
        }
118

    
119
        /**
120
         * @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
121
         */
122
        public XMLEntity getXMLEntity() {
123
                XMLEntity xml = new XMLEntity();
124
                xml.putProperty("className",this.getClass().getName());
125
                xml.putProperty("labelFieldName", labelFieldName);
126
        xml.putProperty("labelHeightFieldName", labelFieldHeight);
127
        xml.putProperty("labelRotationFieldName", labelFieldRotation);
128
                xml.addChild(defaultSymbol.getXMLEntity());
129

    
130
                return xml;
131
        }
132

    
133
        /**
134
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setXMLEntity()
135
         */
136
        public void setXMLEntity03(XMLEntity xml) {
137
                setLabelField(xml.getStringProperty("labelFieldName"));
138

    
139
                FSymbol auxSym = FSymbol.createFromXML03(xml.getChild(0));
140
                setDefaultSymbol(auxSym);
141
        }
142

    
143
        /**
144
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setXMLEntity()
145
         */
146
        public void setXMLEntity(XMLEntity xml) {
147
                setLabelField(xml.getStringProperty("labelFieldName"));
148
        if (xml.contains("labelHeightFieldName"))
149
            setLabelHeightField(xml.getStringProperty("labelHeightFieldName"));
150
        if (xml.contains("labelRotationFieldName"))
151
            setLabelRotationField(xml.getStringProperty("labelRotationFieldName"));
152

    
153
                FSymbol auxSym = FSymbol.createFromXML(xml.getChild(0));
154
                setDefaultSymbol(auxSym);
155
        }
156

    
157
        /**
158
         * @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
159
         */
160
        public Legend cloneLegend() throws XMLException {
161
                return (Legend) LegendFactory.createFromXML(getXMLEntity());
162
        }
163

    
164
        /* (non-Javadoc)
165
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
166
         */
167
        public void setDataSource(DataSource ds) {
168
                // No hacemos nada, no lo vamos a usar
169
        }
170

    
171
        /* (non-Javadoc)
172
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
173
         */
174
        public int getShapeType() {
175
                return shapeType;
176
        }
177

    
178
        /* (non-Javadoc)
179
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setShapeType(int)
180
         */
181
        public void setShapeType(int shapeType) {
182
                if (this.shapeType != shapeType) {
183
                        switch (shapeType) {
184
                                case FShape.POINT:
185
                                        defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
186

    
187
                                        break;
188

    
189
                                case FShape.LINE:
190
                                        defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
191

    
192
                                        break;
193

    
194
                                case FShape.POLYGON:
195
                                        defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
196

    
197
                                        break;
198
                        }
199

    
200
                        this.shapeType = shapeType;
201
                }
202
        }
203

    
204
        /* (non-Javadoc)
205
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
206
         */
207
        public String getLabelHeightField() {
208
                return labelFieldHeight;
209
        }
210

    
211
        /**
212
         * Inserta el texto que refleja el alto del campo.
213
         *
214
         * @param str String.
215
         */
216
        public void setLabelHeightField(String str) {
217
                labelFieldHeight = str;
218
        }
219

    
220
        /* (non-Javadoc)
221
         * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
222
         */
223
        public String getLabelRotationField() {
224
                return labelFieldRotation;
225
        }
226

    
227
        /**
228
         * Inserta el texto que refleja la rotaci?n del campo.
229
         *
230
         * @param str String.
231
         */
232
        public void setLabelRotationField(String str) {
233
                labelFieldRotation = str;
234
        }
235

    
236
    public FSymbol getSymbolByFeature(IFeature feat) {
237
        return defaultSymbol;
238
    }
239

    
240
        public void useDefaultSymbol(boolean b) {
241
                // TODO Auto-generated method stub
242
        }
243

    
244
        /* public boolean isBWithHeightText() {
245
                return bWithHeightText;
246
        }
247

248
        public void setBWithHeightText(boolean withHeightText) {
249
                bWithHeightText = withHeightText;
250
        } */
251
}