svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / impl / VectorialIntervalLegend.java @ 33652
History | View | Annotate | Download (6.2 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.MapContextLocator; |
27 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
28 |
import org.gvsig.fmap.mapcontext.rendering.legend.IInterval; |
29 |
import org.gvsig.fmap.mapcontext.rendering.legend.IVectorialIntervalLegend; |
30 |
import org.gvsig.tools.ToolsLocator; |
31 |
import org.gvsig.tools.dynobject.DynStruct; |
32 |
import org.gvsig.tools.persistence.PersistenceManager; |
33 |
import org.gvsig.tools.persistence.PersistentState; |
34 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
35 |
import org.gvsig.tools.util.Callable; |
36 |
|
37 |
/**
|
38 |
* <p>
|
39 |
* VectorialIntervalLegend (which should be better called GraduatedColorLegend)
|
40 |
* is a legend that allows to classify ranges of values using a color gradient
|
41 |
* based on a value.<b>
|
42 |
* </p>
|
43 |
* <p>
|
44 |
* The color gradient will be calculated according the starting color, the
|
45 |
* ending color and the amount of intervals.
|
46 |
* </p>
|
47 |
*
|
48 |
* @author Vicente Caballero Navarro
|
49 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
50 |
*/
|
51 |
public class VectorialIntervalLegend extends AbstractIntervalLegend { |
52 |
// final static private Logger LOG = LoggerFactory.getLogger(VectorialIntervalLegend.class);
|
53 |
|
54 |
public static final String VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME = |
55 |
"VectorialIntervalLegend";
|
56 |
|
57 |
private static final String FIELD_START_COLOR = "startColor"; |
58 |
private static final String FIELD_END_COLOR = "endColor"; |
59 |
|
60 |
private int shapeType; |
61 |
private Color startColor = Color.red; |
62 |
private Color endColor = Color.blue; |
63 |
|
64 |
/**
|
65 |
* Constructor method
|
66 |
*/
|
67 |
public VectorialIntervalLegend() {
|
68 |
super();
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Constructor method
|
73 |
*
|
74 |
* @param type type of the shape.
|
75 |
*/
|
76 |
public VectorialIntervalLegend(int type) { |
77 |
super();
|
78 |
setShapeType(type); |
79 |
} |
80 |
|
81 |
/**
|
82 |
* Returns the final color
|
83 |
* @return Color final color.
|
84 |
* @uml.property name="endColor"
|
85 |
*/
|
86 |
public Color getEndColor() { |
87 |
return endColor;
|
88 |
} |
89 |
|
90 |
/**
|
91 |
* Inserts the final color.
|
92 |
* @param endColor final color.
|
93 |
* @uml.property name="endColor"
|
94 |
*/
|
95 |
public void setEndColor(Color endColor) { |
96 |
this.endColor = endColor;
|
97 |
} |
98 |
|
99 |
/**
|
100 |
* Returns the initial color.
|
101 |
* @return Color initial color.
|
102 |
* @uml.property name="startColor"
|
103 |
*/
|
104 |
public Color getStartColor() { |
105 |
return startColor;
|
106 |
} |
107 |
|
108 |
/**
|
109 |
* Inserts the initial color
|
110 |
* @param startColor initial color.
|
111 |
* @uml.property name="startColor"
|
112 |
*/
|
113 |
public void setStartColor(Color startColor) { |
114 |
this.startColor = startColor;
|
115 |
} |
116 |
|
117 |
public int getShapeType() { |
118 |
return shapeType;
|
119 |
} |
120 |
|
121 |
public void setShapeType(int shapeType) { |
122 |
if (this.shapeType != shapeType) { |
123 |
setDefaultSymbol(getSymbolManager().createSymbol(shapeType)); |
124 |
this.shapeType = shapeType;
|
125 |
} |
126 |
} |
127 |
|
128 |
|
129 |
public String getClassName() { |
130 |
return getClass().getName();
|
131 |
} |
132 |
|
133 |
public Object clone() throws CloneNotSupportedException { |
134 |
VectorialIntervalLegend clone = (VectorialIntervalLegend) super.clone();
|
135 |
|
136 |
// Nothing to clone, as Color objects are inmutable, keep the original
|
137 |
// references.
|
138 |
|
139 |
return clone;
|
140 |
} |
141 |
|
142 |
public IInterval createInterval(double min, double max) { |
143 |
return new FInterval(min, max); |
144 |
} |
145 |
|
146 |
public void loadFromState(PersistentState state) |
147 |
throws PersistenceException {
|
148 |
// Set parent properties
|
149 |
super.loadFromState(state);
|
150 |
// Set own properties
|
151 |
setStartColor((Color) state.get(FIELD_START_COLOR));
|
152 |
setEndColor((Color) state.get(FIELD_END_COLOR));
|
153 |
} |
154 |
|
155 |
public void saveToState(PersistentState state) throws PersistenceException { |
156 |
// Save parent properties
|
157 |
super.saveToState(state);
|
158 |
// Save own properties
|
159 |
state.set(FIELD_START_COLOR, getStartColor()); |
160 |
state.set(FIELD_END_COLOR, getEndColor()); |
161 |
} |
162 |
|
163 |
public static class RegisterPersistence implements Callable { |
164 |
|
165 |
public Object call() throws Exception { |
166 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
167 |
if( manager.getDefinition(VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
168 |
DynStruct definition = manager.addDefinition( |
169 |
VectorialIntervalLegend.class, |
170 |
VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME, |
171 |
VECTORIAL_INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
172 |
null,
|
173 |
null
|
174 |
); |
175 |
|
176 |
// Extend the Interval Legend base definition
|
177 |
definition.extend(manager.getDefinition(INTERVAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
178 |
|
179 |
// Start color
|
180 |
definition.addDynFieldObject(FIELD_START_COLOR) |
181 |
.setClassOfValue(Color.class)
|
182 |
.setMandatory(true)
|
183 |
.setDescription("Start color");
|
184 |
// End color
|
185 |
definition.addDynFieldObject(FIELD_END_COLOR) |
186 |
.setClassOfValue(Color.class)
|
187 |
.setMandatory(true)
|
188 |
.setDescription("End color");
|
189 |
} |
190 |
return Boolean.TRUE; |
191 |
} |
192 |
|
193 |
} |
194 |
|
195 |
public static class RegisterLegend implements Callable { |
196 |
|
197 |
public Object call() throws Exception { |
198 |
MapContextManager manager = MapContextLocator.getMapContextManager(); |
199 |
|
200 |
manager.registerLegend(IVectorialIntervalLegend.LEGEND_NAME, |
201 |
VectorialIntervalLegend.class); |
202 |
|
203 |
return Boolean.TRUE; |
204 |
} |
205 |
|
206 |
} |
207 |
|
208 |
|
209 |
} |