1 |
1 |
package com.iver.cit.gvsig.fmap.edition;
|
2 |
2 |
|
|
3 |
import java.awt.Color;
|
|
4 |
import java.awt.Font;
|
3 |
5 |
import java.awt.geom.Point2D;
|
4 |
6 |
import java.awt.geom.Rectangle2D;
|
5 |
7 |
import java.io.IOException;
|
... | ... | |
7 |
9 |
import java.util.BitSet;
|
8 |
10 |
import java.util.List;
|
9 |
11 |
|
|
12 |
import org.cresques.cts.ICoordTrans;
|
|
13 |
|
|
14 |
import com.hardcode.gdbms.engine.values.DoubleValue;
|
|
15 |
import com.hardcode.gdbms.engine.values.IntValue;
|
|
16 |
import com.hardcode.gdbms.engine.values.NullValue;
|
10 |
17 |
import com.hardcode.gdbms.engine.values.NumericValue;
|
|
18 |
import com.hardcode.gdbms.engine.values.StringValue;
|
11 |
19 |
import com.hardcode.gdbms.engine.values.Value;
|
|
20 |
import com.hardcode.gdbms.engine.values.ValueFactory;
|
12 |
21 |
import com.iver.cit.gvsig.fmap.DriverException;
|
13 |
22 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
|
14 |
23 |
import com.iver.cit.gvsig.fmap.core.FGeometry;
|
... | ... | |
17 |
26 |
import com.iver.cit.gvsig.fmap.core.IGeometry;
|
18 |
27 |
import com.iver.cit.gvsig.fmap.core.IRow;
|
19 |
28 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
|
|
29 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
|
20 |
30 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
|
21 |
31 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel;
|
|
32 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
|
22 |
33 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
|
|
34 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
|
23 |
35 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
|
24 |
36 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
|
25 |
37 |
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation;
|
|
38 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial;
|
|
39 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
|
|
40 |
import com.iver.cit.gvsig.fmap.rendering.Legend;
|
|
41 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend;
|
26 |
42 |
import com.vividsolutions.jts.geom.Envelope;
|
27 |
43 |
import com.vividsolutions.jts.index.quadtree.Quadtree;
|
28 |
44 |
|
... | ... | |
30 |
46 |
private ArrayList labels;
|
31 |
47 |
private MappingAnnotation mapping;
|
32 |
48 |
private BitSet delBitset=new BitSet();
|
|
49 |
private Legend legend;
|
|
50 |
private boolean isInPixels=true;
|
|
51 |
private FLyrAnnotation lyrAnnotation;
|
33 |
52 |
|
|
53 |
|
|
54 |
public void createLabel(IRow row){
|
|
55 |
FSymbol symbol;
|
|
56 |
// El mapping[0] es el text
|
|
57 |
int fieldId = mapping.getColumnText();
|
|
58 |
// El mapping[1] es el ?ngulo
|
|
59 |
int idFieldRotationText = mapping.getColumnRotate();
|
|
60 |
// El mapping[2] es el color
|
|
61 |
int idFieldColorText = mapping.getColumnColor();
|
|
62 |
// El mapping[3] es el alto
|
|
63 |
int idFieldHeightText = mapping.getColumnHeight();
|
|
64 |
// El mapping[4] es el tipo de fuente
|
|
65 |
int idFieldTypeFontText = mapping.getColumnTypeFont();
|
|
66 |
// El mapping[5] es el estilo de fuente
|
|
67 |
int idFieldStyleFontText = mapping.getColumnStyleFont();
|
|
68 |
|
|
69 |
IGeometry geom = ((IFeature) row).getGeometry();
|
|
70 |
String t = new String();
|
|
71 |
Value val = row.getAttribute(fieldId);
|
|
72 |
t = val.toString();
|
|
73 |
if (idFieldColorText != -1) {
|
|
74 |
DoubleValue valColor = (DoubleValue) row
|
|
75 |
.getAttribute(idFieldColorText);
|
|
76 |
t = t.concat(valColor.toString());
|
|
77 |
}
|
|
78 |
if (idFieldTypeFontText != -1) {
|
|
79 |
StringValue valTypeFont = (StringValue) row
|
|
80 |
.getAttribute(idFieldTypeFontText);
|
|
81 |
t = t.concat(valTypeFont.toString());
|
|
82 |
}
|
|
83 |
if (idFieldStyleFontText != -1) {
|
|
84 |
IntValue valStyleFont = (IntValue) row
|
|
85 |
.getAttribute(idFieldStyleFontText);
|
|
86 |
t = t.concat(valStyleFont.toString());
|
|
87 |
}
|
|
88 |
|
|
89 |
Value total = ValueFactory.createValue(t);
|
|
90 |
|
|
91 |
FLabel[] lbls = geom.createLabels(0, true);
|
|
92 |
for (int j = 0; j < lbls.length; j++) {
|
|
93 |
if (lbls[j] != null) {
|
|
94 |
lbls[j].setString(val.toString());
|
|
95 |
if (idFieldRotationText != -1) {
|
|
96 |
DoubleValue rotation = (DoubleValue) row
|
|
97 |
.getAttribute(idFieldRotationText);
|
|
98 |
lbls[j].setRotation(rotation.getValue());
|
|
99 |
} else {
|
|
100 |
lbls[j]
|
|
101 |
.setRotation(legend.getDefaultSymbol()
|
|
102 |
.getRotation());
|
|
103 |
}
|
|
104 |
|
|
105 |
float height;
|
|
106 |
if (idFieldHeightText != -1) {
|
|
107 |
NumericValue h = (NumericValue) row
|
|
108 |
.getAttribute(idFieldHeightText);
|
|
109 |
height = h.floatValue();
|
|
110 |
lbls[j].setHeight(height);
|
|
111 |
} else {
|
|
112 |
height = legend.getDefaultSymbol().getFontSize();
|
|
113 |
lbls[j].setHeight(height);
|
|
114 |
}
|
|
115 |
VectorialUniqueValueLegend vuvl = (VectorialUniqueValueLegend) legend;
|
|
116 |
if (vuvl.getSymbolByValue(total) == null) {
|
|
117 |
Color color;
|
|
118 |
if (idFieldColorText != -1) {
|
|
119 |
DoubleValue c = (DoubleValue) row
|
|
120 |
.getAttribute(idFieldColorText);
|
|
121 |
color = new Color((int) c.getValue());
|
|
122 |
} else {
|
|
123 |
color = legend.getDefaultSymbol().getFontColor();
|
|
124 |
}
|
|
125 |
String typeFont;
|
|
126 |
if (idFieldTypeFontText != -1) {
|
|
127 |
StringValue tf = (StringValue) row
|
|
128 |
.getAttribute(idFieldTypeFontText);
|
|
129 |
typeFont = tf.getValue();
|
|
130 |
} else {
|
|
131 |
typeFont = legend.getDefaultSymbol().getFont()
|
|
132 |
.getFontName();
|
|
133 |
}
|
|
134 |
int style;
|
|
135 |
if (idFieldStyleFontText != -1) {
|
|
136 |
IntValue sf = (IntValue) row
|
|
137 |
.getAttribute(idFieldStyleFontText);
|
|
138 |
style = sf.getValue();
|
|
139 |
} else {
|
|
140 |
style = legend.getDefaultSymbol().getFont().getStyle();
|
|
141 |
}
|
|
142 |
symbol = new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
|
143 |
symbol.setFontSizeInPixels(isInPixels);
|
|
144 |
symbol.setFont(new Font(typeFont, style, (int) height));
|
|
145 |
symbol.setDescription(lbls[j].getString());
|
|
146 |
symbol.setFontColor(color);
|
|
147 |
vuvl.addSymbol(total, symbol);
|
|
148 |
}
|
|
149 |
|
|
150 |
}
|
|
151 |
labels.add(lbls[j]);
|
|
152 |
|
|
153 |
}
|
|
154 |
}
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
34 |
159 |
public int doAddRow(IRow feat) throws DriverIOException, IOException {
|
|
160 |
Value[] values=feat.getAttributes();
|
|
161 |
values[mapping.getColumnText()]=ValueFactory.createValue("New");
|
|
162 |
feat=new DefaultFeature(((DefaultFeature)feat).getGeometry(),values);
|
|
163 |
createLabel(feat);
|
|
164 |
lyrAnnotation.deleteSpatialIndex();
|
35 |
165 |
return super.doAddRow(feat);
|
36 |
166 |
}
|
37 |
167 |
|
... | ... | |
155 |
285 |
this.labels=lyrAnnotation.getLabels();
|
156 |
286 |
this.mapping=lyrAnnotation.getMapping();
|
157 |
287 |
this.delBitset=lyrAnnotation.getDelBitSet();
|
|
288 |
this.legend=lyrAnnotation.getLegend();
|
|
289 |
this.isInPixels=lyrAnnotation.isInPixels();
|
|
290 |
this.lyrAnnotation=lyrAnnotation;
|
158 |
291 |
}
|
159 |
292 |
public IRowEdited[] getFeatures(Rectangle2D r, String strEPSG) throws DriverException {
|
160 |
293 |
// En esta clase suponemos random access.
|
... | ... | |
193 |
326 |
f=new DefaultFeature(geom,f.getAttributes());
|
194 |
327 |
edRow = new DefaultRowEdited(f,
|
195 |
328 |
DefaultRowEdited.STATUS_ORIGINAL, calculatedIndex);
|
196 |
|
System.out.println("Piden la feature con ID= " + index);
|
|
329 |
///System.out.println("Piden la feature con ID= " + index);
|
197 |
330 |
// Exception e = new Exception();
|
198 |
331 |
// e.printStackTrace();
|
199 |
332 |
} catch (DriverException e) {
|