comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ManualPointsArtifact.java @ 3198:d35f28655fa6

Create and handle new manual line type facets. flys-artifacts/trunk@4814 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 27 Jun 2012 15:22:01 +0000
parents 5642a83420f2
children 049ccd2c5935
comparison
equal deleted inserted replaced
3197:3e7911a02645 3198:d35f28655fa6
1 package de.intevation.flys.artifacts; 1 package de.intevation.flys.artifacts;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.List; 4 import java.util.List;
5 5
6 import java.awt.geom.Point2D;
7
6 import org.apache.log4j.Logger; 8 import org.apache.log4j.Logger;
7 9
8 import org.w3c.dom.Document; 10 import org.w3c.dom.Document;
11
12 import org.json.JSONArray;
13 import org.json.JSONException;
9 14
10 import de.intevation.artifactdatabase.state.Facet; 15 import de.intevation.artifactdatabase.state.Facet;
11 16
12 import de.intevation.artifacts.Artifact; 17 import de.intevation.artifacts.Artifact;
13 import de.intevation.artifacts.ArtifactFactory; 18 import de.intevation.artifacts.ArtifactFactory;
15 20
16 import de.intevation.flys.artifacts.model.FacetTypes; 21 import de.intevation.flys.artifacts.model.FacetTypes;
17 22
18 import de.intevation.flys.artifacts.states.DefaultState; 23 import de.intevation.flys.artifacts.states.DefaultState;
19 24
25 import de.intevation.flys.model.FastCrossSectionLine;
26
27 import de.intevation.flys.geom.Lines;
20 28
21 29
22 /** 30 /**
23 * Artifact to store user-added points. 31 * Artifact to store user-added points.
24 */ 32 */
25 public class ManualPointsArtifact 33 public class ManualPointsArtifact
26 extends StaticFLYSArtifact 34 extends StaticFLYSArtifact
27 implements FacetTypes 35 implements FacetTypes, WaterLineArtifact
28 { 36 {
29 /** The logger for this class. */ 37 /** The logger for this class. */
30 private static Logger logger = Logger.getLogger(ManualPointsArtifact.class); 38 private static Logger logger = Logger.getLogger(ManualPointsArtifact.class);
31 39
32 /** The name of the artifact. */ 40 /** The name of the artifact. */
68 public String getPointsData(String facetName) { 76 public String getPointsData(String facetName) {
69 return getDataAsString(facetName + ".data"); 77 return getDataAsString(facetName + ".data");
70 } 78 }
71 79
72 80
81 /**
82 * Access state data storing the jsonstring with lines.
83 * @param facetName Name of facet or null if the so far
84 * only known case should be picked.
85 * @return (String) value of data element (expect json).
86 */
87 public String getLinesData(String facetName) {
88 if (facetName == null)
89 return getDataAsString("cross_section.manualpoints.lines");
90 // TODO .lineS?
91 return getDataAsString(facetName + ".line");
92 }
93
94
73 /** Setup state and facet. */ 95 /** Setup state and facet. */
74 @Override 96 @Override
75 protected void initialize(Artifact artifact, Object context, CallMeta meta) { 97 protected void initialize(Artifact artifact, Object context, CallMeta meta) {
76 logger.debug("ManualPointsArtifact.initialize"); 98 logger.debug("ManualPointsArtifact.initialize");
77 List<Facet> fs = new ArrayList<Facet>(); 99 List<Facet> fs = new ArrayList<Facet>();
88 } 110 }
89 } 111 }
90 112
91 113
92 /** 114 /**
115 * Get value of line at index.
116 * @param index index in json array defining lines.
117 * @return water height of line at given index.
118 */
119 protected double getLine(int index) {
120 try {
121 JSONArray lines = new JSONArray((String) getLinesData(null));
122 JSONArray array = lines.getJSONArray(index);
123
124 return array.getDouble(0);
125 }
126 catch(JSONException e){
127 logger.error("Could not decode json for line.");
128 return 0d;
129 }
130 }
131
132
133 /**
134 * Get the water line "surface".
135 */
136 @Override
137 public Lines.LineData getWaterLines(int index, FastCrossSectionLine csl) {
138 List<Point2D> points = csl.getPoints();
139 return Lines.createWaterLines(points, getLine(index));
140 }
141
142 /**
93 * Determines Facets initial disposition regarding activity (think of 143 * Determines Facets initial disposition regarding activity (think of
94 * selection in Client ThemeList GUI). This will be checked one time 144 * selection in Client ThemeList GUI). This will be checked one time
95 * when the facet enters a collections describe document. 145 * when the facet enters a collections describe document.
96 * 146 *
97 * @param facetName name of the facet. 147 * @param facetName name of the facet.

http://dive4elements.wald.intevation.org