Statistics
| Revision:

svn-gvsig-desktop / trunk / extSymbology / src / org / gvsig / symbology / fmap / rendering / GraduatedSymbolLegend.java @ 18755

History | View | Annotate | Download (6.36 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 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

    
42
/* CVS MESSAGES:
43
*
44
* $Id: GraduatedSymbolLegend.java 16187 2007-11-08 16:13:44Z jdominguez $
45
* $Log$
46
* Revision 1.3  2007-05-17 09:32:06  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.2  2007/03/09 11:20:56  jaume
50
* Advanced symbology (start committing)
51
*
52
* Revision 1.1.2.4  2007/02/15 16:23:44  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.1.2.3  2007/02/14 15:53:35  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.1.2.2  2007/02/13 16:19:19  jaume
59
* graduated symbol legends (start commiting)
60
*
61
* Revision 1.1.2.1  2007/02/12 15:15:20  jaume
62
* refactored interval legend and added graduated symbol legend
63
*
64
*
65
*/
66
package org.gvsig.symbology.fmap.rendering;
67

    
68
import org.gvsig.symbology.fmap.styles.SimpleMarkerFillPropertiesStyle;
69
import org.gvsig.symbology.fmap.symbols.MarkerFillSymbol;
70

    
71
import com.iver.cit.gvsig.fmap.core.FShape;
72
import com.iver.cit.gvsig.fmap.core.IFeature;
73
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
74
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
75
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
76
import com.iver.cit.gvsig.fmap.rendering.VectorialIntervalLegend;
77
import com.iver.utiles.StringUtilities;
78
import com.iver.utiles.XMLEntity;
79

    
80

    
81
/**
82
 * <p>GraduatedSymbolLegend is a legend that allows to classify ranges of
83
 * values using a value with symbol sizes.<b>
84
 * </p>
85
 * <p>
86
 * The symbol size will be calculated according the min size, the
87
 * max size and the amount of intervals. So for a min size of 1, a max size
88
 * of 5, and 5 intervals, symbol sizes will be [1, 2, 3, 4, 5].
89
 * </p>
90
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
91
 */
92
public class GraduatedSymbolLegend extends VectorialIntervalLegend {
93
        private double maxSymbolSize;
94
        private double minSymbolSize;
95
        private ISymbol templateSymbol;
96
        /**
97
         * DefaultConstructor
98
         */
99
        public GraduatedSymbolLegend() {
100
                super();
101
        }
102
        
103
        /**
104
         * Convenience constructor.
105
         * 
106
         * Creates a new instance of GraduatedSymbolLegend from a VectorialIntervalLegend by
107
         * taking the same fields. 
108
         * @param leg
109
         */
110
        public GraduatedSymbolLegend(VectorialIntervalLegend leg) {
111
                this();
112
                VectorialIntervalLegend.initializeVectorialIntervalLegend(leg, this);
113
        }
114
        
115
        /**
116
         * Returns the max symbol size. Combined with the min symbol size and
117
         * the interval count, will produce the symbol sizes.
118
         * @return double, the max size.
119
         */
120
        public double getMaxSymbolSize() {
121
                return maxSymbolSize;
122
        }
123

    
124
        /**
125
         * Returns the min symbol size. Combined with the max symbol size and
126
         * the interval count, will produce the symbol sizes.
127
         * @return double, the min size.
128
         */
129
        public double getMinSymbolSize() {
130
                return minSymbolSize;
131
        }
132

    
133
        /**
134
         * Sets the max symbol size. Combined with the min symbol size and
135
         * the interval count, will produce the symbol sizes.
136
         */
137
        public void setMaxSymbolSize(double size) {
138
                this.maxSymbolSize = size;
139
        }
140

    
141
        /**
142
         * Sets the min symbol size. Combined with the max symbol size and
143
         * the interval count, will produce the symbol sizes.
144
         */
145
        public void setMinSymbolSize(double size) {
146
                this.minSymbolSize = size;
147
        }
148

    
149
        public XMLEntity getXMLEntity() {
150
                XMLEntity xml = super.getXMLEntity();
151

    
152
                xml.putProperty("className", getClass().getName());
153
                xml.putProperty("maxSymbolSize", maxSymbolSize);
154
                xml.putProperty("minSymbolSize", minSymbolSize);
155

    
156
                if (templateSymbol != null) {
157
                        XMLEntity templateXML = templateSymbol.getXMLEntity();
158
                        templateXML.putProperty("id", "templateSymbol");
159
                        xml.addChild(templateXML);
160
                }
161
                
162
                // remove unuseful properties from supertype
163
                xml.remove("startColor");
164
                xml.remove("endColor");
165
                return xml;
166
        }
167

    
168
        public void setXMLEntity(XMLEntity xml) {
169
                // patch for avoid errors in call to supertype's
170
                // setXMLEntity(XMLEntity)
171
                xml.putProperty("startColor",
172
                                StringUtilities.color2String(super.getStartColor()));
173
                xml.putProperty("endColor",
174
                                StringUtilities.color2String(super.getEndColor()));
175
                
176
                // end patch
177
                super.setXMLEntity(xml);
178
                maxSymbolSize = xml.getDoubleProperty("maxSymbolSize");
179
                minSymbolSize = xml.getDoubleProperty("minSymbolSize");
180
                
181
                if (xml.firstChild("id", "templateSymbol") != null) {
182
                        XMLEntity templateXML = xml.firstChild("id", "templateSymbol");
183
                        templateSymbol = SymbologyFactory.createSymbolFromXML(templateXML, "templateSymbol");
184
                } 
185
        }
186

    
187
        @Override
188
        public ISymbol getSymbolByFeature(IFeature feat) {
189
                ISymbol theSymbol = super.getSymbolByFeature(feat); 
190
                        
191
                if (feat.getGeometry().getGeometryType() == FShape.POLYGON && theSymbol instanceof IMarkerSymbol) {
192
                        // transform it to a fill symbol
193
                        MarkerFillSymbol aux = new MarkerFillSymbol();
194
                        // tell the fill style to draw the IMarkerSymbol
195
                        // as a IFillSymbol centering it in the shape polygon
196
                        // centroid and applying offset (if any).
197
                        aux.setMarker((IMarkerSymbol) theSymbol);
198
                        SimpleMarkerFillPropertiesStyle p = new SimpleMarkerFillPropertiesStyle();
199
                        p.setFillStyle(SimpleMarkerFillPropertiesStyle.SINGLE_CENTERED_SYMBOL);
200
                        aux.setMarkerFillProperties(p);
201
                        theSymbol = aux;
202
                }
203
                return theSymbol;
204
        }
205

    
206
        /**
207
         * Sets the default symbol.
208
         * @param symbol
209
         */
210
        public void setTemplateSymbol(ISymbol symbol) {
211
                this.templateSymbol = symbol;
212
        }
213
        /**
214
         * Obtains the template symbol
215
         * @return
216
         */
217
        public ISymbol getTemplateSymbol() {
218
                return templateSymbol;
219
        }
220
}