annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java @ 1770:e8a98eee816d

Cosmetics, documentation. flys-artifacts/trunk@3091 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 26 Oct 2011 12:55:32 +0000
parents a7def20539fb
children 595c404523a6
rev   line source
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.charts;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import java.math.MathContext;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5 import java.awt.Dimension;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import java.awt.BorderLayout;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.awt.FlowLayout;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9 import javax.swing.JPanel;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import javax.swing.JButton;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11 import javax.swing.JComboBox;
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
12 import javax.swing.JTextField;
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
13 import javax.swing.DefaultComboBoxModel;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
14
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
15 import java.awt.event.ItemListener;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import java.awt.event.ItemEvent;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17 import java.awt.event.ActionListener;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 import java.awt.event.ActionEvent;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
20 import java.awt.geom.Point2D;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
21
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 import java.util.List;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 import java.io.File;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 import java.io.IOException;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 import java.io.FileWriter;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 import java.io.PrintWriter;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 import org.jfree.ui.ApplicationFrame;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30 import org.jfree.ui.RefineryUtilities;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 import org.jfree.chart.ChartFactory;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 import org.jfree.chart.plot.PlotOrientation;
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
35 import org.jfree.chart.plot.XYPlot;
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37 import org.jfree.chart.ChartUtilities;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 import org.jfree.chart.JFreeChart;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 import org.jfree.chart.ChartPanel;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
41 import org.jfree.chart.axis.NumberAxis;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
42
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 import org.jfree.data.xy.XYDataset;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 import org.jfree.data.xy.DefaultXYDataset;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 import de.intevation.flys.model.CrossSection;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 import de.intevation.flys.model.CrossSectionLine;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 import de.intevation.flys.model.CrossSectionPoint;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
50 import de.intevation.flys.geom.Lines;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
51
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
52 import de.intevation.flys.backend.SessionFactoryProvider;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 import org.hibernate.Session;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 import org.hibernate.Query;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 public class CrossSectionApp
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 extends ApplicationFrame
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 {
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 938
diff changeset
60 public static final String RIVER = System.getProperty("river", "Saar");
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 public static final double EPSILON = 1e-4;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64 protected Session session;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66 protected JComboBox crossSectionsCB;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 protected JComboBox crossSectionLinesCB;
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
68 protected JTextField waterlevelTF;
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 protected ChartPanel chartPanel;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
72 protected Double lastWaterLevel;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
73
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 public static class CrossSectionItem {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77 CrossSection crossSection;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
78
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
79 public CrossSectionItem(CrossSection crossSection) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 this.crossSection = crossSection;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83 public String toString() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 return crossSection.getDescription();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 } // CrossSectionItem
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
87
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
88 public static class CrossSectionLineItem {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 CrossSectionLine line;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 public CrossSectionLineItem(CrossSectionLine line) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 this.line = line;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96 public String toString() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 double v = line.getKm().doubleValue();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98 return String.valueOf(Math.round(v * 1000.0)/1000d);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 } // CrossSectionLineItem
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 public CrossSectionApp(String title) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 super(title);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 session = SessionFactoryProvider
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 .createSessionFactory()
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 .openSession();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 JPanel content = createContent();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110 content.setPreferredSize(new Dimension(640, 480));
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 setContentPane(content);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 public List<CrossSection> crossSections(String river) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 Query query = session.createQuery(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 "from CrossSection where river.name = :river");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 query.setParameter("river", river);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 return query.list();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 public JPanel createContent() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 JPanel panel = new JPanel(new BorderLayout());
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 JPanel nav = new JPanel(new FlowLayout());
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 Object [] csis = createCrossSectionItems();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 crossSectionsCB = new JComboBox(csis);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 DefaultComboBoxModel dcbm;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 if (csis.length > 0) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 Object [] cslis =
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 createCrossSectionLineItems(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 ((CrossSectionItem)csis[0]).crossSection);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 dcbm = new DefaultComboBoxModel(cslis);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 if (cslis.length > 0) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 dcbm.setSelectedItem(cslis[0]);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 else {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 dcbm = new DefaultComboBoxModel(new Object[0]);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 crossSectionLinesCB = new JComboBox(dcbm);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 nav.add(crossSectionsCB);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 nav.add(crossSectionLinesCB);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 crossSectionsCB.addItemListener(new ItemListener() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 public void itemStateChanged(ItemEvent ie) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 if (ie.getStateChange() == ItemEvent.SELECTED) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 updateCrossSection(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 ((CrossSectionItem)ie.getItem()).crossSection);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 });
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 crossSectionLinesCB.addItemListener(new ItemListener() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 public void itemStateChanged(ItemEvent ie) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 if (ie.getStateChange() == ItemEvent.SELECTED) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
163 updateChart();
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 });
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
169 waterlevelTF = new JTextField(5);
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
171 waterlevelTF.addActionListener(new ActionListener() {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
172 public void actionPerformed(ActionEvent ae) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
173 waterLevelChanged();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
174 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
175 });
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
176
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
177 nav.add(waterlevelTF);
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 JButton dump = new JButton("dump");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 dump.addActionListener(new ActionListener() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 public void actionPerformed(ActionEvent ae) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 dumpData();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 });
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 nav.add(dump);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
189 panel.add(nav, BorderLayout.SOUTH);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
190
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
191 chartPanel = createChartPanel();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
192
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
193 panel.add(chartPanel, BorderLayout.CENTER);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
194
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 return panel;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
198 protected void waterLevelChanged() {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
199 String value = waterlevelTF.getText();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
200 try {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
201 lastWaterLevel = Double.parseDouble(value);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
202 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
203 catch (NumberFormatException nfe) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
204 waterlevelTF.setText(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
205 lastWaterLevel != null ? lastWaterLevel.toString() : "");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
206 return;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
207 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
208 updateChart();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
209 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
210
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
211 protected void updateChart() {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
212
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
213 CrossSectionLineItem csli =
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
214 (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
215
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
216 JFreeChart chart = createChart(csli == null
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
217 ? new DefaultXYDataset()
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
218 : generateDataset(csli.line, lastWaterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
219
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
220 chartPanel.setChart(chart);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
221 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
222
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
223 protected ChartPanel createChartPanel() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
224 CrossSectionLineItem csli =
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
225 (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
226
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
227 JFreeChart chart = createChart(csli == null
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
228 ? new DefaultXYDataset()
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
229 : generateDataset(csli.line, lastWaterLevel));
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
230
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
231 return new ChartPanel(chart);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
232 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
233
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
234 protected void dumpData() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
235
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
236 CrossSectionLineItem csli =
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
237 (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
238
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
239 if (csli == null) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
240 return;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
241 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
242
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
243 CrossSectionLine line = csli.line;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
244
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
245 double km = Math.round(line.getKm().doubleValue() * 1000d)/1000d;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
246
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
247 String kmS = String.valueOf(km).replace(".", "-");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
248
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
249 int i = 1;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
250 File file = new File("cross-section-" + kmS + ".txt");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
251 while (file.exists()) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
252 file = new File("cross-section-" + kmS + "[" + (i++) + "].txt");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
253 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
254
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
255 System.err.println("dump points to file '" + file + "'");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
256
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
257 List<CrossSectionPoint> points = line.getPoints();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 PrintWriter out = null;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
261 MathContext mc = new MathContext(3);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
262
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
263 try {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
264 out =
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
265 new PrintWriter(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
266 new FileWriter(file));
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
267
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
268 for (CrossSectionPoint point: points) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
269 out.println(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270 point.getX().round(mc) + " " +
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
271 point.getY().round(mc));
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
272 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
273
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
274 out.flush();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
275 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
276 catch (IOException ioe) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
277 ioe.printStackTrace();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
278 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
279 finally {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
280 if (out != null) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
281 out.close();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
282 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
283 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
284 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285
1122
111794adf285 Get real (but yet not parameterized) data to display in CrossSection.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 938
diff changeset
286 public static XYDataset generateDataset(
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
287 CrossSectionLine line,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
288 Double waterlevel
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
289 ) {
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290 DefaultXYDataset dataset = new DefaultXYDataset();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1122
diff changeset
292 List<Point2D> points = line.fetchCrossSectionLinesPoints();
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294 if (points.isEmpty()) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 return dataset;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
296 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
298 if (waterlevel != null) {
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1122
diff changeset
299 double [][] data = Lines.createWaterLines(points, waterlevel);
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
300 dataset.addSeries(String.valueOf(waterlevel), data);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
301 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
302
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
303 CrossSection cs = line.getCrossSection();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
304
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
305 String legend = (cs != null ? cs.getDescription() : "???")
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306 + " " + Math.round(line.getKm().doubleValue() * 1000d)/1000d;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
307
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1122
diff changeset
308 double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1122
diff changeset
309
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1122
diff changeset
310 dataset.addSeries(legend, values);
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 return dataset;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
315 protected void updateCrossSection(CrossSection crossSection) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
316 Object [] cslis = createCrossSectionLineItems(crossSection);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
317 DefaultComboBoxModel dcbm = new DefaultComboBoxModel(cslis);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
318 if (cslis.length > 0) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
319 dcbm.setSelectedItem(cslis[0]);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
320 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
321 crossSectionLinesCB.setModel(dcbm);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
322 if (cslis.length > 0) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
323 CrossSectionLine line =
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
324 ((CrossSectionLineItem)cslis[0]).line;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
325 }
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
326 updateChart();
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
327 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
328
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
329 protected Object [] createCrossSectionLineItems(CrossSection cs) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
330 List<CrossSectionLine> lines = cs.getLines();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
331 Object [] result = new Object[lines.size()];
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
332 for (int i = 0; i < result.length; ++i) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
333 result[i] = new CrossSectionLineItem(lines.get(i));
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
334 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
335 return result;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
336 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
337
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
338
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
339 protected Object [] createCrossSectionItems() {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 List<CrossSection> crossSections = crossSections(RIVER);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
341 Object [] result = new Object[crossSections.size()];
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
342 for (int i = 0; i < result.length; ++i) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
343 result[i] = new CrossSectionItem(crossSections.get(i));
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
344 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
345 return result;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
346 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
347
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
348 public static JFreeChart createChart(XYDataset dataset) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
349 JFreeChart chart = ChartFactory.createXYLineChart(
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
350 null,
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
351 "Abstand [m]",
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
352 "H\u00f6he [m]",
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
353 dataset,
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
354 PlotOrientation.VERTICAL,
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
355 true,
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
356 true,
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
357 false);
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
358
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
359 XYPlot plot = chart.getXYPlot();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
360 NumberAxis yAxis = (NumberAxis)plot.getRangeAxis();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
361 yAxis.setAutoRangeIncludesZero(false);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 936
diff changeset
362
936
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
363 ChartUtilities.applyCurrentTheme(chart);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
364 return chart;
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
365 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
366
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
367 public static void main(String [] args) {
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
368 CrossSectionApp csa = new CrossSectionApp("Querprofile");
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
369 csa.pack();
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
370 RefineryUtilities.centerFrameOnScreen(csa);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
371 csa.setVisible(true);
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
372 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
373 }
759808931a2e Add Swing standalone app to test/develope cross sections directly from database.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
374 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org