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 / AbstractClassifiedVectorLegend.java @ 40560
History | View | Annotate | Download (6.13 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 org.gvsig.fmap.dal.exception.DataException; |
27 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
28 |
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend; |
29 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent; |
30 |
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent; |
31 |
import org.gvsig.tools.ToolsLocator; |
32 |
import org.gvsig.tools.dynobject.DynStruct; |
33 |
import org.gvsig.tools.persistence.PersistenceManager; |
34 |
import org.gvsig.tools.persistence.PersistentState; |
35 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
36 |
import org.gvsig.tools.util.Callable; |
37 |
|
38 |
/**
|
39 |
* Abstract class that implements the interface for legends composed by
|
40 |
* classified symbols.It will have two methods that will be executed depending
|
41 |
* on the action that had been done with the legend (addition of a new symbol or
|
42 |
* clear the legend).
|
43 |
*
|
44 |
* @author 2008- pepe vidal salvador - jose.vidal.salvador@iver.es
|
45 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
46 |
*/
|
47 |
public abstract class AbstractClassifiedVectorLegend extends |
48 |
AbstractVectorialLegend implements IClassifiedVectorLegend {
|
49 |
|
50 |
public static final String CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME = |
51 |
"ClassifiedVectorLegend";
|
52 |
|
53 |
private static final String FIELD_FIELD_NAMES = "fieldNames"; |
54 |
private static final String FIELD_FIELD_TYPES = "fieldTypes"; |
55 |
|
56 |
private String[] fieldNames; |
57 |
private int[] fieldTypes; |
58 |
|
59 |
/**
|
60 |
* Looks for a change in a classified symbol of a legend. To perform it, the
|
61 |
* Array of LegendListeners is scaned and when the corresponding listener is
|
62 |
* true, the method is invoked and the change will be done.
|
63 |
*
|
64 |
* @param event
|
65 |
*/
|
66 |
public void fireClassifiedSymbolChangeEvent(SymbolLegendEvent event) { |
67 |
for (int i = 0; i < getListeners().length; i++) { |
68 |
getListeners()[i].symbolChanged(event); |
69 |
} |
70 |
} |
71 |
|
72 |
/**
|
73 |
* Looks for a change in a legend of classified symbols. In this case if the
|
74 |
* specific legend is cleared.
|
75 |
*
|
76 |
* @param event
|
77 |
*/
|
78 |
public void fireLegendClearEvent(LegendClearEvent event) { |
79 |
for (int i = 0; i < getListeners().length; i++) { |
80 |
getListeners()[i].legendCleared(event); |
81 |
} |
82 |
} |
83 |
|
84 |
public String[] getClassifyingFieldNames() { |
85 |
return fieldNames;
|
86 |
} |
87 |
|
88 |
public void setClassifyingFieldNames(String[] fieldNames) { |
89 |
this.fieldNames = fieldNames;
|
90 |
} |
91 |
|
92 |
public int[] getClassifyingFieldTypes() { |
93 |
return fieldTypes;
|
94 |
} |
95 |
|
96 |
public void setClassifyingFieldTypes(int[] fieldTypes) { |
97 |
this.fieldTypes = fieldTypes;
|
98 |
} |
99 |
|
100 |
public boolean isSuitableForShapeType(int shapeType) { |
101 |
return getShapeType() == shapeType;
|
102 |
} |
103 |
|
104 |
protected String[] getRequiredFeatureAttributeNames( |
105 |
FeatureStore featureStore) throws DataException {
|
106 |
String[] requiredFieldNames = null; |
107 |
String[] classified = getClassifyingFieldNames(); |
108 |
requiredFieldNames = new String[classified.length + 1]; |
109 |
requiredFieldNames[0] =
|
110 |
featureStore.getDefaultFeatureType() |
111 |
.getDefaultGeometryAttributeName(); |
112 |
for (int i = 1; i < requiredFieldNames.length; i++) { |
113 |
requiredFieldNames[i] = classified[i - 1];
|
114 |
} |
115 |
|
116 |
return requiredFieldNames;
|
117 |
} |
118 |
|
119 |
public Object clone() throws CloneNotSupportedException { |
120 |
AbstractClassifiedVectorLegend clone = |
121 |
(AbstractClassifiedVectorLegend) super.clone();
|
122 |
|
123 |
// Clone fieldNames
|
124 |
clone.fieldNames = new String[fieldNames.length]; |
125 |
System.arraycopy(fieldNames, 0, clone.fieldNames, 0, fieldNames.length); |
126 |
// Clone fieldTypes
|
127 |
clone.fieldTypes = new int[fieldTypes.length]; |
128 |
System.arraycopy(fieldTypes, 0, clone.fieldTypes, 0, fieldTypes.length); |
129 |
|
130 |
return clone;
|
131 |
} |
132 |
|
133 |
public void loadFromState(PersistentState state) |
134 |
throws PersistenceException {
|
135 |
// Set parent properties
|
136 |
super.loadFromState(state);
|
137 |
// Set own properties
|
138 |
this.fieldNames = state.getStringArray(FIELD_FIELD_NAMES);
|
139 |
this.fieldTypes = state.getIntArray(FIELD_FIELD_TYPES);
|
140 |
} |
141 |
|
142 |
public void saveToState(PersistentState state) throws PersistenceException { |
143 |
// Save parent properties
|
144 |
super.saveToState(state);
|
145 |
// Save own properties
|
146 |
state.set(FIELD_FIELD_NAMES, this.fieldNames);
|
147 |
state.set(FIELD_FIELD_TYPES, this.fieldTypes);
|
148 |
} |
149 |
|
150 |
public static class RegisterPersistence implements Callable { |
151 |
|
152 |
public Object call() throws Exception { |
153 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
154 |
if( manager.getDefinition(CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME)==null ) { |
155 |
DynStruct definition = manager.addDefinition( |
156 |
AbstractClassifiedVectorLegend.class, |
157 |
CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME, |
158 |
CLASSIFIED_VECTOR_LEGEND_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
159 |
null,
|
160 |
null
|
161 |
); |
162 |
// Extend the Vectorial Legend base definition
|
163 |
definition.extend(manager.getDefinition(VECTORIAL_LEGEND_PERSISTENCE_DEFINITION_NAME)); |
164 |
|
165 |
// Field names
|
166 |
definition.addDynFieldArray(FIELD_FIELD_NAMES) |
167 |
.setClassOfItems(String.class);
|
168 |
// Field types
|
169 |
definition.addDynFieldArray(FIELD_FIELD_TYPES) |
170 |
.setClassOfItems(int.class);
|
171 |
} |
172 |
return Boolean.TRUE; |
173 |
} |
174 |
|
175 |
} |
176 |
|
177 |
} |