01: package com.vividsolutions.jump.workbench.ui.plugin;
02:
03: import com.vividsolutions.jts.geom.Coordinate;
04: import com.vividsolutions.jts.io.WKTWriter;
05: import com.vividsolutions.jump.feature.Feature;
06: import com.vividsolutions.jump.io.FUTURE_JTS_WKTWriter;
07: import com.vividsolutions.jump.io.GMLGeometryWriter;
08: import com.vividsolutions.jump.util.Fmt;
09: import com.vividsolutions.jump.util.StringUtil;
10: import com.vividsolutions.jump.workbench.plugin.AbstractPlugIn;
11: import com.vividsolutions.jump.workbench.plugin.PlugInContext;
12: import com.vividsolutions.jump.workbench.ui.AbstractFeatureTextWriter;
13:
14: public class InstallStandardFeatureTextWritersPlugIn extends
15: AbstractPlugIn {
16:
17: public void initialize(PlugInContext context) throws Exception {
18: context.getWorkbenchContext().getFeatureTextWriterRegistry()
19: .register(WKT_WRITER);
20: context.getWorkbenchContext().getFeatureTextWriterRegistry()
21: .register(GML_WRITER);
22: context.getWorkbenchContext().getFeatureTextWriterRegistry()
23: .register(COORDINATE_WRITER);
24: }
25:
26: private static final AbstractFeatureTextWriter COORDINATE_WRITER = new AbstractFeatureTextWriter(
27: false, "CL", "Coordinate List") {
28: public String write(Feature feature) {
29: StringBuffer s = new StringBuffer();
30: String className = StringUtil
31: .classNameWithoutQualifiers(feature.getGeometry()
32: .getClass().getName());
33: s.append(className + "\n");
34: Coordinate[] coordinates = feature.getGeometry()
35: .getCoordinates();
36: for (int i = 0; i < coordinates.length; i++) {
37: s.append("[" + Fmt.fmt(i, 10) + "] ");
38: s.append(coordinates[i].x + ", " + coordinates[i].y
39: + "\n");
40: }
41: return s.toString().trim();
42: }
43: };
44:
45: private static final AbstractFeatureTextWriter GML_WRITER = new AbstractFeatureTextWriter(
46: false, "GML", "Geography Markup Language") {
47: public String write(Feature feature) {
48: return writer.write(feature.getGeometry());
49: }
50:
51: private GMLGeometryWriter writer = new GMLGeometryWriter();
52: };
53:
54: private static final AbstractFeatureTextWriter WKT_WRITER = new AbstractFeatureTextWriter(
55: true, "WKT", "Well-Known Text") {
56: public String write(Feature feature) {
57: return wktWriter.write(feature.getGeometry()).trim();
58: }
59:
60: private FUTURE_JTS_WKTWriter wktWriter = new FUTURE_JTS_WKTWriter();
61: };
62: }
|