comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/chart/PointRecord.java @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-client/src/main/java/org/dive4elements/river/client/client/ui/chart/PointRecord.java@821a02bbfb4e
children 172338b1407f
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 package org.dive4elements.river.client.client.ui.chart;
2
3 import com.google.gwt.json.client.JSONArray;
4 import com.google.gwt.json.client.JSONBoolean;
5 import com.google.gwt.json.client.JSONNumber;
6 import com.google.gwt.json.client.JSONString;
7 import com.google.gwt.json.client.JSONValue;
8
9 import com.smartgwt.client.widgets.grid.ListGridRecord;
10
11 /** Simple record to store points. */
12 public class PointRecord extends ListGridRecord {
13 protected static final String ATTRIBUTE_X = "X";
14 protected static final String ATTRIBUTE_Y = "Y";
15 protected static final String ATTRIBUTE_NAME = "name";
16 protected static final String ATTRIBUTE_ACTIVE = "active";
17
18 /** From a JSON-encoded point, create a PointRecord. */
19 public static PointRecord fromJSON(JSONArray jsonArray) {
20 JSONValue x = jsonArray.get(0);
21 JSONNumber y = (JSONNumber) jsonArray.get(1);
22 JSONString s = (JSONString) jsonArray.get(2);
23 JSONBoolean b = (JSONBoolean)jsonArray.get(3);
24
25 if(x instanceof JSONNumber) {
26 return new PointRecord(
27 b.booleanValue(), ((JSONNumber)x).doubleValue(),
28 y.doubleValue(), s.stringValue());
29 }
30 else {
31 return new PointRecord(
32 b.booleanValue(), ((JSONString)x).stringValue(),
33 y.doubleValue(), s.stringValue());
34 }
35 }
36
37 protected boolean isTimeseriesPoint = false;
38
39 public PointRecord(boolean isActive, double x, double y, String name) {
40 setActive(isActive);
41 setName(name);
42 setX(x);
43 setY(y);
44 }
45
46 /**
47 * Constructor taking the x axis value as String representing a Date value.
48 * @param isActive
49 * @param x
50 * @param y
51 * @param name
52 */
53 public PointRecord(boolean isActive, String x, double y, String name) {
54 setActive(isActive);
55 setName(name);
56 setX(x);
57 setY(y);
58
59 this.isTimeseriesPoint = true;
60 }
61
62 public void setActive(boolean isActive) {
63 setAttribute(ATTRIBUTE_ACTIVE, isActive);
64 }
65
66 public boolean isActive() {
67 return getAttributeAsBoolean(ATTRIBUTE_ACTIVE);
68 }
69
70 public boolean isTimeseriesPoint() {
71 return this.isTimeseriesPoint;
72 }
73
74 public void setName(String name) {
75 setAttribute(ATTRIBUTE_NAME, name);
76 }
77
78 public String getName() {
79 return getAttributeAsString(ATTRIBUTE_NAME);
80 }
81
82 public void setX(double x) {
83 setAttribute(ATTRIBUTE_X, x);
84 }
85
86 public void setX(String date) {
87 setAttribute(ATTRIBUTE_X, date);
88 }
89
90 public void setY(double y) {
91 setAttribute(ATTRIBUTE_Y, y);
92 }
93
94 public double getX() {
95 return getAttributeAsDouble(ATTRIBUTE_X);
96 }
97
98 public String getXAsDate() {
99 return getAttributeAsString(ATTRIBUTE_X);
100 }
101
102 public double getY() {
103 return getAttributeAsDouble(ATTRIBUTE_Y);
104 }
105 }

http://dive4elements.wald.intevation.org