root / trunk / extensions / extAddEventTheme / src / com / iver / gvsig / addeventtheme / AddEventThemListener.java @ 5240
History | View | Annotate | Download (3.66 KB)
1 |
package com.iver.gvsig.addeventtheme; |
---|---|
2 |
|
3 |
import java.awt.geom.PathIterator; |
4 |
import java.io.IOException; |
5 |
|
6 |
import com.hardcode.driverManager.DriverLoadException; |
7 |
import com.hardcode.gdbms.engine.values.DoubleValue; |
8 |
import com.hardcode.gdbms.engine.values.NumericValue; |
9 |
import com.hardcode.gdbms.engine.values.Value; |
10 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
11 |
import com.iver.cit.gvsig.fmap.DriverException; |
12 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
13 |
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator; |
14 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
15 |
import com.iver.cit.gvsig.fmap.core.IRow; |
16 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
17 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
18 |
import com.iver.cit.gvsig.fmap.drivers.addevent.AddEventThemeDriver; |
19 |
import com.iver.cit.gvsig.fmap.edition.AfterRowEditEvent; |
20 |
import com.iver.cit.gvsig.fmap.edition.BeforeRowEditEvent; |
21 |
import com.iver.cit.gvsig.fmap.edition.EditionEvent; |
22 |
import com.iver.cit.gvsig.fmap.edition.IEditionListener; |
23 |
import com.iver.cit.gvsig.fmap.edition.VectorialEditableAdapter; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
25 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
26 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
27 |
import com.iver.utiles.DoubleUtilities; |
28 |
|
29 |
public class AddEventThemListener implements LayerListener,IEditionListener{ |
30 |
|
31 |
|
32 |
public void visibilityChanged(LayerEvent e) { |
33 |
|
34 |
} |
35 |
|
36 |
public void activationChanged(LayerEvent e) { |
37 |
|
38 |
} |
39 |
|
40 |
public void nameChanged(LayerEvent e) { |
41 |
|
42 |
} |
43 |
|
44 |
public void editionChanged(LayerEvent e) { |
45 |
if (e.getSource().isEditing()){
|
46 |
VectorialEditableAdapter vea = |
47 |
(VectorialEditableAdapter)((FLyrVect)e.getSource()).getSource(); |
48 |
vea.addEditionListener(this);
|
49 |
} |
50 |
} |
51 |
|
52 |
public void processEvent(EditionEvent e) { |
53 |
// TODO Auto-generated method stub
|
54 |
|
55 |
} |
56 |
|
57 |
public void beforeRowEditEvent(IRow feat,BeforeRowEditEvent e) { |
58 |
if (EditionEvent.CHANGE_TYPE_MODIFY == e.getChangeType()) {
|
59 |
VectorialEditableAdapter vea = (VectorialEditableAdapter) e |
60 |
.getSource(); |
61 |
int numRow = (int) e.getNumRow(); |
62 |
//DefaultFeature df = null;
|
63 |
try {
|
64 |
//df = (DefaultFeature) vea.getFeature(numRow);
|
65 |
|
66 |
if (EditionEvent.GRAPHIC == e.getSourceType()) {
|
67 |
double[] d = new double[4]; |
68 |
IGeometry g = ((DefaultFeature)feat).getGeometry(); |
69 |
g.getPathIterator(null).currentSegment(d);
|
70 |
int[] xy = ((AddEventThemeDriver) vea.getDriver()) |
71 |
.getFieldsIndex(); |
72 |
Value[] values = ((DefaultFeature)feat).getAttributes();
|
73 |
values[xy[0]] = ValueFactory.createValue(DoubleUtilities.format(d[0],".".charAt(0),4)); |
74 |
values[xy[1]] = ValueFactory.createValue(DoubleUtilities.format(d[1],".".charAt(0),4)); |
75 |
//feat = new DefaultFeature(g, values);
|
76 |
//Value value0=vea.getRecordset().getFieldValue(numRow,xy[0]);
|
77 |
//((DoubleValue)value0).setValue(d[0]);
|
78 |
//Value value1=vea.getRecordset().getFieldValue(numRow,xy[1]);
|
79 |
//((DoubleValue)value1).setValue(d[1]);
|
80 |
//vea.setRow(numRow, df);
|
81 |
} else if (EditionEvent.ALPHANUMERIC == e.getSourceType()) { |
82 |
IGeometry g = ((DefaultFeature)feat).getGeometry(); |
83 |
int[] xy = ((AddEventThemeDriver) vea.getDriver()) |
84 |
.getFieldsIndex(); |
85 |
NumericValue x = (NumericValue) ((DefaultFeature) feat) |
86 |
.getAttribute(xy[0]);
|
87 |
NumericValue y = (NumericValue) ((DefaultFeature) feat) |
88 |
.getAttribute(xy[1]);
|
89 |
g = ShapeFactory.createPoint2D(x.doubleValue(), y |
90 |
.doubleValue()); |
91 |
((DefaultFeature)feat).setGeometry(g); |
92 |
//feat = new DefaultFeature(g, ((DefaultFeature) feat)
|
93 |
// .getAttributes());
|
94 |
//vea.setRow(numRow, df);
|
95 |
} |
96 |
} catch (DriverLoadException e1) {
|
97 |
e1.printStackTrace(); |
98 |
} |
99 |
} |
100 |
} |
101 |
|
102 |
public void afterRowEditEvent(AfterRowEditEvent e) { |
103 |
|
104 |
|
105 |
} |
106 |
|
107 |
|
108 |
|
109 |
} |