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