svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.labeling.app / org.gvsig.labeling.app.mainplugin / src / main / java / org / gvsig / labeling / label / OnSelectionLabeled.java @ 43510
History | View | Annotate | Download (5.27 KB)
1 | 40911 | jldominguez | /* 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: OnSelectionLabeled.java 10815 2007-03-20 16:16:20Z jaume $
|
||
45 | * $Log$
|
||
46 | * Revision 1.3 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.labeling.label; |
||
61 | |||
62 | import org.gvsig.fmap.dal.exception.DataException; |
||
63 | import org.gvsig.fmap.dal.feature.FeatureSelection; |
||
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.labeling.lang.LabelClassUtils; |
||
71 | import org.gvsig.tools.ToolsLocator; |
||
72 | import org.gvsig.tools.dynobject.DynStruct; |
||
73 | import org.gvsig.tools.persistence.PersistenceManager; |
||
74 | import org.gvsig.tools.persistence.PersistentState; |
||
75 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
76 | |||
77 | /**
|
||
78 | *
|
||
79 | * OnSelectionLabeled.java
|
||
80 | *
|
||
81 | *
|
||
82 | *
|
||
83 | *
|
||
84 | */
|
||
85 | public class OnSelectionLabeled implements ILabelingMethod { |
||
86 | |||
87 | private static final String FIELD_DEFAULT_LABEL = "defaultLabel"; |
||
88 | private static final String ONSELECTION_LABELING_METHOD_PERSISTENCE_NAME = |
||
89 | "ONSELECTION_LABELING_METHOD_PERSISTENCE_NAME";
|
||
90 | private ILabelClass defaultLabel;
|
||
91 | |||
92 | /**
|
||
93 | * Empty constructor for persistence.
|
||
94 | */
|
||
95 | public OnSelectionLabeled() {
|
||
96 | // Nothing to do
|
||
97 | } |
||
98 | |||
99 | public OnSelectionLabeled(ILabelClass defaultLabel) {
|
||
100 | this.defaultLabel = defaultLabel;
|
||
101 | } |
||
102 | |||
103 | |||
104 | public void addLabelClass(ILabelClass lbl) { |
||
105 | defaultLabel = lbl; |
||
106 | } |
||
107 | |||
108 | |||
109 | public void deleteLabelClass(ILabelClass lbl) { |
||
110 | // does nothing
|
||
111 | } |
||
112 | |||
113 | public boolean allowsMultipleClass() { |
||
114 | return false; |
||
115 | } |
||
116 | |||
117 | public void renameLabelClass(ILabelClass lbl, String newName) { |
||
118 | // does nothing
|
||
119 | } |
||
120 | |||
121 | |||
122 | public FeatureSet getFeatureIteratorByLabelClass(FLyrVect layer, ILabelClass lc, ViewPort viewPort, String[] usedFields) |
||
123 | throws DataException {
|
||
124 | |||
125 | FeatureStore fsto = layer.getFeatureStore(); |
||
126 | FeatureSet fset = (FeatureSelection) fsto.getSelection(); |
||
127 | return fset;
|
||
128 | } |
||
129 | |||
130 | public boolean definesPriorities() { |
||
131 | return false; |
||
132 | } |
||
133 | |||
134 | public void setDefinesPriorities(boolean flag) { |
||
135 | /* nothing, since only one label class is suported */
|
||
136 | } |
||
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 | ILabelClass lbl = (ILabelClass) LabelClassUtils.clone(this.defaultLabel);
|
||
152 | OnSelectionLabeled resp = new OnSelectionLabeled(lbl);
|
||
153 | return resp;
|
||
154 | } |
||
155 | |||
156 | /* (non-Javadoc)
|
||
157 | * @see org.gvsig.tools.persistence.Persistent#loadFromState(org.gvsig.tools.persistence.PersistentState)
|
||
158 | */
|
||
159 | public void loadFromState(PersistentState state) |
||
160 | throws PersistenceException {
|
||
161 | defaultLabel = (ILabelClass) state.get(FIELD_DEFAULT_LABEL); |
||
162 | } |
||
163 | |||
164 | /* (non-Javadoc)
|
||
165 | * @see org.gvsig.tools.persistence.Persistent#saveToState(org.gvsig.tools.persistence.PersistentState)
|
||
166 | */
|
||
167 | public void saveToState(PersistentState state) throws PersistenceException { |
||
168 | state.set(FIELD_DEFAULT_LABEL, defaultLabel); |
||
169 | } |
||
170 | |||
171 | public static void registerPersistent() { |
||
172 | |||
173 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
174 | if( manager.getDefinition(ONSELECTION_LABELING_METHOD_PERSISTENCE_NAME)==null ) { |
||
175 | DynStruct definition = manager.addDefinition( |
||
176 | OnSelectionLabeled.class, |
||
177 | ONSELECTION_LABELING_METHOD_PERSISTENCE_NAME, |
||
178 | ONSELECTION_LABELING_METHOD_PERSISTENCE_NAME+ |
||
179 | " Persistence definition",
|
||
180 | null,
|
||
181 | null
|
||
182 | ); |
||
183 | |||
184 | definition.addDynFieldObject(FIELD_DEFAULT_LABEL).setMandatory(true)
|
||
185 | .setClassOfValue(ILabelClass.class); |
||
186 | } |
||
187 | |||
188 | } |
||
189 | |||
190 | // =================================================
|
||
191 | // =================================================
|
||
192 | |||
193 | } |