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 @ 43020
History | View | Annotate | Download (6.1 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 | 41421 | jjdelcerro | |
25 | 40435 | jjdelcerro | package org.gvsig.symbology.fmap.mapcontext.rendering.legend.styling; |
26 | |||
27 | import org.gvsig.fmap.dal.exception.DataException; |
||
28 | import org.gvsig.fmap.dal.feature.FeatureQuery; |
||
29 | import org.gvsig.fmap.dal.feature.FeatureSet; |
||
30 | import org.gvsig.fmap.dal.feature.FeatureStore; |
||
31 | 40676 | jldominguez | import org.gvsig.fmap.dal.feature.FeatureType; |
32 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.ViewPort; |
33 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
34 | 40676 | jldominguez | import org.gvsig.fmap.mapcontext.layers.vectorial.IntersectsEnvelopeEvaluator; |
35 | 43020 | jjdelcerro | import org.gvsig.fmap.mapcontext.layers.vectorial.SpatialEvaluatorsFactory; |
36 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelClass; |
37 | import org.gvsig.fmap.mapcontext.rendering.legend.styling.ILabelingMethod; |
||
38 | import org.gvsig.tools.ToolsLocator; |
||
39 | import org.gvsig.tools.dynobject.DynStruct; |
||
40 | 41196 | jldominguez | import org.gvsig.tools.evaluator.AndEvaluator; |
41 | 40676 | jldominguez | import org.gvsig.tools.evaluator.Evaluator; |
42 | 40435 | jjdelcerro | import org.gvsig.tools.persistence.PersistenceManager; |
43 | import org.gvsig.tools.persistence.PersistentState; |
||
44 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
45 | import org.gvsig.tools.util.Callable; |
||
46 | |||
47 | public class DefaultLabelingMethod implements ILabelingMethod { |
||
48 | |||
49 | |||
50 | private static final String FIELD_DEFAULT_LABEL = "defaultLabel"; |
||
51 | private static final String DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME = |
||
52 | "DefaultLabelingMethod";
|
||
53 | private ILabelClass defaultLabel;
|
||
54 | |||
55 | /**
|
||
56 | * Empty constructor for persistence.
|
||
57 | */
|
||
58 | public DefaultLabelingMethod() {
|
||
59 | // Nothing to do
|
||
60 | } |
||
61 | |||
62 | public DefaultLabelingMethod(LabelClass defaultLabel) {
|
||
63 | this();
|
||
64 | this.defaultLabel = defaultLabel;
|
||
65 | } |
||
66 | |||
67 | |||
68 | public void addLabelClass(ILabelClass lbl) { |
||
69 | defaultLabel = lbl; |
||
70 | } |
||
71 | |||
72 | |||
73 | public void deleteLabelClass(ILabelClass lbl) { |
||
74 | // does nothing
|
||
75 | } |
||
76 | |||
77 | public String getClassName() { |
||
78 | return getClass().getName();
|
||
79 | } |
||
80 | |||
81 | public boolean allowsMultipleClass() { |
||
82 | return false; |
||
83 | } |
||
84 | |||
85 | public void renameLabelClass(ILabelClass lbl, String newName) { |
||
86 | // does nothing
|
||
87 | } |
||
88 | |||
89 | |||
90 | 40703 | jldominguez | public FeatureSet getFeatureIteratorByLabelClass(
|
91 | FLyrVect layer, |
||
92 | ILabelClass lc, |
||
93 | ViewPort viewPort, |
||
94 | String[] usedFields) throws DataException { |
||
95 | |||
96 | 40435 | jjdelcerro | FeatureStore featureStore=layer.getFeatureStore(); |
97 | 40703 | jldominguez | |
98 | if (viewPort == null && usedFields == null) { |
||
99 | // nothing more to do
|
||
100 | return featureStore.getFeatureSet();
|
||
101 | } |
||
102 | 40435 | jjdelcerro | FeatureQuery featureQuery=featureStore.createFeatureQuery(); |
103 | 40703 | jldominguez | |
104 | if (usedFields != null) { |
||
105 | featureQuery.setAttributeNames(usedFields); |
||
106 | } |
||
107 | 40676 | jldominguez | |
108 | 41196 | jldominguez | Evaluator eva = null;
|
109 | |||
110 | 40676 | jldominguez | if (viewPort != null) { |
111 | 43020 | jjdelcerro | eva = SpatialEvaluatorsFactory.getInstance().intersects( |
112 | viewPort.getAdjustedEnvelope(), |
||
113 | layer.getProjection(), |
||
114 | featureStore |
||
115 | ); |
||
116 | 40676 | jldominguez | } |
117 | 41196 | jldominguez | |
118 | if (lc.getSQLQuery() != null && lc.getSQLQuery().trim().length() > 0) { |
||
119 | Evaluator vp_eva = eva; |
||
120 | AndEvaluator and_eva = new AndEvaluator(vp_eva);
|
||
121 | |||
122 | String sql_str = lc.getSQLQuery();
|
||
123 | /*
|
||
124 | * SQL filter was validated in the dialog
|
||
125 | */
|
||
126 | Evaluator sql_eval = EvaluatorCreator.getEvaluator(sql_str); |
||
127 | and_eva.addEvaluator(sql_eval); |
||
128 | eva = and_eva; |
||
129 | } |
||
130 | 40676 | jldominguez | |
131 | 41196 | jldominguez | featureQuery.setFilter(eva); |
132 | 40435 | jjdelcerro | return (FeatureSet)featureStore.getFeatureSet(featureQuery);
|
133 | } |
||
134 | |||
135 | public boolean definesPriorities() { |
||
136 | return false; |
||
137 | } |
||
138 | |||
139 | public void setDefinesPriorities(boolean flag) { |
||
140 | /* nothing, since only one label class is suported */
|
||
141 | } |
||
142 | public ILabelClass getLabelClassByName(String labelName) { |
||
143 | return defaultLabel;
|
||
144 | } |
||
145 | |||
146 | public void clearAllClasses() { |
||
147 | defaultLabel = null;
|
||
148 | } |
||
149 | |||
150 | public ILabelClass[] getLabelClasses() { |
||
151 | return defaultLabel == null ? new ILabelClass[0] : new ILabelClass[] { defaultLabel }; |
||
152 | } |
||
153 | |||
154 | public ILabelingMethod cloneMethod() {
|
||
155 | //XMLENTITY-UPDATED
|
||
156 | // if (defaultLabel !=null)
|
||
157 | // try {
|
||
158 | // return new DefaultLabelingMethod(LabelingFactory.createLabelClassFromXML(defaultLabel.getXMLEntity()));
|
||
159 | // } catch (XMLException e) {
|
||
160 | // // TODO Auto-generated catch block
|
||
161 | // e.printStackTrace();
|
||
162 | // }
|
||
163 | return new DefaultLabelingMethod(); |
||
164 | } |
||
165 | |||
166 | /* (non-Javadoc)
|
||
167 | * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
||
168 | */
|
||
169 | public void loadFromState(PersistentState state) |
||
170 | throws PersistenceException {
|
||
171 | defaultLabel = (ILabelClass) state.get(FIELD_DEFAULT_LABEL); |
||
172 | } |
||
173 | |||
174 | /* (non-Javadoc)
|
||
175 | * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
|
||
176 | */
|
||
177 | public void saveToState(PersistentState state) throws PersistenceException { |
||
178 | state.set(FIELD_DEFAULT_LABEL, defaultLabel); |
||
179 | } |
||
180 | |||
181 | public static class RegisterPersistence implements Callable { |
||
182 | |||
183 | public Object call() throws Exception { |
||
184 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
185 | if( manager.getDefinition(DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME)==null ) { |
||
186 | DynStruct definition = manager.addDefinition( |
||
187 | DefaultLabelingMethod.class, |
||
188 | DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME, |
||
189 | DEFAULT_LABELING_METHOD_PERSISTENCE_DEFINITION_NAME+" Persistence definition",
|
||
190 | null,
|
||
191 | null
|
||
192 | ); |
||
193 | |||
194 | definition.addDynFieldObject(FIELD_DEFAULT_LABEL).setMandatory(false).setClassOfValue(ILabelClass.class);
|
||
195 | } |
||
196 | return Boolean.TRUE; |
||
197 | } |
||
198 | |||
199 | } |
||
200 | |||
201 | |||
202 | |||
203 | } |