Statistics
| Revision:

svn-gvsig-desktop / tags / v2_0_0_Build_2021 / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / legend / styling / DefaultLabelingMethod.java @ 34111

History | View | Annotate | Download (5.71 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: DefaultLabelingMethod.java 10815 2007-03-20 16:16:20Z jaume $
45
* $Log$
46
* Revision 1.1  2007-03-20 16:16:20  jaume
47
* refactored to use ISymbol instead of FSymbol
48
*
49
* Revision 1.2  2007/03/09 08:33:43  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1.2.2  2007/02/01 11:42:47  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.1.2.1  2007/01/30 18:10:45  jaume
56
* start commiting labeling stuff
57
*
58
*
59
*/
60
package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling;
61

    
62
import org.gvsig.fmap.dal.exception.DataException;
63
import org.gvsig.fmap.dal.feature.FeatureQuery;
64
import org.gvsig.fmap.dal.feature.FeatureSet;
65
import org.gvsig.fmap.dal.feature.FeatureStore;
66
import org.gvsig.fmap.mapcontext.ViewPort;
67
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
68
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass;
69
import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod;
70
import org.gvsig.tools.ToolsLocator;
71
import org.gvsig.tools.dynobject.DynStruct;
72
import org.gvsig.tools.persistence.PersistenceManager;
73
import org.gvsig.tools.persistence.PersistentState;
74
import org.gvsig.tools.persistence.exception.PersistenceException;
75
import org.gvsig.tools.util.Callable;
76

    
77
public class DefaultLabelingMethod implements ILabelingMethod {
78

    
79

    
80
        private static final String FIELD_DEFAULT_LABEL = "defaultLabel";
81
        private static final String DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME =
82
                        "DefaultLabelingMethod";
83
        private ILabelClass defaultLabel;
84

    
85
        /**
86
         * Empty constructor for persistence.
87
         */
88
        public DefaultLabelingMethod() {
89
                // Nothing to do
90
        }
91

    
92
        public DefaultLabelingMethod(LabelClass defaultLabel) {
93
                this();
94
                this.defaultLabel = defaultLabel;
95
        }
96

    
97

    
98
        public void addLabelClass(ILabelClass lbl) {
99
                defaultLabel = lbl;
100
        }
101

    
102

    
103
        public void deleteLabelClass(ILabelClass lbl) {
104
                // does nothing
105
        }
106

    
107
        public String getClassName() {
108
                return getClass().getName();
109
        }
110

    
111
        public boolean allowsMultipleClass() {
112
                return false;
113
        }
114

    
115
        public void renameLabelClass(ILabelClass lbl, String newName) {
116
                // does nothing
117
        }
118

    
119

    
120
        public FeatureSet getFeatureIteratorByLabelClass(FLyrVect layer, ILabelClass lc, ViewPort viewPort, String[] usedFields)
121
        throws DataException {
122
                FeatureStore featureStore=layer.getFeatureStore();
123
                FeatureQuery featureQuery=featureStore.createFeatureQuery();
124
                featureQuery.setAttributeNames(usedFields);
125
                return (FeatureSet)featureStore.getFeatureSet(featureQuery);
126
//                layer.getSource().getFeatureIterator(
127
//                                        viewPort.getAdjustedExtent(), usedFields,
128
//                                        layer.getProjection(), true);
129
        }
130

    
131
        public boolean definesPriorities() {
132
                return false;
133
        }
134

    
135
        public void setDefinesPriorities(boolean flag) {
136
                /* nothing, since only one label class is suported */
137
        }
138
        public ILabelClass getLabelClassByName(String labelName) {
139
                return defaultLabel;
140
        }
141

    
142
        public void clearAllClasses() {
143
                defaultLabel = null;
144
        }
145

    
146
        public ILabelClass[] getLabelClasses() {
147
                return defaultLabel == null ? new ILabelClass[0] : new ILabelClass[] { defaultLabel };
148
        }
149

    
150
        public ILabelingMethod cloneMethod() {
151
//XMLENTITY-UPDATED        
152
//                if (defaultLabel !=null)
153
//                        try {
154
//                                return new DefaultLabelingMethod(LabelingFactory.createLabelClassFromXML(defaultLabel.getXMLEntity()));
155
//                        } catch (XMLException e) {
156
//                                // TODO Auto-generated catch block
157
//                                e.printStackTrace();
158
//                        }
159
                return new DefaultLabelingMethod();
160
        }
161

    
162
        /* (non-Javadoc)
163
         * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
164
         */
165
        public void loadFromState(PersistentState state)
166
                        throws PersistenceException {
167
                defaultLabel = (ILabelClass) state.get(FIELD_DEFAULT_LABEL);
168
        }
169

    
170
        /* (non-Javadoc)
171
         * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
172
         */
173
        public void saveToState(PersistentState state) throws PersistenceException {
174
                state.set(FIELD_DEFAULT_LABEL, defaultLabel);
175
        }
176
        
177
        public static class RegisterPersistence implements Callable {
178

    
179
                public Object call() throws Exception {
180
                        PersistenceManager manager = ToolsLocator.getPersistenceManager();
181
                        if( manager.getDefinition(DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME)==null ) {
182
                                DynStruct definition = manager.addDefinition(
183
                                                DefaultLabelingMethod.class,
184
                                                DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME,
185
                                                DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
186
                                                null, 
187
                                                null
188
                                );
189
                                
190
                                definition.addDynFieldObject(FIELD_DEFAULT_LABEL).setMandatory(false).setClassOfValue(ILabelClass.class);
191
                        }
192
                        return Boolean.TRUE;
193
                }
194
                
195
        }
196

    
197

    
198
        
199
}