root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / DotDensityLegend.java @ 10679
History | View | Annotate | Download (5.67 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: DotDensityLegend.java 10679 2007-03-09 11:25:01Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3 2007-03-09 11:20:56 jaume
|
47 |
* Advanced symbology (start committing)
|
48 |
*
|
49 |
* Revision 1.2.2.5 2007/02/21 07:34:09 jaume
|
50 |
* labeling starts working
|
51 |
*
|
52 |
* Revision 1.2.2.4 2007/02/15 16:23:44 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.2.2.3 2007/02/12 15:15:20 jaume
|
56 |
* refactored interval legend and added graduated symbol legend
|
57 |
*
|
58 |
* Revision 1.2.2.2 2007/02/09 07:47:04 jaume
|
59 |
* Isymbol moved
|
60 |
*
|
61 |
* Revision 1.2.2.1 2007/01/26 13:48:17 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.2 2007/01/16 11:50:50 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.1 2007/01/10 16:39:41 jaume
|
68 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
69 |
*
|
70 |
* Revision 1.2 2006/11/17 12:49:58 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.1 2006/11/14 12:30:26 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
*
|
77 |
*/
|
78 |
package com.iver.cit.gvsig.fmap.rendering; |
79 |
|
80 |
import java.awt.Color; |
81 |
|
82 |
import com.hardcode.gdbms.engine.values.NumericValue; |
83 |
import com.hardcode.gdbms.engine.values.Value; |
84 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
85 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
86 |
import com.iver.cit.gvsig.fmap.core.symbols.DotDensityFillSymbol; |
87 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
88 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
89 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol; |
90 |
import com.iver.utiles.StringUtilities; |
91 |
import com.iver.utiles.XMLEntity; |
92 |
|
93 |
|
94 |
/**
|
95 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
96 |
*/
|
97 |
public class DotDensityLegend extends VectorialUniqueValueLegend { |
98 |
|
99 |
private double dotValue; |
100 |
private static final int SIMPLE_FILL_LAYER_INDEX = 0; |
101 |
private static final int DOT_DENSITY_LAYER_INDEX = 1; |
102 |
|
103 |
public ISymbol getSymbolByValue(Value key) {
|
104 |
MultiLayerFillSymbol sym = (MultiLayerFillSymbol) getDefaultSymbol(); |
105 |
DotDensityFillSymbol densitySym = (DotDensityFillSymbol) sym.getLayer(DOT_DENSITY_LAYER_INDEX); |
106 |
densitySym.setDotCount((int) (((NumericValue) key).doubleValue()/dotValue));
|
107 |
return sym;
|
108 |
} |
109 |
|
110 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
111 |
return getSymbolByValue(feat.getAttribute(fieldId));
|
112 |
} |
113 |
|
114 |
public void setDotValue(double dotValue) { |
115 |
this.dotValue = dotValue;
|
116 |
} |
117 |
|
118 |
public XMLEntity getXMLEntity() {
|
119 |
XMLEntity xml = new XMLEntity();
|
120 |
xml.putProperty("className", getClass().getName());
|
121 |
xml.putProperty("dotValue", dotValue);
|
122 |
xml.putProperty("fieldName", getFieldName());
|
123 |
xml.addChild(getDefaultSymbol().getXMLEntity()); |
124 |
return xml;
|
125 |
} |
126 |
|
127 |
public void setXMLEntity(XMLEntity xml) { |
128 |
dotValue = xml.getDoubleProperty("dotValue");
|
129 |
setFieldName(xml.getStringProperty("fieldName"));
|
130 |
setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
131 |
} |
132 |
|
133 |
public ILineSymbol getOutline() {
|
134 |
try {
|
135 |
// defined by the SimpleFillSymbol layer
|
136 |
XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()). |
137 |
getLayer(SIMPLE_FILL_LAYER_INDEX).getXMLEntity(); |
138 |
return (ILineSymbol) SymbologyFactory.createStyleFromXML(xml.getChild(0), "outline"); |
139 |
} catch (NullPointerException npE) { |
140 |
return null; |
141 |
} |
142 |
} |
143 |
|
144 |
public Color getDotColor() { |
145 |
try {
|
146 |
// defined by the DotDensitySymbol layer
|
147 |
XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()). |
148 |
getLayer(DOT_DENSITY_LAYER_INDEX).getXMLEntity(); |
149 |
return StringUtilities.string2Color(xml.getStringProperty("color")); |
150 |
} catch (NullPointerException npE) { |
151 |
return null; |
152 |
} |
153 |
} |
154 |
|
155 |
public Color getBGColor() { |
156 |
try {
|
157 |
// defined by the SimpleFillSymbol layer
|
158 |
XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()). |
159 |
getLayer(SIMPLE_FILL_LAYER_INDEX).getXMLEntity(); |
160 |
return StringUtilities.string2Color(xml.getStringProperty("color")); |
161 |
} catch (NullPointerException npE) { |
162 |
return null; |
163 |
} |
164 |
} |
165 |
|
166 |
public double getDotValue() { |
167 |
try {
|
168 |
XMLEntity xml = getXMLEntity(); |
169 |
return xml.getDoubleProperty("dotValue"); |
170 |
} catch (NullPointerException npE) { |
171 |
return 0; |
172 |
} |
173 |
} |
174 |
|
175 |
public double getDotSize() { |
176 |
try {
|
177 |
// defined by the DotDensitySymbol layer
|
178 |
XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()). |
179 |
getLayer(DOT_DENSITY_LAYER_INDEX).getXMLEntity(); |
180 |
return xml.getDoubleProperty("dotSize"); |
181 |
} catch (NullPointerException npE) { |
182 |
return -1; // TODO define default |
183 |
} |
184 |
} |
185 |
} |