Statistics
| Revision:

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

History | View | Annotate | Download (5.51 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

    
23
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.impl;
24

    
25
import org.gvsig.fmap.dal.exception.DataException;
26
import org.gvsig.fmap.dal.feature.FeatureStore;
27
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedVectorLegend;
28
import org.gvsig.fmap.mapcontext.rendering.legend.events.LegendClearEvent;
29
import org.gvsig.fmap.mapcontext.rendering.legend.events.SymbolLegendEvent;
30
import org.gvsig.tools.ToolsLocator;
31
import org.gvsig.tools.dynobject.DynClass;
32
import org.gvsig.tools.persistence.PersistenceException;
33
import org.gvsig.tools.persistence.PersistentState;
34

    
35
/**
36
 * Abstract class that implements the interface for legends composed by
37
 * classified symbols.It will have two methods that will be executed depending
38
 * on the action that had been done with the legend (addition of a new symbol or
39
 * clear the legend).
40
 * 
41
 * @author 2008- pepe vidal salvador - jose.vidal.salvador@iver.es
42
 * @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
43
 */
44
public abstract class AbstractClassifiedVectorLegend extends
45
                AbstractVectorialLegend implements IClassifiedVectorLegend {
46

    
47
        public static final String CLASSIFIED_VECTOR_LEGEND_DYNCLASS_NAME =
48
                        "ClassifiedVectorLegend";
49

    
50
        private static final String FIELD_FIELD_NAMES = "fieldNames";
51
        private static final String FIELD_FIELD_TYPES = "fieldTypes";
52

    
53
        private String[] fieldNames;
54
        private int[] fieldTypes;
55

    
56
        /**
57
         * Looks for a change in a classified symbol of a legend. To perform it, the
58
         * Array of LegendListeners is scaned and when the corresponding listener is
59
         * true, the method is invoked and the change will be done.
60
         * 
61
         * @param event
62
         */
63
        public void fireClassifiedSymbolChangeEvent(SymbolLegendEvent event) {
64
                for (int i = 0; i < getListeners().length; i++) {
65
                        getListeners()[i].symbolChanged(event);
66
                }
67
        }
68

    
69
        /**
70
         * Looks for a change in a legend of classified symbols. In this case if the
71
         * specific legend is cleared.
72
         * 
73
         * @param event
74
         */
75
        public void fireLegendClearEvent(LegendClearEvent event) {
76
                for (int i = 0; i < getListeners().length; i++) {
77
                        getListeners()[i].legendCleared(event);
78
                }
79
        }
80

    
81
        public String[] getClassifyingFieldNames() {
82
                return fieldNames;
83
        }
84

    
85
        public void setClassifyingFieldNames(String[] fieldNames) {
86
                this.fieldNames = fieldNames;
87
        }
88

    
89
        public int[] getClassifyingFieldTypes() {
90
                return fieldTypes;
91
        }
92

    
93
        public void setClassifyingFieldTypes(int[] fieldTypes) {
94
                this.fieldTypes = fieldTypes;
95
        }
96

    
97
        public boolean isSuitableForShapeType(int shapeType) {
98
                return getShapeType() == shapeType;
99
        }
100

    
101
        protected String[] getRequiredFeatureAttributeNames(
102
                        FeatureStore featureStore) throws DataException {
103
                String[] requiredFieldNames = null;
104
                String[] classified = getClassifyingFieldNames();
105
                requiredFieldNames = new String[classified.length + 1];
106
                requiredFieldNames[0] =
107
                                featureStore.getDefaultFeatureType()
108
                                                .getDefaultGeometryAttributeName();
109
                for (int i = 1; i < requiredFieldNames.length; i++) {
110
                        requiredFieldNames[i] = classified[i - 1];
111
                }
112

    
113
                return requiredFieldNames;
114
        }
115

    
116
        public Object clone() throws CloneNotSupportedException {
117
                AbstractClassifiedVectorLegend clone =
118
                                (AbstractClassifiedVectorLegend) super.clone();
119

    
120
                // Clone fieldNames
121
                clone.fieldNames = new String[fieldNames.length];
122
                System.arraycopy(fieldNames, 0, clone.fieldNames, 0, fieldNames.length);
123
                // Clone fieldTypes
124
                clone.fieldTypes = new int[fieldTypes.length];
125
                System.arraycopy(fieldTypes, 0, clone.fieldTypes, 0, fieldTypes.length);
126

    
127
                return clone;
128
        }
129

    
130
        public void loadFromState(PersistentState state)
131
                        throws PersistenceException {
132
                // Set parent properties
133
                super.loadFromState(state);
134
                // Set own properties
135
                setClassifyingFieldNames((String[]) state.getArray(FIELD_FIELD_NAMES,
136
                                String.class));
137
                setClassifyingFieldTypes(state.getIntArray(FIELD_FIELD_TYPES));
138
        }
139

    
140
        public void saveToState(PersistentState state) throws PersistenceException {
141
                // Save parent properties
142
                super.saveToState(state);
143
                // Save own properties
144
                state.set(FIELD_FIELD_NAMES, getClassifyingFieldNames());
145
                state.set(FIELD_FIELD_TYPES, getClassifyingFieldTypes());
146
        }
147

    
148
        public static void registerPersistence() {
149
                // Add the DynClass definition.
150
                DynClass dynClass =
151
                                ToolsLocator.getDynObjectManager().add(
152
                                                CLASSIFIED_VECTOR_LEGEND_DYNCLASS_NAME);
153

    
154
                // Extend the Vector Legend base definition
155
                dynClass.extend(VECTORIAL_LEGEND_DYNCLASS_NAME);
156

    
157
                // Field names
158
                dynClass.addDynFieldList(FIELD_FIELD_NAMES);
159
                // Field types
160
                dynClass.addDynFieldList(FIELD_FIELD_TYPES);
161
        }
162

    
163
}