2 |
2 |
|
3 |
3 |
import java.awt.Graphics2D;
|
4 |
4 |
import java.awt.image.BufferedImage;
|
|
5 |
import java.util.Iterator;
|
5 |
6 |
import java.util.Vector;
|
6 |
7 |
import java.util.logging.Level;
|
7 |
8 |
import java.util.logging.Logger;
|
... | ... | |
10 |
11 |
import javax.print.attribute.standard.PrintQuality;
|
11 |
12 |
|
12 |
13 |
import org.gvsig.data.ReadException;
|
|
14 |
import org.gvsig.data.vectorial.Feature;
|
|
15 |
import org.gvsig.data.vectorial.FeatureCollection;
|
|
16 |
import org.gvsig.data.vectorial.FeatureStore;
|
|
17 |
import org.gvsig.data.vectorial.FeatureType;
|
13 |
18 |
import org.gvsig.fmap.core.geometries.utils.FConstant;
|
14 |
19 |
import org.gvsig.fmap.core.geometries.utils.FLabel;
|
15 |
20 |
import org.gvsig.fmap.geom.Geometry;
|
... | ... | |
21 |
26 |
import org.gvsig.fmap.mapcontext.layers.FLayer;
|
22 |
27 |
import org.gvsig.fmap.mapcontext.layers.ReadableVectorial;
|
23 |
28 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
|
|
29 |
import org.gvsig.fmap.mapcontext.rendering.legend.NullValue;
|
24 |
30 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
|
25 |
31 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupportToolkit;
|
26 |
32 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleTextSymbol;
|
... | ... | |
87 |
93 |
&& (scale <= zoom.getMinScale()) ) ) {
|
88 |
94 |
try {
|
89 |
95 |
// limit the labeling to the visible extent
|
90 |
|
FBitSet bs = layer.queryByRect(viewPort.getAdjustedExtent());
|
91 |
|
|
92 |
|
ReadableVectorial source = layer.getSource();
|
93 |
|
SelectableDataSource recordSet = source.getRecordset();
|
94 |
|
|
95 |
|
for(int i=bs.nextSetBit(0); i>=0 && !cancel.isCanceled(); i=bs.nextSetBit(i+1)) {
|
96 |
|
Value[] vv = recordSet.getRow(i);
|
|
96 |
// FBitSet bs = layer.queryByRect(viewPort.getAdjustedExtent());
|
|
97 |
FeatureCollection collection=(FeatureCollection)layer.getFeatureStore().getDataCollection(new String[0],null,null);
|
|
98 |
// ReadableVectorial source = layer.getSource();
|
|
99 |
// SelectableDataSource recordSet = source.getRecordset();
|
|
100 |
Iterator iterator=collection.iterator();
|
|
101 |
while(iterator.hasNext()){
|
|
102 |
if (cancel.isCanceled()){
|
|
103 |
return;
|
|
104 |
}
|
|
105 |
Feature feature=(Feature)iterator.next();
|
|
106 |
// for(int i=bs.nextSetBit(0); i>=0 && !cancel.isCanceled(); i=bs.nextSetBit(i+1)) {
|
|
107 |
// Value[] vv = recordSet.getRow(i);
|
97 |
108 |
double size;
|
98 |
109 |
|
99 |
110 |
if (useFixedSize){
|
... | ... | |
102 |
113 |
} else if (idHeightField != -1) {
|
103 |
114 |
// text size is defined in the table
|
104 |
115 |
try {
|
105 |
|
size = ((NumericValue) vv[idHeightField]).doubleValue() * fontScaleFactor;
|
|
116 |
size = ((Number) feature.get(idHeightField)).doubleValue() * fontScaleFactor;
|
106 |
117 |
} catch (ClassCastException ccEx) {
|
107 |
|
if (!NullValue.class.equals(vv[idHeightField].getClass())) {
|
|
118 |
if (!NullValue.class.equals(feature.get(idHeightField).getClass())) {
|
108 |
119 |
throw new ReadException("Unknown", ccEx);
|
109 |
120 |
}
|
110 |
121 |
// a null value
|
111 |
122 |
Logger.getAnonymousLogger().
|
112 |
|
warning("Null text height value for text '"+vv[idTextField].toString()+"'");
|
|
123 |
warning("Null text height value for text '"+feature.get(idTextField).toString()+"'");
|
113 |
124 |
continue;
|
114 |
125 |
}
|
115 |
126 |
} else {
|
... | ... | |
138 |
149 |
double rotation = 0D;
|
139 |
150 |
if (idRotationField!= -1) {
|
140 |
151 |
// text rotation is defined in the table
|
141 |
|
rotation = -Math.toRadians(((NumericValue) vv[idRotationField]).doubleValue());
|
|
152 |
rotation = -Math.toRadians(((Number) feature.get(idRotationField)).doubleValue());
|
142 |
153 |
}
|
143 |
154 |
|
144 |
|
Geometry geom = source.getGeometry(i);
|
145 |
|
sym.setText(vv[idTextField].toString());
|
|
155 |
Geometry geom = (Geometry)feature.getDefaultGeometry();
|
|
156 |
sym.setText(feature.get(idTextField).toString());
|
146 |
157 |
sym.setRotation(rotation);
|
147 |
158 |
|
148 |
159 |
FLabel[] aux = geom.createLabels(0, true);
|
... | ... | |
152 |
163 |
sym.draw(g, null, p, cancel);
|
153 |
164 |
}
|
154 |
165 |
}
|
155 |
|
} catch (VisitorException e) {
|
156 |
|
Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the layer extent.\n" +
|
157 |
|
e.getMessage());
|
158 |
|
} catch (ExpansionFileReadException e) {
|
159 |
|
Logger.getAnonymousLogger().log(Level.SEVERE, "Could not draw annotation in the layer" +
|
160 |
|
"\""+layer.getName()+"\".\nIs the layer being edited?.\n"+e.getMessage());
|
161 |
166 |
} catch (ReadException e) {
|
162 |
167 |
Logger.getAnonymousLogger().log(Level.SEVERE, "Could not draw annotation in the layer.\n" +
|
163 |
168 |
e.getMessage());
|
... | ... | |
199 |
204 |
|
200 |
205 |
public String getRotationField() throws ReadException {
|
201 |
206 |
if (idRotationField == -1) return null;
|
202 |
|
return ((SelectableDataSource) layer.getRecordset())
|
203 |
|
.getFieldName(idRotationField);
|
|
207 |
return ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getByOrder(idRotationField).getName();
|
204 |
208 |
}
|
205 |
209 |
|
206 |
210 |
public int getRotationFieldId() {
|
... | ... | |
213 |
217 |
|
214 |
218 |
public String getTextField() throws ReadException {
|
215 |
219 |
if (idTextField == -1) return null;
|
216 |
|
return ((SelectableDataSource) layer.getRecordset())
|
217 |
|
.getFieldName(idTextField);
|
|
220 |
return ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getByOrder(idTextField).getName();
|
218 |
221 |
}
|
219 |
222 |
|
220 |
223 |
public int getTextFieldId() {
|
... | ... | |
227 |
230 |
|
228 |
231 |
public String getHeightField() throws ReadException {
|
229 |
232 |
if (idHeightField == -1) return null;
|
230 |
|
return ((SelectableDataSource) layer.getRecordset())
|
231 |
|
.getFieldName(idHeightField);
|
|
233 |
return ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getByOrder(idHeightField).getName();
|
232 |
234 |
}
|
233 |
235 |
|
234 |
236 |
public int getHeightFieldId() {
|
... | ... | |
255 |
257 |
|
256 |
258 |
public void setTextField(String textFieldName) {
|
257 |
259 |
try {
|
258 |
|
idTextField = ((SelectableDataSource) layer.getRecordset())
|
259 |
|
.getFieldIndexByName(textFieldName);
|
260 |
|
} catch (ReadDriverException e) {
|
|
260 |
idTextField = ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getFieldIndex(textFieldName);
|
|
261 |
} catch (ReadException e) {
|
261 |
262 |
Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage());
|
262 |
263 |
}
|
263 |
264 |
}
|
... | ... | |
265 |
266 |
public void setRotationField(String rotationFieldName) {
|
266 |
267 |
if (rotationFieldName != null) {
|
267 |
268 |
try {
|
268 |
|
idRotationField = ((SelectableDataSource) layer.getRecordset())
|
269 |
|
.getFieldIndexByName(rotationFieldName);
|
270 |
|
} catch (ReadDriverException e) {
|
|
269 |
idRotationField = ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getFieldIndex(rotationFieldName);
|
|
270 |
} catch (ReadException e) {
|
271 |
271 |
Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage());
|
272 |
272 |
}
|
273 |
273 |
} else idRotationField = -1;
|
... | ... | |
282 |
282 |
public void setHeightField(String heightFieldName) {
|
283 |
283 |
if (heightFieldName != null) {
|
284 |
284 |
try {
|
285 |
|
idHeightField = ((SelectableDataSource) layer.getRecordset())
|
286 |
|
.getFieldIndexByName(heightFieldName);
|
|
285 |
idHeightField = ((FeatureType)layer.getFeatureStore().getFeatureTypes().get(0)).getFieldIndex(heightFieldName);
|
287 |
286 |
} catch (ReadException e) {
|
288 |
287 |
Logger.getAnonymousLogger().log(Level.SEVERE, e.getMessage());
|
289 |
288 |
}
|
... | ... | |
291 |
290 |
}
|
292 |
291 |
|
293 |
292 |
|
294 |
|
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, PrintRequestAttributeSet properties) throws ReadDriverException {
|
|
293 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, PrintRequestAttributeSet properties) throws ReadException {
|
295 |
294 |
isPrinting = true;
|
296 |
295 |
PrintQuality resolution=(PrintQuality)properties.get(PrintQuality.class);
|
297 |
296 |
if (resolution.equals(PrintQuality.NORMAL)){
|