root / trunk / extensions / extSymbology / src / org / gvsig / symbology / fmap / labeling / FeatureDependentLabeled.java @ 23117
History | View | Annotate | Download (5.08 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: FeatureDependentLabeled.java 10671 2007-03-09 08:33:43Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-03-09 08:33:43 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.1.2.2 2007/02/01 11:42:47 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.1 2007/01/30 18:10:45 jaume
|
53 |
* start commiting labeling stuff
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package org.gvsig.symbology.fmap.labeling; |
58 |
|
59 |
|
60 |
import java.util.ArrayList; |
61 |
|
62 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
63 |
import com.iver.cit.gvsig.fmap.ViewPort; |
64 |
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
66 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.ILabelingMethod; |
67 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelClass; |
68 |
import com.iver.cit.gvsig.fmap.rendering.styling.labeling.LabelingFactory; |
69 |
import com.iver.utiles.XMLEntity; |
70 |
|
71 |
public class FeatureDependentLabeled implements ILabelingMethod { |
72 |
private boolean flagDefinesPriorities; |
73 |
private ArrayList<LabelClass> classes = new ArrayList<LabelClass>(); |
74 |
|
75 |
public void addLabelClass(LabelClass lbl) throws IllegalArgumentException{ |
76 |
if (getLabelClassByName(lbl.getName()) !=null) { |
77 |
throw new IllegalArgumentException("A class with the same name already exists!"); |
78 |
} |
79 |
classes.add(lbl); |
80 |
} |
81 |
|
82 |
public void deleteLabelClass(LabelClass lbl) { |
83 |
classes.remove(lbl); |
84 |
} |
85 |
|
86 |
public String getClassName() { |
87 |
return getClass().getName();
|
88 |
} |
89 |
|
90 |
public XMLEntity getXMLEntity() {
|
91 |
XMLEntity xml = new XMLEntity();
|
92 |
xml.putProperty("className", getClassName());
|
93 |
xml.putProperty("definesPriorities", definesPriorities());
|
94 |
|
95 |
|
96 |
|
97 |
LabelClass[] labels = getLabelClasses();
|
98 |
if (labels!=null) { |
99 |
XMLEntity xmlLabels = new XMLEntity();
|
100 |
xmlLabels.putProperty("id", "LabelClasses"); |
101 |
for (int i = 0; i < labels.length; i++) { |
102 |
xmlLabels.addChild(labels[i].getXMLEntity()); |
103 |
} |
104 |
xml.addChild(xmlLabels); |
105 |
} |
106 |
return xml;
|
107 |
} |
108 |
|
109 |
public LabelClass[] getLabelClasses() { |
110 |
return classes.toArray(new LabelClass[0]); |
111 |
} |
112 |
|
113 |
public void setXMLEntity(XMLEntity xml) { |
114 |
if (xml.contains("definesPriorities")) |
115 |
setDefinesPriorities(xml.getBooleanProperty("definesPriorities"));
|
116 |
|
117 |
XMLEntity aux = xml.firstChild("id", "defaultLabelClass"); |
118 |
|
119 |
// if (aux!=null)
|
120 |
// defaultLabel = LabelingFactory.createLabelClassFromXML(aux);
|
121 |
|
122 |
aux = xml.firstChild("id", "LabelClasses"); |
123 |
if (aux!=null) { |
124 |
for (int i = 0; i < aux.getChildrenCount(); i++) { |
125 |
addLabelClass(LabelingFactory. |
126 |
createLabelClassFromXML(aux.getChild(i))); |
127 |
} |
128 |
} |
129 |
} |
130 |
|
131 |
public boolean allowsMultipleClass() { |
132 |
return true; |
133 |
} |
134 |
|
135 |
public void renameLabelClass(LabelClass lbl, String newName) { |
136 |
LabelClass label = (LabelClass) classes.get(classes.indexOf(lbl)); |
137 |
label.setName(newName); |
138 |
} |
139 |
|
140 |
public IFeatureIterator getFeatureIteratorByLabelClass(FLyrVect layer, LabelClass lc, ViewPort viewPort, String[] usedFields) |
141 |
throws ReadDriverException {
|
142 |
String sqlFields = ""; |
143 |
for (int i = 0; i < usedFields.length; i++) { |
144 |
sqlFields += usedFields[i]; |
145 |
if (i < usedFields.length -1) sqlFields += ", "; |
146 |
} |
147 |
String sql = "select "+sqlFields+" from "+layer.getRecordset().getName()+" where "+lc.getSQLQuery()+";"; |
148 |
return layer.getSource().getFeatureIterator(sql, layer.getProjection());
|
149 |
} |
150 |
|
151 |
public boolean definesPriorities() { |
152 |
return flagDefinesPriorities;
|
153 |
} |
154 |
|
155 |
public void setDefinesPriorities(boolean flag) { |
156 |
if (flag == false) { |
157 |
LabelClass[] lcs = getLabelClasses();
|
158 |
for (int i = 0; i < lcs.length; i++) { |
159 |
lcs[i].setPriority(0);
|
160 |
} |
161 |
} |
162 |
flagDefinesPriorities = flag; |
163 |
} |
164 |
|
165 |
public void clearAllClasses() { |
166 |
classes.clear(); |
167 |
} |
168 |
|
169 |
public LabelClass getLabelClassByName(String labelName) { |
170 |
LabelClass[] classes = getLabelClasses();
|
171 |
for (int i = 0; i < classes.length; i++) { |
172 |
if (classes[i].getName().equals(labelName)) {
|
173 |
return classes[i];
|
174 |
} |
175 |
} |
176 |
return null; |
177 |
} |
178 |
|
179 |
public ILabelingMethod cloneMethod() {
|
180 |
// TODO Auto-generated method stub
|
181 |
throw new Error("Not yet implemented!"); |
182 |
} |
183 |
} |