root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / labeling / DefaultLabelingMethod.java @ 28176
History | View | Annotate | Download (4.71 KB)
1 | 18622 | jdominguez | /* 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 com.iver.cit.gvsig.fmap.rendering.styling.labeling; |
||
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.utiles.XMLEntity; |
||
67 | |||
68 | 22070 | vcaballero | public class DefaultLabelingMethod implements ILabelingMethod { |
69 | 23908 | vcaballero | |
70 | 22070 | vcaballero | private LabelClass defaultLabel;
|
71 | 23908 | vcaballero | |
72 | 22070 | vcaballero | public DefaultLabelingMethod() {}
|
73 | 23908 | vcaballero | |
74 | 22070 | vcaballero | public DefaultLabelingMethod(LabelClass defaultLabel) {
|
75 | this();
|
||
76 | this.defaultLabel = defaultLabel;
|
||
77 | } |
||
78 | 18622 | jdominguez | |
79 | 23908 | vcaballero | |
80 | 18622 | jdominguez | public void addLabelClass(LabelClass lbl) { |
81 | 22070 | vcaballero | defaultLabel = lbl; |
82 | 18622 | jdominguez | } |
83 | |||
84 | public void deleteLabelClass(LabelClass lbl) { |
||
85 | // does nothing
|
||
86 | } |
||
87 | |||
88 | public String getClassName() { |
||
89 | return getClass().getName();
|
||
90 | } |
||
91 | |||
92 | public XMLEntity getXMLEntity() {
|
||
93 | XMLEntity xml = new XMLEntity();
|
||
94 | xml.putProperty("className", getClassName());
|
||
95 | 23908 | vcaballero | |
96 | 22070 | vcaballero | if (defaultLabel !=null) { |
97 | XMLEntity defaultLabelClassXML = defaultLabel.getXMLEntity(); |
||
98 | defaultLabelClassXML.putProperty("id", "defaultLabelClass"); |
||
99 | xml.addChild(defaultLabelClassXML); |
||
100 | } |
||
101 | 18622 | jdominguez | return xml;
|
102 | } |
||
103 | |||
104 | public void setXMLEntity(XMLEntity xml) { |
||
105 | 22070 | vcaballero | if (xml.findChildren("id", "defaultClass") !=null) |
106 | defaultLabel = LabelingFactory. |
||
107 | createLabelClassFromXML(xml.firstChild("id", "defaultLabelClass")); |
||
108 | 18622 | jdominguez | } |
109 | |||
110 | public boolean allowsMultipleClass() { |
||
111 | return false; |
||
112 | } |
||
113 | |||
114 | public void renameLabelClass(LabelClass lbl, String newName) { |
||
115 | // does nothing
|
||
116 | } |
||
117 | 23908 | vcaballero | |
118 | |||
119 | 18622 | jdominguez | public IFeatureIterator getFeatureIteratorByLabelClass(FLyrVect layer, LabelClass lc, ViewPort viewPort, String[] usedFields) |
120 | throws ReadDriverException {
|
||
121 | 23917 | vcaballero | |
122 | 24003 | vcaballero | // if(lc.isUseSqlQuery()){
|
123 | String sqlFields = ""; |
||
124 | for (int i = 0; i < usedFields.length; i++) { |
||
125 | sqlFields += usedFields[i]; |
||
126 | if (i < usedFields.length -1) sqlFields += ", "; |
||
127 | } |
||
128 | String fieldNames[] = layer.getSource().getRecordset().getFieldNames(); |
||
129 | StringBuilder sql = new StringBuilder(); |
||
130 | sql.append("select ");
|
||
131 | for (int i=0; i<fieldNames.length-1; i++) { |
||
132 | sql.append(fieldNames[i]); |
||
133 | sql.append(",");
|
||
134 | } |
||
135 | sql.append(fieldNames[fieldNames.length-1]);
|
||
136 | sql.append(" from ");
|
||
137 | sql.append(layer.getRecordset().getName()); |
||
138 | 23917 | vcaballero | if(lc.isUseSqlQuery()){
|
139 | sql.append(" where ");
|
||
140 | sql.append(lc.getSQLQuery()); |
||
141 | 23908 | vcaballero | } |
142 | 24003 | vcaballero | sql.append(";");
|
143 | 28176 | vcaballero | return layer.getSource().getFeatureIterator(sql.toString(), viewPort.getProjection());
|
144 | 24003 | vcaballero | // }
|
145 | // else {
|
||
146 | // return layer.getSource().getFeatureIterator(
|
||
147 | // viewPort.getAdjustedExtent(), usedFields,
|
||
148 | // layer.getProjection(), true);
|
||
149 | // }
|
||
150 | 18622 | jdominguez | } |
151 | 23908 | vcaballero | |
152 | 18622 | jdominguez | public boolean definesPriorities() { |
153 | return false; |
||
154 | } |
||
155 | 23908 | vcaballero | |
156 | 18622 | jdominguez | public void setDefinesPriorities(boolean flag) { |
157 | 23908 | vcaballero | /* nothing, since only one label class is suported */
|
158 | 18622 | jdominguez | } |
159 | 23908 | vcaballero | |
160 | 22070 | vcaballero | public LabelClass getLabelClassByName(String labelName) { |
161 | return defaultLabel;
|
||
162 | } |
||
163 | 23908 | vcaballero | |
164 | 22070 | vcaballero | public void clearAllClasses() { |
165 | defaultLabel = null;
|
||
166 | } |
||
167 | 23908 | vcaballero | |
168 | 22070 | vcaballero | public LabelClass[] getLabelClasses() { |
169 | return defaultLabel == null ? new LabelClass[0] : new LabelClass[] { defaultLabel }; |
||
170 | } |
||
171 | 23908 | vcaballero | |
172 | 22070 | vcaballero | public ILabelingMethod cloneMethod() {
|
173 | if (defaultLabel !=null) |
||
174 | return new DefaultLabelingMethod(LabelingFactory.createLabelClassFromXML(defaultLabel.getXMLEntity())); |
||
175 | return new DefaultLabelingMethod(); |
||
176 | } |
||
177 | 18622 | jdominguez | } |