comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java @ 1884:4ae9c92feb8c

StableXYDifferenceRenderer: Make rendering work with definition holes. flys-artifacts/trunk@3243 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 13 Nov 2011 14:02:35 +0000
parents eb671699fbc2
children e384d78ff78b
comparison
equal deleted inserted replaced
1883:eb671699fbc2 1884:4ae9c92feb8c
81 public class CrossSectionApp 81 public class CrossSectionApp
82 extends ApplicationFrame 82 extends ApplicationFrame
83 { 83 {
84 public static final String RIVER = System.getProperty("river", "Saar"); 84 public static final String RIVER = System.getProperty("river", "Saar");
85 85
86 public static final double EPSILON = 1e-4; 86 public static final String WATER_LEVEL = System.getProperty("waterlevel");
87
88 public static final String KM = System.getProperty("km");
89
90 public static final double EPSILON = 1e-4;
87 91
88 protected Session session; 92 protected Session session;
89 93
90 protected JComboBox crossSectionLinesCB; 94 protected JComboBox crossSectionLinesCB;
91 protected JTextField waterlevelTF; 95 protected JTextField waterlevelTF;
169 173
170 @Override 174 @Override
171 public Class<?> getColumnClass(int columnIndex) { 175 public Class<?> getColumnClass(int columnIndex) {
172 switch (columnIndex) { 176 switch (columnIndex) {
173 case 0: return String.class; 177 case 0: return String.class;
174 case 1: return Boolean.class; 178 case 1:
175 case 2: return Boolean.class; 179 case 2:
176 case 3: return Boolean.class; 180 case 3:
177 case 4: return Boolean.class; 181 case 4: return Boolean.class;
178 } 182 }
179 return null; 183 return null;
180 } 184 }
181 185
236 "from CrossSection where river.name = :river"); 240 "from CrossSection where river.name = :river");
237 query.setParameter("river", river); 241 query.setParameter("river", river);
238 return query.list(); 242 return query.list();
239 } 243 }
240 244
241 protected Map<Double, List<Pair<CrossSection, CrossSectionLine>>> loadAllLines( 245 protected Map<Double, List<Pair<CrossSection, CrossSectionLine>>>
242 List<CrossSection> crossSections 246 loadAllLines(List<CrossSection> crossSections) {
243 ) {
244 Map<Double, List<Pair<CrossSection, CrossSectionLine>>> km2lines = 247 Map<Double, List<Pair<CrossSection, CrossSectionLine>>> km2lines =
245 new TreeMap<Double, List<Pair<CrossSection, CrossSectionLine>>>(); 248 new TreeMap<Double, List<Pair<CrossSection, CrossSectionLine>>>();
246 for (CrossSection cs: crossSections) { 249 for (CrossSection cs: crossSections) {
247 List<CrossSectionLine> lines = cs.getLines(); 250 List<CrossSectionLine> lines = cs.getLines();
248 for (CrossSectionLine csl: lines) { 251 for (CrossSectionLine csl: lines) {
249 Double km = Math.round(csl.getKm().doubleValue() * 1000d)/1000d; 252 Double km = Math.round(csl.getKm().doubleValue() * 1000d)/1000d;
250 List<Pair<CrossSection, CrossSectionLine>> ls = km2lines.get(km); 253 List<Pair<CrossSection, CrossSectionLine>> ls
254 = km2lines.get(km);
251 if (ls == null) { 255 if (ls == null) {
252 ls = new ArrayList<Pair<CrossSection, CrossSectionLine>>(2); 256 ls = new ArrayList<Pair<CrossSection, CrossSectionLine>>(2);
253 km2lines.put(km, ls); 257 km2lines.put(km, ls);
254 } 258 }
255 ls.add(new Pair<CrossSection, CrossSectionLine>(cs, csl)); 259 ls.add(new Pair<CrossSection, CrossSectionLine>(cs, csl));
277 281
278 DefaultComboBoxModel dcbm = new DefaultComboBoxModel(clis); 282 DefaultComboBoxModel dcbm = new DefaultComboBoxModel(clis);
279 283
280 crossSectionLinesCB = new JComboBox(dcbm); 284 crossSectionLinesCB = new JComboBox(dcbm);
281 285
286 if (KM != null) {
287 try {
288 double km = Double.parseDouble(KM);
289
290 CrossSectionLineItem found = null;
291
292 for (Object o: clis) {
293 CrossSectionLineItem csli = (CrossSectionLineItem)o;
294 if (Math.abs(csli.km - km) < EPSILON) {
295 found = csli;
296 break;
297 }
298 }
299
300 if (found != null) {
301 crossSectionLinesCB.setSelectedItem(found);
302 }
303 }
304 catch (NumberFormatException nfe) {
305 System.err.println("km is not a number: "
306 + nfe.getMessage());
307 }
308 }
309
282 nav.add(crossSectionLinesCB); 310 nav.add(crossSectionLinesCB);
283 311
284 crossSectionLinesCB.addItemListener(new ItemListener() { 312 crossSectionLinesCB.addItemListener(new ItemListener() {
285 @Override 313 @Override
286 public void itemStateChanged(ItemEvent ie) { 314 public void itemStateChanged(ItemEvent ie) {
290 } 318 }
291 }); 319 });
292 320
293 waterlevelTF = new JTextField(5); 321 waterlevelTF = new JTextField(5);
294 322
323 if (WATER_LEVEL != null) {
324 try {
325 waterlevelTF.setText(
326 (lastWaterLevel = Double.valueOf(WATER_LEVEL)).toString());
327 }
328 catch (NumberFormatException nfe) {
329 System.err.println("Water level not a number: " +
330 nfe.getMessage());
331 }
332 }
333
295 waterlevelTF.addActionListener(new ActionListener() { 334 waterlevelTF.addActionListener(new ActionListener() {
296 @Override 335 @Override
297 public void actionPerformed(ActionEvent ae) { 336 public void actionPerformed(ActionEvent ae) {
298 waterLevelChanged(); 337 waterLevelChanged();
299 } 338 }
341 } 380 }
342 381
343 protected void waterLevelChanged() { 382 protected void waterLevelChanged() {
344 String value = waterlevelTF.getText(); 383 String value = waterlevelTF.getText();
345 try { 384 try {
346 lastWaterLevel = Double.parseDouble(value); 385 lastWaterLevel = Double.valueOf(value);
347 } 386 }
348 catch (NumberFormatException nfe) { 387 catch (NumberFormatException nfe) {
349 waterlevelTF.setText( 388 waterlevelTF.setText(
350 lastWaterLevel != null ? lastWaterLevel.toString() : ""); 389 lastWaterLevel != null ? lastWaterLevel.toString() : "");
351 return; 390 return;
525 (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem(); 564 (CrossSectionLineItem)crossSectionLinesCB.getSelectedItem();
526 565
527 for (int i = 0; i < drawCrossSection.length; ++i) { 566 for (int i = 0; i < drawCrossSection.length; ++i) {
528 List<Point2D> points = null; 567 List<Point2D> points = null;
529 CrossSection cs = crossSections.get(i); 568 CrossSection cs = crossSections.get(i);
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
545 if (drawCrossSection[i]) {
546 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
547 if (csl.getA() == cs) {
548 if (points == null) {
549 points = csl.getB().fetchCrossSectionLinesPoints();
550 }
551
552 generateProfile(
553 points, cs.getDescription(), datasets);
554 break;
555 }
556 }
557 }
558
559 if (drawWaterLevel[i]) {
560 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
561 if (csl.getA() == cs) {
562 if (points == null) {
563 points = csl.getB().fetchCrossSectionLinesPoints();
564 }
565 generateWaterLevels(points, datasets);
566 break;
567 }
568 }
569 }
570 569
571 if (drawGround[i]) { 570 if (drawGround[i]) {
572 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) { 571 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
573 if (csl.getA() == cs) { 572 if (csl.getA() == cs) {
574 if (points == null) { 573 if (points == null) {
580 datasets); 579 datasets);
581 break; 580 break;
582 } 581 }
583 } 582 }
584 } 583 }
584
585 if (drawFill[i]) {
586 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
587 if (csl.getA() == cs) {
588 if (points == null) {
589 points = csl.getB().fetchCrossSectionLinesPoints();
590 }
591
592 generateFill(
593 points, cs.getDescription(), datasets);
594 break;
595 }
596 }
597 }
598
599 if (drawCrossSection[i]) {
600 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
601 if (csl.getA() == cs) {
602 if (points == null) {
603 points = csl.getB().fetchCrossSectionLinesPoints();
604 }
605
606 generateProfile(
607 points, cs.getDescription(), datasets);
608 break;
609 }
610 }
611 }
612
613 if (drawWaterLevel[i]) {
614 for (Pair<CrossSection, CrossSectionLine> csl: csli.lines) {
615 if (csl.getA() == cs) {
616 if (points == null) {
617 points = csl.getB().fetchCrossSectionLinesPoints();
618 }
619 generateWaterLevels(points, datasets);
620 break;
621 }
622 }
623 }
624
585 } 625 }
586 626
587 return datasets; 627 return datasets;
588 } 628 }
589 629

http://dive4elements.wald.intevation.org