comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java @ 1883:eb671699fbc2

CrossSectionApp: Draw water, too. flys-artifacts/trunk@3242 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 12 Nov 2011 22:26:27 +0000
parents 0e9c0b49b4ef
children 4ae9c92feb8c
comparison
equal deleted inserted replaced
1882:d67a9ca116c3 1883:eb671699fbc2
20 import java.awt.event.ActionListener; 20 import java.awt.event.ActionListener;
21 import java.awt.event.ItemEvent; 21 import java.awt.event.ItemEvent;
22 import java.awt.event.ItemListener; 22 import java.awt.event.ItemListener;
23 23
24 import java.awt.geom.Point2D; 24 import java.awt.geom.Point2D;
25 import java.awt.geom.Rectangle2D;
25 26
26 import java.io.File; 27 import java.io.File;
27 import java.io.FileWriter; 28 import java.io.FileWriter;
28 import java.io.IOException; 29 import java.io.IOException;
29 import java.io.PrintWriter; 30 import java.io.PrintWriter;
33 import java.util.ArrayList; 34 import java.util.ArrayList;
34 import java.util.Arrays; 35 import java.util.Arrays;
35 import java.util.List; 36 import java.util.List;
36 import java.util.Map; 37 import java.util.Map;
37 import java.util.TreeMap; 38 import java.util.TreeMap;
39
40 import java.awt.Color;
41 import java.awt.Paint;
42 import java.awt.TexturePaint;
43
44 import java.awt.image.BufferedImage;
38 45
39 import javax.swing.DefaultComboBoxModel; 46 import javax.swing.DefaultComboBoxModel;
40 import javax.swing.JButton; 47 import javax.swing.JButton;
41 import javax.swing.JComboBox; 48 import javax.swing.JComboBox;
42 import javax.swing.JPanel; 49 import javax.swing.JPanel;
89 96
90 protected List<CrossSection> crossSections; 97 protected List<CrossSection> crossSections;
91 protected boolean [] drawCrossSection; 98 protected boolean [] drawCrossSection;
92 protected boolean [] drawWaterLevel; 99 protected boolean [] drawWaterLevel;
93 protected boolean [] drawGround; 100 protected boolean [] drawGround;
101 protected boolean [] drawFill;
94 102
95 protected Map<Double, List<Pair<CrossSection, CrossSectionLine>>> km2lines; 103 protected Map<Double, List<Pair<CrossSection, CrossSectionLine>>> km2lines;
104
105 protected static final Paint TRANSPARENT = createTransparentPaint();
96 106
97 public class CrossSectionTableModel extends AbstractTableModel { 107 public class CrossSectionTableModel extends AbstractTableModel {
98 108
99 @Override 109 @Override
100 public String getColumnName(int col) { 110 public String getColumnName(int col) {
101 switch (col) { 111 switch (col) {
102 case 0: return "Peilungsname"; 112 case 0: return "Peilungsname";
103 case 1: return "Peilung"; 113 case 1: return "Peilung";
104 case 2: return "Wasserstand"; 114 case 2: return "Wasserstand";
105 case 3: return "Boden"; 115 case 3: return "Boden";
116 case 4: return "Wasser";
106 } 117 }
107 return ""; 118 return "";
108 } 119 }
109 120
110 @Override 121 @Override
111 public int getColumnCount() { 122 public int getColumnCount() {
112 return 4; 123 return 5;
113 } 124 }
114 125
115 @Override 126 @Override
116 public int getRowCount() { 127 public int getRowCount() {
117 return crossSections != null ? crossSections.size() : 0; 128 return crossSections != null ? crossSections.size() : 0;
123 switch (col) { 134 switch (col) {
124 case 0: return crossSections.get(row).getDescription(); 135 case 0: return crossSections.get(row).getDescription();
125 case 1: return drawCrossSection[row]; 136 case 1: return drawCrossSection[row];
126 case 2: return drawWaterLevel[row]; 137 case 2: return drawWaterLevel[row];
127 case 3: return drawGround[row]; 138 case 3: return drawGround[row];
139 case 4: return drawFill[row];
128 } 140 }
129 return null; 141 return null;
130 } 142 }
131 143
132 @Override 144 @Override
142 fireTableCellUpdated(row, col); 154 fireTableCellUpdated(row, col);
143 } 155 }
144 break; 156 break;
145 case 3: 157 case 3:
146 if (change(drawGround, row, (Boolean)value)) { 158 if (change(drawGround, row, (Boolean)value)) {
159 fireTableCellUpdated(row, col);
160 }
161 break;
162 case 4:
163 if (change(drawFill, row, (Boolean)value)) {
147 fireTableCellUpdated(row, col); 164 fireTableCellUpdated(row, col);
148 } 165 }
149 break; 166 break;
150 } 167 }
151 } 168 }
155 switch (columnIndex) { 172 switch (columnIndex) {
156 case 0: return String.class; 173 case 0: return String.class;
157 case 1: return Boolean.class; 174 case 1: return Boolean.class;
158 case 2: return Boolean.class; 175 case 2: return Boolean.class;
159 case 3: return Boolean.class; 176 case 3: return Boolean.class;
177 case 4: return Boolean.class;
160 } 178 }
161 return null; 179 return null;
162 } 180 }
163 181
164 @Override 182 @Override
165 public boolean isCellEditable( 183 public boolean isCellEditable(
166 int rowIndex, 184 int rowIndex,
167 int columnIndex 185 int columnIndex
168 ) { 186 ) {
169 return columnIndex >= 1 && columnIndex <= 3; 187 return columnIndex >= 1 && columnIndex <= 4;
170 } 188 }
171 } // class CrossSectionTableModel 189 } // class CrossSectionTableModel
172 190
173 private static boolean change( 191 private static boolean change(
174 boolean [] values, 192 boolean [] values,
246 264
247 JPanel nav = new JPanel(new FlowLayout()); 265 JPanel nav = new JPanel(new FlowLayout());
248 266
249 crossSections = crossSections(RIVER); 267 crossSections = crossSections(RIVER);
250 km2lines = loadAllLines(crossSections); 268 km2lines = loadAllLines(crossSections);
251 drawCrossSection = new boolean[crossSections.size()]; 269
252 Arrays.fill(drawCrossSection, true); 270 int CS = crossSections.size();
253 271 Arrays.fill(drawCrossSection = new boolean[CS], true);
254 drawWaterLevel = new boolean[crossSections.size()]; 272 drawWaterLevel = new boolean[CS];
255 drawGround = new boolean[crossSections.size()]; 273 drawGround = new boolean[CS];
274 drawFill = new boolean[CS];
256 275
257 Object [] clis = createCrossSectionLineItems(km2lines); 276 Object [] clis = createCrossSectionLineItems(km2lines);
258 277
259 DefaultComboBoxModel dcbm = new DefaultComboBoxModel(clis); 278 DefaultComboBoxModel dcbm = new DefaultComboBoxModel(clis);
260 279
425 444
426 datasets.add(new Pair<XYDataset, XYItemRenderer>( 445 datasets.add(new Pair<XYDataset, XYItemRenderer>(
427 new XYSeriesCollection(series), null)); 446 new XYSeriesCollection(series), null));
428 } 447 }
429 448
449 public void generateFill(
450 List<Point2D> points,
451 String legend,
452 List<Pair<XYDataset, XYItemRenderer>> datasets
453 ) {
454 if (points == null || points.isEmpty() || lastWaterLevel == null) {
455 return;
456 }
457
458 double [][] data = Lines.createWaterLines(points, lastWaterLevel);
459 double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
460
461 DefaultXYDataset dataset = new DefaultXYDataset();
462
463 dataset.addSeries(legend + "-Linie", values);
464 dataset.addSeries(legend + "-Fl\u00e4che", data);
465
466 datasets.add(new Pair<XYDataset, XYItemRenderer>(
467 dataset,
468 new StableXYDifferenceRenderer(
469 TRANSPARENT, Color.blue, false)));
470 }
471
430 public void generateProfile( 472 public void generateProfile(
431 List<Point2D> points, 473 List<Point2D> points,
432 String legend, 474 String legend,
433 List<Pair<XYDataset, XYItemRenderer>> datasets 475 List<Pair<XYDataset, XYItemRenderer>> datasets
434 ) { 476 ) {
460 } 502 }
461 503
462 double [][] values = CrossSectionLine.fetchCrossSectionProfile(points); 504 double [][] values = CrossSectionLine.fetchCrossSectionProfile(points);
463 505
464 DefaultXYDataset dataset = new DefaultXYDataset(); 506 DefaultXYDataset dataset = new DefaultXYDataset();
507
508 XYSeries series = new XYSeries(legend, false);
509
465 dataset.addSeries(legend, values); 510 dataset.addSeries(legend, values);
466 511
467 StableXYDifferenceRenderer renderer = 512 StableXYDifferenceRenderer renderer =
468 new StableXYDifferenceRenderer(); 513 new StableXYDifferenceRenderer();
469 514
481 526
482 for (int i = 0; i < drawCrossSection.length; ++i) { 527 for (int i = 0; i < drawCrossSection.length; ++i) {
483 List<Point2D> points = null; 528 List<Point2D> points = null;
484 CrossSection cs = crossSections.get(i); 529 CrossSection cs = crossSections.get(i);
485 530
531 if (drawFill[i]) {
532 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
533 if (csl.getA() == cs) {
534 if (points == null) {
535 points = csl.getB().fetchCrossSectionLinesPoints();
536 }
537
538 generateFill(
539 points, cs.getDescription(), datasets);
540 break;
541 }
542 }
543 }
544
486 if (drawCrossSection[i]) { 545 if (drawCrossSection[i]) {
487 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) { 546 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
488 if (csl.getA() == cs) { 547 if (csl.getA() == cs) {
489 points = csl.getB().fetchCrossSectionLinesPoints(); 548 if (points == null) {
549 points = csl.getB().fetchCrossSectionLinesPoints();
550 }
490 551
491 generateProfile( 552 generateProfile(
492 points, cs.getDescription(), datasets); 553 points, cs.getDescription(), datasets);
493 break; 554 break;
494 } 555 }
496 } 557 }
497 558
498 if (drawWaterLevel[i]) { 559 if (drawWaterLevel[i]) {
499 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) { 560 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
500 if (csl.getA() == cs) { 561 if (csl.getA() == cs) {
501 if (points != null) { 562 if (points == null) {
502 points = csl.getB().fetchCrossSectionLinesPoints(); 563 points = csl.getB().fetchCrossSectionLinesPoints();
503 } 564 }
504 generateWaterLevels(points, datasets); 565 generateWaterLevels(points, datasets);
505 break; 566 break;
506 } 567 }
508 } 569 }
509 570
510 if (drawGround[i]) { 571 if (drawGround[i]) {
511 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) { 572 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
512 if (csl.getA() == cs) { 573 if (csl.getA() == cs) {
513 if (points != null) { 574 if (points == null) {
514 points = csl.getB().fetchCrossSectionLinesPoints(); 575 points = csl.getB().fetchCrossSectionLinesPoints();
515 } 576 }
516 generateGround( 577 generateGround(
517 points, 578 points,
518 cs.getDescription() + "/Boden", 579 cs.getDescription() + "/Boden",
572 633
573 ChartUtilities.applyCurrentTheme(chart); 634 ChartUtilities.applyCurrentTheme(chart);
574 return chart; 635 return chart;
575 } 636 }
576 637
638 protected static Paint createTransparentPaint() {
639 BufferedImage texture = new BufferedImage(
640 1, 1, BufferedImage.TYPE_4BYTE_ABGR);
641
642 return new TexturePaint(
643 texture, new Rectangle2D.Double(0d, 0d, 0d, 0d));
644 }
645
577 public static void main(String [] args) { 646 public static void main(String [] args) {
578 CrossSectionApp csa = new CrossSectionApp("Querprofile"); 647 CrossSectionApp csa = new CrossSectionApp("Querprofile");
579 csa.pack(); 648 csa.pack();
580 RefineryUtilities.centerFrameOnScreen(csa); 649 RefineryUtilities.centerFrameOnScreen(csa);
581 csa.setVisible(true); 650 csa.setVisible(true);

http://dive4elements.wald.intevation.org