Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.lib / org.gvsig.symbology.lib.impl / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / VectorialIntervalLegend.java @ 40560

History | View | Annotate | Download (6.32 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl;
25

    
26
import java.awt.Color;
27

    
28
import org.gvsig.fmap.mapcontext.MapContextLocator;
29
import org.gvsig.fmap.mapcontext.MapContextManager;
30
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval;
31
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DynStruct;
34
import org.gvsig.tools.persistence.PersistenceManager;
35
import org.gvsig.tools.persistence.PersistentState;
36
import org.gvsig.tools.persistence.exception.PersistenceException;
37
import org.gvsig.tools.util.Callable;
38

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

    
56
        public static final String VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME =
57
                        "VectorialIntervalLegend";
58

    
59
        private static final String FIELD_START_COLOR = "startColor";
60
        private static final String FIELD_END_COLOR = "endColor";
61
        
62
        private int shapeType;
63
    private Color startColor = Color.red;
64
    private Color endColor = Color.blue;
65

    
66
    /**
67
     * Constructor method
68
     */
69
    public VectorialIntervalLegend() {
70
            super();
71
    }
72

    
73
    /**
74
     * Constructor method
75
     *
76
     * @param type type of the shape.
77
     */
78
    public VectorialIntervalLegend(int type) {
79
            super();
80
            setShapeType(type);
81
    }
82

    
83
    /**
84
         * Returns the final color
85
         * @return Color  final color.
86
         * @uml.property  name="endColor"
87
         */
88
    public Color getEndColor() {
89
        return endColor;
90
    }
91

    
92
    /**
93
         * Inserts the final color.
94
         * @param endColor final color.
95
         * @uml.property  name="endColor"
96
         */
97
    public void setEndColor(Color endColor) {
98
        this.endColor = endColor;
99
    }
100

    
101
    /**
102
         * Returns the initial color.
103
         * @return  Color initial color.
104
         * @uml.property  name="startColor"
105
         */
106
    public Color getStartColor() {
107
        return startColor;
108
    }
109

    
110
    /**
111
         * Inserts the initial color
112
         * @param startColor initial color.
113
         * @uml.property  name="startColor"
114
         */
115
    public void setStartColor(Color startColor) {
116
        this.startColor = startColor;
117
    }
118

    
119
        public int getShapeType() {
120
                return shapeType;
121
        }
122

    
123
        public void setShapeType(int shapeType) {
124
                if (this.shapeType != shapeType) {
125
                        if(defaultSymbol==null || defaultSymbol.getSymbolType()!=shapeType){
126
                                setDefaultSymbol(getSymbolManager().createSymbol(shapeType));
127
                        }
128
                        this.shapeType = shapeType;
129
                }
130
        }
131

    
132

    
133
        public String getClassName() {
134
                return getClass().getName();
135
        }
136

    
137
        public Object clone() throws CloneNotSupportedException {
138
                VectorialIntervalLegend clone = (VectorialIntervalLegend) super.clone();
139

    
140
                // Nothing to clone, as Color objects are inmutable, keep the original
141
                // references.
142

    
143
                return clone;
144
        }
145

    
146
        public IInterval createInterval(double min, double max) {
147
                return new FInterval(min, max);
148
        }
149

    
150
        public void loadFromState(PersistentState state)
151
                        throws PersistenceException {
152
                // Set parent properties
153
                super.loadFromState(state);
154
                // Set own properties
155
                setStartColor((Color) state.get(FIELD_START_COLOR));
156
                setEndColor((Color) state.get(FIELD_END_COLOR));
157
        }
158

    
159
        public void saveToState(PersistentState state) throws PersistenceException {
160
                // Save parent properties
161
                super.saveToState(state);
162
                // Save own properties
163
                state.set(FIELD_START_COLOR, getStartColor());
164
                state.set(FIELD_END_COLOR, getEndColor());
165
        }
166

    
167
        public static class RegisterPersistence implements Callable {
168

    
169
                public Object call() throws Exception {
170
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
171
                        if( manager.getDefinition(VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) {
172
                                DynStruct definition = manager.addDefinition(
173
                                                VectorialIntervalLegend.class,
174
                                                VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME,
175
                                                VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
176
                                                null, 
177
                                                null
178
                                );
179

    
180
                                // Extend the Interval Legend base definition
181
                                definition.extend(manager.getDefinition(INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME));
182

    
183
                                // Start color
184
                                definition.addDynFieldObject(FIELD_START_COLOR)
185
                                                .setClassOfValue(Color.class)
186
                                                .setMandatory(true)
187
                                                .setDescription("Start color");
188
                                // End color
189
                                definition.addDynFieldObject(FIELD_END_COLOR)
190
                                                .setClassOfValue(Color.class)
191
                                                .setMandatory(true)
192
                                                .setDescription("End color");
193
                        }
194
                        return Boolean.TRUE;
195
                }
196
                
197
        }
198

    
199
        public static class RegisterLegend implements Callable {
200

    
201
                public Object call() throws Exception {
202
                MapContextManager manager = MapContextLocator.getMapContextManager();
203

    
204
                manager.registerLegend(IVectorialIntervalLegend.LEGEND_NAME,
205
                    VectorialIntervalLegend.class);
206

    
207
                        return Boolean.TRUE;
208
                }
209
                
210
        }
211

    
212

    
213
}