Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / DotDensityLegend.java @ 10436

History | View | Annotate | Download (5.75 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 10436 2007-02-21 07:34:09Z jaume $
45
* $Log$
46
* Revision 1.2.2.5  2007-02-21 07:34:09  jaume
47
* labeling starts working
48
*
49
* Revision 1.2.2.4  2007/02/15 16:23:44  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2.2.3  2007/02/12 15:15:20  jaume
53
* refactored interval legend and added graduated symbol legend
54
*
55
* Revision 1.2.2.2  2007/02/09 07:47:04  jaume
56
* Isymbol moved
57
*
58
* Revision 1.2.2.1  2007/01/26 13:48:17  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.2  2007/01/16 11:50:50  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.1  2007/01/10 16:39:41  jaume
65
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
66
*
67
* Revision 1.2  2006/11/17 12:49:58  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.1  2006/11/14 12:30:26  jaume
71
* *** empty log message ***
72
*
73
*
74
*/
75
package com.iver.cit.gvsig.fmap.rendering;
76

    
77
import java.awt.Color;
78

    
79
import com.hardcode.gdbms.engine.values.NumericValue;
80
import com.hardcode.gdbms.engine.values.Value;
81
import com.iver.cit.gvsig.fmap.core.IFeature;
82
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
83
import com.iver.cit.gvsig.fmap.core.symbols.DotDensityFillSymbol;
84
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
85
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
86
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol;
87
import com.iver.utiles.StringUtilities;
88
import com.iver.utiles.XMLEntity;
89

    
90

    
91
/**
92
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
93
 */
94
public class DotDensityLegend extends VectorialUniqueValueLegend {
95
    /**
96
         * @uml.property  name="dotValue"
97
         */
98
    private double dotValue;
99
    private static final int SIMPLE_FILL_LAYER_INDEX = 0;
100
    private static final int DOT_DENSITY_LAYER_INDEX = 1;
101

    
102
    public ISymbol getSymbolByValue(Value key) {
103
            MultiLayerFillSymbol sym = (MultiLayerFillSymbol) getDefaultSymbol();
104
            DotDensityFillSymbol densitySym = (DotDensityFillSymbol) sym.getLayer(DOT_DENSITY_LAYER_INDEX);
105
                densitySym.setDotCount((int) (((NumericValue) key).doubleValue()/dotValue));
106
        return sym;
107
    }
108

    
109
    public ISymbol getSymbolByFeature(IFeature feat) {
110
        return getSymbolByValue(feat.getAttribute(fieldId));
111
    }
112

    
113
    /**
114
         * @param dotValue
115
         * @uml.property  name="dotValue"
116
         */
117
    public void setDotValue(double dotValue) {
118
        this.dotValue = dotValue;
119
    }
120

    
121
    public XMLEntity getXMLEntity() {
122
        XMLEntity xml = new XMLEntity();
123
        xml.putProperty("className", getClass().getName());
124
        xml.putProperty("dotValue", dotValue);
125
        xml.putProperty("fieldName", getFieldName());
126
        xml.addChild(getDefaultSymbol().getXMLEntity());
127
        return xml;
128
    }
129

    
130
    public void setXMLEntity(XMLEntity xml) {
131
        dotValue = xml.getDoubleProperty("dotValue");
132
        setFieldName(xml.getStringProperty("fieldName"));
133
        setDefaultSymbol(SymbologyFactory.createSymbolFromXML(xml.getChild(0), null));
134
    }
135

    
136
    public ILineSymbol getOutline() {
137
            try {
138
                    // defined by the SimpleFillSymbol layer
139
            XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()).
140
                    getLayer(SIMPLE_FILL_LAYER_INDEX).getXMLEntity();
141
                return (ILineSymbol) SymbologyFactory.createStyleFromXML(xml.getChild(0), "outline");
142
        } catch (NullPointerException npE) {
143
                return null;
144
        }
145
    }
146

    
147
    public Color getDotColor() {
148
            try {
149
                    // defined by the DotDensitySymbol layer
150
                    XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()).
151
                             getLayer(DOT_DENSITY_LAYER_INDEX).getXMLEntity();
152
                return StringUtilities.string2Color(xml.getStringProperty("color"));
153
        } catch (NullPointerException npE) {
154
                return null;
155
        }
156
    }
157

    
158
    public Color getBGColor() {
159
            try {
160
                    // defined by the SimpleFillSymbol layer
161
                    XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()).
162
                            getLayer(SIMPLE_FILL_LAYER_INDEX).getXMLEntity();
163
                return StringUtilities.string2Color(xml.getStringProperty("color"));
164
        } catch (NullPointerException npE) {
165
                return null;
166
        }
167
    }
168

    
169
    /**
170
         * @return
171
         * @uml.property  name="dotValue"
172
         */
173
    public double getDotValue() {
174
            try {
175
                XMLEntity xml = getXMLEntity();
176
                    return xml.getDoubleProperty("dotValue");
177
            } catch (NullPointerException npE) {
178
                    return 0;
179
            }
180
    }
181

    
182
    public double getDotSize() {
183
            try {
184
                    // defined by the DotDensitySymbol layer
185
                    XMLEntity xml = ((MultiLayerFillSymbol) getDefaultSymbol()).
186
                             getLayer(DOT_DENSITY_LAYER_INDEX).getXMLEntity();
187
                    return xml.getDoubleProperty("dotSize");
188
            } catch (NullPointerException npE) {
189
                    return -1; // TODO define default
190
            }
191
    }
192
}