01: package de.hawhamburg.sridsupport;
02:
03: import java.awt.Graphics2D;
04: import java.util.Iterator;
05:
06: import com.vividsolutions.jts.util.Assert;
07: import com.vividsolutions.jump.feature.Feature;
08: import com.vividsolutions.jump.workbench.model.CategoryEvent;
09: import com.vividsolutions.jump.workbench.model.FeatureEvent;
10: import com.vividsolutions.jump.workbench.model.Layer;
11: import com.vividsolutions.jump.workbench.model.LayerEvent;
12: import com.vividsolutions.jump.workbench.model.LayerListener;
13: import com.vividsolutions.jump.workbench.ui.Viewport;
14: import com.vividsolutions.jump.workbench.ui.renderer.style.Style;
15:
16: /**
17: * Ensures that all geometries have a given SRID. Because it is a Style, it will
18: * be saved to the task file.
19: */
20: public class SRIDStyle implements Style {
21: private int srid = -1;
22:
23: public void paint(Feature f, Graphics2D g, Viewport viewport)
24: throws Exception {
25: }
26:
27: private boolean initialized = false;
28:
29: public void initialize(Layer layer) {
30: if (initialized) {
31: return;
32: }
33: updateSRIDs(layer);
34: layer.getLayerManager().addLayerListener(new LayerListener() {
35: public void featuresChanged(FeatureEvent e) {
36: for (Iterator i = e.getFeatures().iterator(); i
37: .hasNext();) {
38: Feature feature = (Feature) i.next();
39: feature.getGeometry().setSRID(srid);
40: }
41: }
42:
43: public void layerChanged(LayerEvent e) {
44: }
45:
46: public void categoryChanged(CategoryEvent e) {
47: }
48: });
49: initialized = true;
50: }
51:
52: public void updateSRIDs(Layer layer) {
53: for (Iterator i = layer.getFeatureCollectionWrapper()
54: .iterator(); i.hasNext();) {
55: Feature feature = (Feature) i.next();
56: feature.getGeometry().setSRID(srid);
57: }
58: }
59:
60: public Object clone() {
61: try {
62: return super .clone();
63: } catch (CloneNotSupportedException e) {
64: Assert.shouldNeverReachHere();
65: return null;
66: }
67: }
68:
69: public void setEnabled(boolean enabled) {
70: this .enabled = enabled;
71: }
72:
73: private boolean enabled = true;
74:
75: public boolean isEnabled() {
76: return enabled;
77: }
78:
79: public int getSRID() {
80: return srid;
81: }
82:
83: public void setSRID(int srid) {
84: this.srid = srid;
85: }
86:
87: }
|