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