annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQ.java @ 4221:480de0dbca8e

Extended location input helper. The locationpicker has now an attribute whether the input is distance or location to display one or two clickable columns. Replaced the record click handler with cell click handler.
author Raimund Renkert <rrenkert@intevation.de>
date Tue, 23 Oct 2012 13:17:20 +0200
parents 5ff481ab24a1
children bcf25d8c183e
rev   line source
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.model;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
3 import java.util.regex.Matcher;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
4 import java.util.regex.Pattern;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
5
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import gnu.trove.TDoubleArrayList;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
8 import org.apache.log4j.Logger;
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
9
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 public class WQ
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
11 extends W
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
12 {
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
13 public static final Pattern NUMBERS_PATTERN =
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
14 Pattern.compile("\\D*(\\d++.\\d*)\\D*");
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
15
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
16 private static Logger log = Logger.getLogger(WQ.class);
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
17
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
18 protected TDoubleArrayList qs;
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 public WQ() {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 this("");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 public WQ(String name) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
25 super(name);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
26 qs = new TDoubleArrayList();
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 public WQ(int capacity) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 this(capacity, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public WQ(int capacity, String name) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
35 super(capacity, name);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
36 qs = new TDoubleArrayList(capacity);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 public WQ(double [] qs, double [] ws) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 this(qs, ws, "");
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 public WQ(double [] qs, double [] ws, String name) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 super(name);
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
45 this.ws = new TDoubleArrayList(ws);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
46 this.qs = new TDoubleArrayList(qs);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48
2087
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
49
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
50 public Double getRawValue() {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
51 if (name == null || name.length() == 0) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
52 // this should never happen
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
53 return null;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
54 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
55
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
56 Matcher m = NUMBERS_PATTERN.matcher(name);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
57
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
58 if (m.matches()) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
59 String raw = m.group(1);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
60
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
61 try {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
62 return Double.valueOf(raw);
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
63 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
64 catch (NumberFormatException nfe) {
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
65 // do nothing
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
66 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
67 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
68
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
69 return null;
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
70 }
bda04ae1154f #196 Localized the WQ labels in CSV exports.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1678
diff changeset
71
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 public void add(double w, double q) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
73 ws.add(w);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
74 qs.add(q);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 public double getQ(int idx) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
78 return qs.getQuick(idx);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
81 @Override
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 public double [] get(int idx) {
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 return get(idx, new double [2]);
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
86 @Override
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87 public double [] get(int idx, double [] dst) {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
88 dst[0] = ws.getQuick(idx);
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
89 dst[1] = qs.getQuick(idx);
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 return dst;
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 public double [] getQs() {
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
94 return qs.toNativeArray();
744
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
95 }
b385577bcaca WQ: Added a method to guess is increasing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 726
diff changeset
96
2182
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
97 @Override
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
98 public void removeNaNs() {
5ff481ab24a1 Refactored class hierachy to integrate model for W~W.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2087
diff changeset
99 removeNaNs(new TDoubleArrayList [] { ws, qs });
1033
821aaceb2776 Fix for flys/issue191
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 926
diff changeset
100 }
726
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 }
cbaa3ca86f2f Added base class WQ for WQKms.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org