annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/services/DischargeTablesOverview.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 0674d89210f5
children 08b6458909a9
rev   line source
4213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.services;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import java.awt.Color;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import java.text.DateFormat;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import java.text.ParseException;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import java.util.ArrayList;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import java.util.Collections;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import java.util.Date;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import java.util.List;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import java.util.Locale;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import org.apache.log4j.Logger;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import org.hibernate.Session;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import org.jfree.chart.ChartFactory;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import org.jfree.chart.JFreeChart;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.jfree.chart.plot.PlotOrientation;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import org.jfree.chart.plot.XYPlot;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 import org.jfree.data.xy.XYSeries;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import org.jfree.data.xy.XYSeriesCollection;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 import org.w3c.dom.Document;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 import org.w3c.dom.Element;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 import org.w3c.dom.NodeList;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 import de.intevation.artifacts.CallMeta;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 import de.intevation.artifacts.GlobalContext;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 import de.intevation.flys.artifacts.model.DischargeTables;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 import de.intevation.flys.artifacts.model.GaugesFactory;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 import de.intevation.flys.artifacts.resources.Resources;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 import de.intevation.flys.backend.SessionHolder;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 import de.intevation.flys.model.DischargeTable;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 import de.intevation.flys.model.Gauge;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 import de.intevation.flys.model.TimeInterval;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public class DischargeTablesOverview extends AbstractChartService {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 private static final Logger log = Logger
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 .getLogger(DischargeTablesOverview.class);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 private static final long serialVersionUID = 1L;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 public static final String I18N_CHART_TITLE = "gauge.discharge.service.chart.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43 public static final String DEFAULT_CHART_TITLE = "Pegel: XXX";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 public static final String I18N_CHART_X_AXIS_TITLE = "gauge.discharge.service.chart.x.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 public static final String DEFAULT_X_AXIS_TITLE = "Q [m^3/s]";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 public static final String I18N_CHART_Y_AXIS_TITLE = "gauge.discharge.service.chart.y.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 public static final String DEFAULT_Y_AXIS_TITLE = "W [cm]";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 public static final String I18N_CHART_SERIES_TITLE = "gauge.discharge.service.chart.series.title";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52 public static final String DEFAULT_CHART_SERIES_TITLE = "Abflusskurve";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public static final String I18N_CHART_SERIES_TITLE_MASTER = "gauge.discharge.service.chart.series.title.master";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 public static final String DEFAULT_CHART_SERIES_TITLE_MASTER = "Aktuelle Abflusskurve";
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 public static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58 DateFormat.SHORT, Locale.GERMANY);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60 private Session session;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62 @Override
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 protected void init() {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 session = SessionHolder.acquire();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 @Override
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 protected void finish() {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 if (session != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 session.close();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71 SessionHolder.release();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 protected JFreeChart createChart(Document data,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 GlobalContext globalContext, CallMeta callMeta) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 Gauge gauge = extractGauge(data);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80 if (gauge == null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81 log.warn("Could not determine Gauge from request!");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 log.info("create discharge chart for gauge '" + gauge.getName() + "'");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 TimeInterval timerange = extractTimeInterval(data);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 List<DischargeTable> dts = getDischargeTables(gauge, timerange);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 XYSeriesCollection dataset = new XYSeriesCollection();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 for (DischargeTable dt : dts) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 try {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 XYSeries series = createSeries(callMeta, dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 if (series != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95 dataset.addSeries(series);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98 catch (IllegalArgumentException iae) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99 log.warn("unable to create discharge curve: "
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 + iae.getMessage());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 String title = Resources.format(callMeta, I18N_CHART_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 DEFAULT_CHART_TITLE, gauge.getName());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107 String xAxis = Resources.getMsg(callMeta, I18N_CHART_X_AXIS_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 DEFAULT_X_AXIS_TITLE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 String yAxis = Resources.format(callMeta, I18N_CHART_Y_AXIS_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111 DEFAULT_Y_AXIS_TITLE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113 JFreeChart chart = ChartFactory.createXYLineChart(title, xAxis, yAxis,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 null, PlotOrientation.VERTICAL, true, true, false);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 chart.setBackgroundPaint(Color.white);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 XYPlot plot = (XYPlot) chart.getPlot();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 plot.setDataset(0, dataset);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120 plot.setBackgroundPaint(Color.white);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 plot.setDomainGridlinePaint(Color.gray);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 plot.setRangeGridlinePaint(Color.gray);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 plot.setDomainGridlinesVisible(true);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 plot.setRangeGridlinesVisible(true);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
125
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
126 return chart;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
127 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
128
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
129 protected XYSeries createSeries(CallMeta callMeta, DischargeTable dt)
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
130 throws IllegalArgumentException {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
131
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
132 double[][] xy = null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
133
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
134 if (dt.getKind() == DischargeTables.MASTER) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
135 xy = DischargeTables.loadDischargeTableValues(dt,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
136 DischargeTables.MASTER_SCALE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
137 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
138 else {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
139 xy = DischargeTables.loadDischargeTableValues(dt,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
140 DischargeTables.HISTORICAL_SCALE);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
141 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
142
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
143 XYSeries series = new XYSeries(createSeriesTitle(callMeta, dt), false);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
144 for (int i = 0, n = xy[0].length; i < n; i++) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
145 series.add(xy[0][i], xy[1][i]);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
146 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
147
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
148 return series;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
149 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
150
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
151 protected String createSeriesTitle(CallMeta callMeta, DischargeTable dt)
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
152 throws IllegalArgumentException {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
153 TimeInterval timeInterval = dt.getTimeInterval();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
154 Date start = timeInterval.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
155 Date end = timeInterval.getStopTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
156
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
157 if (start != null && end != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
158 return Resources.format(callMeta, I18N_CHART_SERIES_TITLE,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
159 DEFAULT_CHART_SERIES_TITLE, start, end);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
160 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
161 else if (start != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
162 return Resources.format(callMeta, I18N_CHART_SERIES_TITLE_MASTER,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
163 DEFAULT_CHART_SERIES_TITLE, start);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
164 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
165 else {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
166 throw new IllegalArgumentException(
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
167 "Missing start date of DischargeTable " + dt.getId());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
168 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
169 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
170
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
171 protected Gauge extractGauge(Document data) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
172 NodeList gauges = data.getElementsByTagName("gauge");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
173
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
174 if (gauges.getLength() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
175 String name = ((Element) gauges.item(0)).getAttribute("name");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
176 if (name != null && name.length() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
177 return GaugesFactory.getGauge(name);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
178 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
179 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
180
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
181 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
182 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
184 protected TimeInterval extractTimeInterval(Document data) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
185 NodeList timeranges = data.getElementsByTagName("timerange");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
186
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
187 if (timeranges != null && timeranges.getLength() > 0) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
188 Element timerange = (Element) timeranges.item(0);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
189
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
190 String lower = timerange.getAttribute("lower");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
191 String upper = timerange.getAttribute("upper");
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
192
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
193 if (lower != null && upper != null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
194 try {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
195 Date d1 = DATE_FORMAT.parse(lower);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196 Date d2 = DATE_FORMAT.parse(upper);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
197
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 return new TimeInterval(d1, d2);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 catch (ParseException pe) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201 log.warn("Wrong time format: " + pe.getMessage());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
202 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
204 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
205
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
206 return null;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
207 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
208
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
209 protected List<DischargeTable> getDischargeTables(Gauge gauge,
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
210 TimeInterval timerange) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
211 List<DischargeTable> all = gauge.getDischargeTables();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212 Collections.sort(all);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
213
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
214 if (timerange == null) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
215 return all;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
216 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
217
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
218 List<DischargeTable> dts = new ArrayList<DischargeTable>(all.size());
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
219 long startDate = timerange.getStartTime().getTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 long stopDate = timerange.getStopTime().getTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222 for (DischargeTable dt : all) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 TimeInterval tmp = dt.getTimeInterval();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 Date start = tmp.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225 Date stop = tmp.getStartTime();
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
227 if (start.getTime() > startDate && start.getTime() < stopDate) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
228 dts.add(dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
229 continue;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
230 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
231 else if (stop != null && stop.getTime() < stopDate
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
232 && stop.getTime() > startDate) {
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
233 dts.add(dt);
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
234 continue;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
235 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
236 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
237
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
238 return dts;
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
239 }
0674d89210f5 Added a new service to query a diagram with discharge tables.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
240 }

http://dive4elements.wald.intevation.org