Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / DotDensityLegend.java @ 9641

History | View | Annotate | Download (4.33 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 9641 2007-01-10 16:42:08Z jaume $
45
* $Log$
46
* Revision 1.1  2007-01-10 16:39:41  jaume
47
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
48
*
49
* Revision 1.2  2006/11/17 12:49:58  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1  2006/11/14 12:30:26  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
package com.iver.cit.gvsig.fmap.rendering;
58

    
59
import java.awt.Color;
60

    
61
import com.hardcode.gdbms.engine.values.NumericValue;
62
import com.hardcode.gdbms.engine.values.Value;
63
import com.iver.cit.gvsig.fmap.core.IFeature;
64
import com.iver.cit.gvsig.fmap.core.SymbolFactory;
65
import com.iver.cit.gvsig.fmap.core.symbols.DotDensityFillSymbol;
66
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
67
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol;
68
import com.iver.utiles.StringUtilities;
69
import com.iver.utiles.XMLEntity;
70

    
71

    
72
public class DotDensityLegend extends VectorialUniqueValueLegend {
73
    private double dotValue;
74

    
75
    public ISymbol getSymbolByValue(Value key) {
76
            DotDensityFillSymbol sym = (DotDensityFillSymbol) getDefaultSymbol();
77
        sym.setDotCount((int) (((NumericValue) key).doubleValue()/dotValue));
78
        return sym;
79
    }
80

    
81
    public ISymbol getSymbolByFeature(IFeature feat) {
82
        return getSymbolByValue(feat.getAttribute(fieldId));
83
    }
84

    
85
    public void setDotValue(double dotValue) {
86
        this.dotValue = dotValue;
87
    }
88

    
89
    public XMLEntity getXMLEntity() {
90
        XMLEntity xml = new XMLEntity();
91
        xml.putProperty("className", getClass().getName());
92
        xml.putProperty("dotValue", dotValue);
93
        xml.putProperty("fieldName", getFieldName());
94
        xml.addChild(getDefaultSymbol().getXMLEntity());
95
        return xml;
96
    }
97

    
98
    public void setXMLEntity(XMLEntity xml) {
99
        dotValue = xml.getDoubleProperty("dotValue");
100
        setFieldName(xml.getStringProperty("fieldName"));
101
        setDefaultSymbol(SymbolFactory.createFromXML(xml.getChild(0), null));
102
    }
103

    
104
    public Color getOutlineColor() {
105
            try {
106
            XMLEntity xml = getDefaultSymbol().getXMLEntity();
107
                return StringUtilities.string2Color(xml.getStringProperty("outline"));
108
        } catch (NullPointerException npE) {
109
                return null;
110
        }
111
    }
112

    
113
    public Color getDotColor() {
114
            try {
115
            XMLEntity xml = getDefaultSymbol().getXMLEntity().getChild(0);
116
                return StringUtilities.string2Color(xml.getStringProperty("color"));
117
        } catch (NullPointerException npE) {
118
                return null;
119
        }
120
    }
121

    
122
    public Color getBGColor() {
123
            try {
124
            XMLEntity xml = getDefaultSymbol().getXMLEntity();
125
                return StringUtilities.string2Color(xml.getStringProperty("color"));
126
        } catch (NullPointerException npE) {
127
                return null;
128
        }
129
    }
130

    
131
    public double getDotValue() {
132
            try {
133
                XMLEntity xml = getXMLEntity();
134
                    return xml.getDoubleProperty("dotValue");
135
            } catch (NullPointerException npE) {
136
                    return 0;
137
            }
138
    }
139

    
140
    public double getDotSize() {
141
            try {
142
                    XMLEntity xml = getDefaultSymbol().getXMLEntity().getChild(0);
143
                    return xml.getDoubleProperty("dotSize");
144
            } catch (NullPointerException npE) {
145
                    return -1; // TODO define default
146
            }
147
    }
148
}