Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / VectorialIntervalLegend.java @ 31631

History | View | Annotate | Download (6.39 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl;
23

    
24
import java.awt.Color;
25

    
26
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.dynobject.DynClass;
29
import org.gvsig.tools.persistence.PersistenceException;
30
import org.gvsig.tools.persistence.PersistentState;
31

    
32
/**
33
 * <p>
34
 * VectorialIntervalLegend (which should be better called GraduatedColorLegend)
35
 * is a legend that allows to classify ranges of values using a color gradient
36
 * based on a value.<b>
37
 * </p>
38
 * <p>
39
 * The color gradient will be calculated according the starting color, the
40
 * ending color and the amount of intervals.
41
 * </p>
42
 * 
43
 * @author Vicente Caballero Navarro
44
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
45
 */
46
public class VectorialIntervalLegend extends AbstractIntervalLegend {
47
        public static final String VECTORIAL_INTERVAL_LEGEND_DYNCLASS_NAME =
48
                        "VectorialIntervalLegend";
49

    
50
        private static final String FIELD_START_COLOR = "startColor";
51
        private static final String FIELD_END_COLOR = "endColor";
52
        
53
        private int shapeType;
54
    private Color startColor = Color.red;
55
    private Color endColor = Color.blue;
56

    
57
    /**
58
     * Constructor method
59
     */
60
    public VectorialIntervalLegend() {
61
        //defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
62
    }
63

    
64
    /**
65
     * Constructor method
66
     *
67
     * @param type type of the shape.
68
     */
69
    public VectorialIntervalLegend(int type) {
70
            setShapeType(type);
71
    }
72

    
73
//    public ILegend cloneLegend() throws XMLException {
74
//        return LegendFactory.createFromXML(getXMLEntity());
75
//    }
76

    
77
    /**
78
         * Returns the final color
79
         * @return Color  final color.
80
         * @uml.property  name="endColor"
81
         */
82
    public Color getEndColor() {
83
        return endColor;
84
    }
85

    
86
    /**
87
         * Inserts the final color.
88
         * @param endColor final color.
89
         * @uml.property  name="endColor"
90
         */
91
    public void setEndColor(Color endColor) {
92
        this.endColor = endColor;
93
    }
94

    
95
    /**
96
         * Returns the initial color.
97
         * @return  Color initial color.
98
         * @uml.property  name="startColor"
99
         */
100
    public Color getStartColor() {
101
        return startColor;
102
    }
103

    
104
    /**
105
         * Inserts the initial color
106
         * @param startColor initial color.
107
         * @uml.property  name="startColor"
108
         */
109
    public void setStartColor(Color startColor) {
110
        this.startColor = startColor;
111
    }
112

    
113
        public int getShapeType() {
114
                return shapeType;
115
        }
116

    
117
        public void setShapeType(int shapeType) {
118
                if (this.shapeType != shapeType) {
119
                        setDefaultSymbol(getSymbolManager().createSymbol(shapeType));
120
                        this.shapeType = shapeType;
121
                }
122
        }
123

    
124

    
125
        public String getClassName() {
126
                return getClass().getName();
127
        }
128

    
129
        public Object clone() throws CloneNotSupportedException {
130
                VectorialIntervalLegend clone = (VectorialIntervalLegend) super.clone();
131

    
132
                // Nothing to clone, as Color objects are inmutable, keep the original
133
                // references.
134

    
135
                return clone;
136
        }
137

    
138
        public void loadFromState(PersistentState state)
139
                        throws PersistenceException {
140
                // Set parent properties
141
                super.loadFromState(state);
142
                // Set own properties
143
                setStartColor((Color) state.get(FIELD_START_COLOR));
144
                setEndColor((Color) state.get(FIELD_END_COLOR));
145
        }
146

    
147
        public void saveToState(PersistentState state) throws PersistenceException {
148
                // Save parent properties
149
                super.saveToState(state);
150
                // Save own properties
151
                state.set(FIELD_START_COLOR, getStartColor());
152
                state.set(FIELD_END_COLOR, getEndColor());
153
        }
154

    
155
        public static void registerPersistence() {
156
                // Add the DynClass definition.
157
                DynClass dynClass =
158
                                ToolsLocator.getDynObjectManager().add(
159
                                                VECTORIAL_INTERVAL_LEGEND_DYNCLASS_NAME);
160

    
161
                // Extend the Interval Legend base definition
162
                dynClass.extend(INTERVAL_LEGEND_DYNCLASS_NAME);
163

    
164
                // Start color
165
                dynClass.addDynFieldObject(FIELD_START_COLOR)
166
                                .setMandatory(true)
167
                                .setDescription("Start color");
168
                // End color
169
                dynClass.addDynFieldObject(FIELD_END_COLOR)
170
                                .setMandatory(true)
171
                                .setDescription("End color");
172

    
173
                ToolsLocator.getPersistenceManager().registerClass(
174
                                VectorialIntervalLegend.class, dynClass);
175
        }
176

    
177
        public IInterval createInterval(double min, double max) {
178
                return new FInterval(min, max);
179
        }
180

    
181
        //
182
        /**
183
         * <p>This method does not exist officially. But what it does is just apply the
184
         * values of a VectorialIntervalLegend to other so, It is not needed to
185
         * replicate the code of populating the legend in every panel that produces
186
         * a legend by intervals.<br>
187
         * </p>
188
         * <p>
189
         * ok this method is messy, but it's useful ;-)
190
         * </p>
191
         */
192
//        public static void initializeVectorialIntervalLegend(
193
//                        AbstractIntervalLegend srcLegend,
194
//                        AbstractIntervalLegend targetLegend) {
195
//                targetLegend.shapeType        = srcLegend.shapeType;
196
//                targetLegend.symbols          = srcLegend.symbols;
197
//                targetLegend.keys             = srcLegend.keys;
198
//                targetLegend.index            = srcLegend.index;
199
//                targetLegend.setClassifyingFieldNames(srcLegend.getClassifyingFieldNames());
200
//                targetLegend.setClassifyingFieldTypes(srcLegend.getClassifyingFieldTypes());
201
////                targetLegend.fieldId          = srcLegend.fieldId;
202
//                targetLegend.defaultSymbol    = srcLegend.defaultSymbol;
203
////                targetLegend.featureStore       = srcLegend.featureStore;
204
//                targetLegend.intervalType     = srcLegend.intervalType;
205
//                targetLegend.useDefaultSymbol = srcLegend.useDefaultSymbol;
206
//        }
207

    
208
}