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