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 / styling / DefaultLabelingMethod.java @ 40560
History | View | Annotate | Download (5.45 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: DefaultLabelingMethod.java 10815 2007-03-20 16:16:20Z jaume $
|
||
27 | * $Log$
|
||
28 | * Revision 1.1 2007-03-20 16:16:20 jaume
|
||
29 | * refactored to use ISymbol instead of FSymbol
|
||
30 | *
|
||
31 | * Revision 1.2 2007/03/09 08:33:43 jaume
|
||
32 | * *** empty log message ***
|
||
33 | *
|
||
34 | * Revision 1.1.2.2 2007/02/01 11:42:47 jaume
|
||
35 | * *** empty log message ***
|
||
36 | *
|
||
37 | * Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
||
38 | * start commiting labeling stuff
|
||
39 | *
|
||
40 | *
|
||
41 | */
|
||
42 | package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling; |
||
43 | |||
44 | import org.gvsig.fmap.dal.exception.DataException; |
||
45 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
46 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
47 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
48 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
49 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
50 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
||
51 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
||
52 | import org.gvsig.tools.ToolsLocator; |
||
53 | import org.gvsig.tools.dynobject.DynStruct; |
||
54 | import org.gvsig.tools.persistence.PersistenceManager; |
||
55 | import org.gvsig.tools.persistence.PersistentState; |
||
56 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
57 | import org.gvsig.tools.util.Callable; |
||
58 | |||
59 | public class DefaultLabelingMethod implements ILabelingMethod { |
||
60 | |||
61 | |||
62 | private static final String FIELD_DEFAULT_LABEL = "defaultLabel"; |
||
63 | private static final String DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME = |
||
64 | "DefaultLabelingMethod";
|
||
65 | private ILabelClass defaultLabel;
|
||
66 | |||
67 | /**
|
||
68 | * Empty constructor for persistence.
|
||
69 | */
|
||
70 | public DefaultLabelingMethod() {
|
||
71 | // Nothing to do
|
||
72 | } |
||
73 | |||
74 | public DefaultLabelingMethod(LabelClass defaultLabel) {
|
||
75 | this();
|
||
76 | this.defaultLabel = defaultLabel;
|
||
77 | } |
||
78 | |||
79 | |||
80 | public void addLabelClass(ILabelClass lbl) { |
||
81 | defaultLabel = lbl; |
||
82 | } |
||
83 | |||
84 | |||
85 | public void deleteLabelClass(ILabelClass lbl) { |
||
86 | // does nothing
|
||
87 | } |
||
88 | |||
89 | public String getClassName() { |
||
90 | return getClass().getName();
|
||
91 | } |
||
92 | |||
93 | public boolean allowsMultipleClass() { |
||
94 | return false; |
||
95 | } |
||
96 | |||
97 | public void renameLabelClass(ILabelClass lbl, String newName) { |
||
98 | // does nothing
|
||
99 | } |
||
100 | |||
101 | |||
102 | public FeatureSet getFeatureIteratorByLabelClass(FLyrVect layer, ILabelClass lc, ViewPort viewPort, String[] usedFields) |
||
103 | throws DataException {
|
||
104 | FeatureStore featureStore=layer.getFeatureStore(); |
||
105 | FeatureQuery featureQuery=featureStore.createFeatureQuery(); |
||
106 | featureQuery.setAttributeNames(usedFields); |
||
107 | return (FeatureSet)featureStore.getFeatureSet(featureQuery);
|
||
108 | // layer.getSource().getFeatureIterator(
|
||
109 | // viewPort.getAdjustedExtent(), usedFields,
|
||
110 | // layer.getProjection(), true);
|
||
111 | } |
||
112 | |||
113 | public boolean definesPriorities() { |
||
114 | return false; |
||
115 | } |
||
116 | |||
117 | public void setDefinesPriorities(boolean flag) { |
||
118 | /* nothing, since only one label class is suported */
|
||
119 | } |
||
120 | public ILabelClass getLabelClassByName(String labelName) { |
||
121 | return defaultLabel;
|
||
122 | } |
||
123 | |||
124 | public void clearAllClasses() { |
||
125 | defaultLabel = null;
|
||
126 | } |
||
127 | |||
128 | public ILabelClass[] getLabelClasses() { |
||
129 | return defaultLabel == null ? new ILabelClass[0] : new ILabelClass[] { defaultLabel }; |
||
130 | } |
||
131 | |||
132 | public ILabelingMethod cloneMethod() {
|
||
133 | //XMLENTITY-UPDATED
|
||
134 | // if (defaultLabel !=null)
|
||
135 | // try {
|
||
136 | // return new DefaultLabelingMethod(LabelingFactory.createLabelClassFromXML(defaultLabel.getXMLEntity()));
|
||
137 | // } catch (XMLException e) {
|
||
138 | // // TODO Auto-generated catch block
|
||
139 | // e.printStackTrace();
|
||
140 | // }
|
||
141 | return new DefaultLabelingMethod(); |
||
142 | } |
||
143 | |||
144 | /* (non-Javadoc)
|
||
145 | * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
||
146 | */
|
||
147 | public void loadFromState(PersistentState state) |
||
148 | throws PersistenceException {
|
||
149 | defaultLabel = (ILabelClass) state.get(FIELD_DEFAULT_LABEL); |
||
150 | } |
||
151 | |||
152 | /* (non-Javadoc)
|
||
153 | * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
|
||
154 | */
|
||
155 | public void saveToState(PersistentState state) throws PersistenceException { |
||
156 | state.set(FIELD_DEFAULT_LABEL, defaultLabel); |
||
157 | } |
||
158 | |||
159 | public static class RegisterPersistence implements Callable { |
||
160 | |||
161 | public Object call() throws Exception { |
||
162 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
163 | if( manager.getDefinition(DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME)==null ) { |
||
164 | DynStruct definition = manager.addDefinition( |
||
165 | DefaultLabelingMethod.class, |
||
166 | DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME, |
||
167 | DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
||
168 | null,
|
||
169 | null
|
||
170 | ); |
||
171 | |||
172 | definition.addDynFieldObject(FIELD_DEFAULT_LABEL).setMandatory(false).setClassOfValue(ILabelClass.class);
|
||
173 | } |
||
174 | return Boolean.TRUE; |
||
175 | } |
||
176 | |||
177 | } |
||
178 | |||
179 | |||
180 | |||
181 | } |