Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixWQCurveGenerator.java @ 6905:1b35b2ddfc28
Artifacts: Introduce ThemeDocument & make stuff compileable again. THIS BREAKS THE SYSTEM! TODO: Move ThemeUtils into ThemeDocument.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 22 Aug 2013 23:31:38 +0200 |
parents | a071f0a80883 |
children | 88b70c788b0f |
comparison
equal
deleted
inserted
replaced
6904:d710bd3df387 | 6905:1b35b2ddfc28 |
---|---|
25 import org.jfree.chart.title.TextTitle; | 25 import org.jfree.chart.title.TextTitle; |
26 import org.jfree.data.xy.XYSeries; | 26 import org.jfree.data.xy.XYSeries; |
27 import org.jfree.ui.RectangleAnchor; | 27 import org.jfree.ui.RectangleAnchor; |
28 import org.jfree.ui.RectangleInsets; | 28 import org.jfree.ui.RectangleInsets; |
29 import org.jfree.ui.TextAnchor; | 29 import org.jfree.ui.TextAnchor; |
30 import org.w3c.dom.Document; | |
31 | 30 |
32 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; | 31 import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; |
33 import org.dive4elements.artifactdatabase.state.Facet; | 32 import org.dive4elements.artifactdatabase.state.Facet; |
34 import org.dive4elements.river.artifacts.D4EArtifact; | 33 import org.dive4elements.river.artifacts.D4EArtifact; |
35 import org.dive4elements.river.artifacts.StaticWKmsArtifact; | 34 import org.dive4elements.river.artifacts.StaticWKmsArtifact; |
55 import org.dive4elements.river.jfree.JFreeUtil; | 54 import org.dive4elements.river.jfree.JFreeUtil; |
56 import org.dive4elements.river.jfree.StickyAxisAnnotation; | 55 import org.dive4elements.river.jfree.StickyAxisAnnotation; |
57 import org.dive4elements.river.jfree.StyledXYSeries; | 56 import org.dive4elements.river.jfree.StyledXYSeries; |
58 import org.dive4elements.river.model.Gauge; | 57 import org.dive4elements.river.model.Gauge; |
59 import org.dive4elements.river.model.River; | 58 import org.dive4elements.river.model.River; |
59 import org.dive4elements.river.themes.ThemeDocument; | |
60 import org.dive4elements.river.utils.RiverUtils; | 60 import org.dive4elements.river.utils.RiverUtils; |
61 import org.dive4elements.river.utils.ThemeUtil; | |
62 | 61 |
63 /** | 62 /** |
64 * Generator for WQ fixing charts. | 63 * Generator for WQ fixing charts. |
65 * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a> | 64 * @author <a href="mailto:christian.lins@intevation.de">Christian Lins</a> |
66 */ | 65 */ |
173 plot.setRangeAxis(1, createYAxis(YAXIS.W.idx)); | 172 plot.setRangeAxis(1, createYAxis(YAXIS.W.idx)); |
174 } | 173 } |
175 } | 174 } |
176 | 175 |
177 @Override | 176 @Override |
178 public void doOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 177 public void doOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
179 logger.debug("doOut: " + aaf.getFacetName()); | 178 logger.debug("doOut: " + aaf.getFacetName()); |
180 if (!prepareChartData(aaf, doc, visible)) { | 179 if (!prepareChartData(aaf, doc, visible)) { |
181 logger.warn("Unknown facet, name " + aaf.getFacetName()); | 180 logger.warn("Unknown facet, name " + aaf.getFacetName()); |
182 } | 181 } |
183 } | 182 } |
184 | 183 |
185 /** | 184 /** |
186 * Return true if data could be handled, | 185 * Return true if data could be handled, |
187 * to be overridden to add more handled data. | 186 * to be overridden to add more handled data. |
188 */ | 187 */ |
189 public boolean prepareChartData(ArtifactAndFacet aaf, Document doc, boolean visible) { | 188 public boolean prepareChartData(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
190 String name = aaf.getFacetName(); | 189 String name = aaf.getFacetName(); |
191 | 190 |
192 this.artifact = (D4EArtifact) aaf.getArtifact(); | 191 this.artifact = (D4EArtifact) aaf.getArtifact(); |
193 | 192 |
194 if(name.startsWith(FIX_SECTOR_AVERAGE_WQ)) { | 193 if(name.startsWith(FIX_SECTOR_AVERAGE_WQ)) { |
255 return true; | 254 return true; |
256 } | 255 } |
257 | 256 |
258 | 257 |
259 /** Add sector average points to chart. */ | 258 /** Add sector average points to chart. */ |
260 protected void doSectorAverageOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 259 protected void doSectorAverageOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
261 logger.debug("doSectorAverageOut"); | 260 logger.debug("doSectorAverageOut"); |
262 | 261 |
263 QWDDateRange qwdd = (QWDDateRange) aaf.getData(context); | 262 QWDDateRange qwdd = (QWDDateRange) aaf.getData(context); |
264 QWD qwd = qwdd != null ? qwdd.getQWD() : null; | 263 QWD qwd = qwdd != null ? qwdd.getQWD() : null; |
265 | 264 |
270 logger.debug("doSectorAverageOut: qwd == null"); | 269 logger.debug("doSectorAverageOut: qwd == null"); |
271 } | 270 } |
272 } | 271 } |
273 | 272 |
274 /** Add analysis event points to chart. */ | 273 /** Add analysis event points to chart. */ |
275 protected void doAnalysisEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 274 protected void doAnalysisEventsOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
276 logger.debug("doAnalysisEventsOut"); | 275 logger.debug("doAnalysisEventsOut"); |
277 | 276 |
278 QWD qwd = (QWD)aaf.getData(context); | 277 QWD qwd = (QWD)aaf.getData(context); |
279 if(qwd != null) { | 278 if(qwd != null) { |
280 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc); | 279 XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc); |
290 qwd.getQ(), | 289 qwd.getQ(), |
291 qwd.getW()); | 290 qwd.getW()); |
292 textAnnos.add(anno); | 291 textAnnos.add(anno); |
293 | 292 |
294 addAxisSeries(series, YAXIS.W.idx, visible); | 293 addAxisSeries(series, YAXIS.W.idx, visible); |
295 if(visible && ThemeUtil.parseShowPointLabel(doc)) { | 294 if(visible && doc.parseShowPointLabel()) { |
296 RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc); | 295 RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc); |
297 flysAnno.setTextAnnotations(textAnnos); | 296 flysAnno.setTextAnnotations(textAnnos); |
298 addAnnotations(flysAnno); | 297 addAnnotations(flysAnno); |
299 } | 298 } |
300 } | 299 } |
303 } | 302 } |
304 } | 303 } |
305 | 304 |
306 | 305 |
307 /** Add reference event points to chart. */ | 306 /** Add reference event points to chart. */ |
308 protected void doReferenceEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 307 protected void doReferenceEventsOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
309 logger.debug("doReferenceEventsOut"); | 308 logger.debug("doReferenceEventsOut"); |
310 | 309 |
311 QWI qwd = (QWI)aaf.getData(context); | 310 QWI qwd = (QWI)aaf.getData(context); |
312 if (qwd == null) { | 311 if (qwd == null) { |
313 logger.debug("doReferenceEventsOut: qwds == null"); | 312 logger.debug("doReferenceEventsOut: qwds == null"); |
327 qwd.getQ(), | 326 qwd.getQ(), |
328 qwd.getW()); | 327 qwd.getW()); |
329 textAnnos.add(anno); | 328 textAnnos.add(anno); |
330 | 329 |
331 addAxisSeries(series, YAXIS.W.idx, visible); | 330 addAxisSeries(series, YAXIS.W.idx, visible); |
332 if(visible && ThemeUtil.parseShowPointLabel(doc)) { | 331 if(visible && doc.parseShowPointLabel()) { |
333 RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc); | 332 RiverAnnotation flysAnno = new RiverAnnotation(null, null, null, doc); |
334 flysAnno.setTextAnnotations(textAnnos); | 333 flysAnno.setTextAnnotations(textAnnos); |
335 addAnnotations(flysAnno); | 334 addAnnotations(flysAnno); |
336 } | 335 } |
337 } | 336 } |
338 | 337 |
339 | 338 |
340 private void addPointFromWQKms(WQKms wqkms, | 339 private void addPointFromWQKms(WQKms wqkms, |
341 String title, | 340 String title, |
342 Document theme, | 341 ThemeDocument theme, |
343 boolean visible | 342 boolean visible |
344 ) { | 343 ) { |
345 XYSeries series = new StyledXYSeries(title, theme); | 344 XYSeries series = new StyledXYSeries(title, theme); |
346 Double ckm = (Double) context.getContextValue(CURRENT_KM); | 345 Double ckm = (Double) context.getContextValue(CURRENT_KM); |
347 if (wqkms == null || wqkms.getKms().length == 0 || ckm == null) { | 346 if (wqkms == null || wqkms.getKms().length == 0 || ckm == null) { |
348 logger.info("addPointFromWQKms: No event data to show."); | 347 logger.info("addPointFromWQKms: No event data to show."); |
351 double[] kms = wqkms.getKms(); | 350 double[] kms = wqkms.getKms(); |
352 for (int i = 0 ; i< kms.length; i++) { | 351 for (int i = 0 ; i< kms.length; i++) { |
353 if (Math.abs(kms[i] - ckm) <= EPSILON) { | 352 if (Math.abs(kms[i] - ckm) <= EPSILON) { |
354 series.add(wqkms.getQ(i), wqkms.getW(i), false); | 353 series.add(wqkms.getQ(i), wqkms.getW(i), false); |
355 addAxisSeries(series, YAXIS.W.idx, visible); | 354 addAxisSeries(series, YAXIS.W.idx, visible); |
356 if(visible && ThemeUtil.parseShowPointLabel(theme)) { | 355 if(visible && theme.parseShowPointLabel()) { |
357 List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>(); | 356 List<XYTextAnnotation> textAnnos = new ArrayList<XYTextAnnotation>(); |
358 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( | 357 XYTextAnnotation anno = new CollisionFreeXYTextAnnotation( |
359 title, | 358 title, |
360 wqkms.getQ(i), | 359 wqkms.getQ(i), |
361 wqkms.getW(i)); | 360 wqkms.getW(i)); |
367 return; | 366 return; |
368 } | 367 } |
369 } | 368 } |
370 } | 369 } |
371 | 370 |
372 protected void doEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 371 protected void doEventsOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
373 logger.debug("doEventsOut"); | 372 logger.debug("doEventsOut"); |
374 // Find W/Q at km. | 373 // Find W/Q at km. |
375 addPointFromWQKms((WQKms) aaf.getData(context), | 374 addPointFromWQKms((WQKms) aaf.getData(context), |
376 aaf.getFacetDescription(), doc, visible); | 375 aaf.getFacetDescription(), doc, visible); |
377 } | 376 } |
378 | 377 |
379 | 378 |
380 protected void doWQCurveOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 379 protected void doWQCurveOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
381 logger.debug("doWQCurveOut"); | 380 logger.debug("doWQCurveOut"); |
382 | 381 |
383 FixWQCurveFacet facet = (FixWQCurveFacet)aaf.getFacet(); | 382 FixWQCurveFacet facet = (FixWQCurveFacet)aaf.getFacet(); |
384 FixFunction func = (FixFunction)facet.getData( | 383 FixFunction func = (FixFunction)facet.getData( |
385 aaf.getArtifact(), context); | 384 aaf.getArtifact(), context); |
426 else { | 425 else { |
427 logger.warn("doWQCurveOut: maxQ <= 0"); | 426 logger.warn("doWQCurveOut: maxQ <= 0"); |
428 } | 427 } |
429 } | 428 } |
430 | 429 |
431 protected void doOutlierOut(ArtifactAndFacet aaf, Document doc, boolean visible) { | 430 protected void doOutlierOut(ArtifactAndFacet aaf, ThemeDocument doc, boolean visible) { |
432 logger.debug("doOutlierOut"); | 431 logger.debug("doOutlierOut"); |
433 | 432 |
434 QWI[] qws = (QWI[])aaf.getData(context); | 433 QWI[] qws = (QWI[])aaf.getData(context); |
435 addQWSeries(qws, aaf, doc, visible); | 434 addQWSeries(qws, aaf, doc, visible); |
436 } | 435 } |
437 | 436 |
438 | 437 |
439 /** Add markers for q sectors. */ | 438 /** Add markers for q sectors. */ |
440 protected void doQSectorOut(ArtifactAndFacet aaf, Document theme, boolean visible) { | 439 protected void doQSectorOut(ArtifactAndFacet aaf, ThemeDocument theme, boolean visible) { |
441 logger.debug("doQSectorOut"); | 440 logger.debug("doQSectorOut"); |
442 if (!visible) { | 441 if (!visible) { |
443 return; | 442 return; |
444 } | 443 } |
445 | 444 |
463 continue; | 462 continue; |
464 } | 463 } |
465 Marker m = new ValueMarker(qsector.getValue()); | 464 Marker m = new ValueMarker(qsector.getValue()); |
466 m.setPaint(Color.black); | 465 m.setPaint(Color.black); |
467 | 466 |
468 float[] dashes = ThemeUtil.parseLineStyle(theme); | 467 float[] dashes = theme.parseLineStyle(); |
469 int size = ThemeUtil.parseLineWidth(theme); | 468 int size = theme.parseLineWidth(); |
470 BasicStroke stroke; | 469 BasicStroke stroke; |
471 if (dashes.length <= 1) { | 470 if (dashes.length <= 1) { |
472 stroke = new BasicStroke(size); | 471 stroke = new BasicStroke(size); |
473 } | 472 } |
474 else { | 473 else { |
479 dashes, | 478 dashes, |
480 0.0f); | 479 0.0f); |
481 } | 480 } |
482 m.setStroke(stroke); | 481 m.setStroke(stroke); |
483 | 482 |
484 if (ThemeUtil.parseShowLineLabel(theme)) { | 483 if (theme.parseShowLineLabel()) { |
485 m.setLabel(qsector.getName()); | 484 m.setLabel(qsector.getName()); |
486 m.setPaint(ThemeUtil.parseTextColor(theme)); | 485 m.setPaint(theme.parseTextColor()); |
487 m.setLabelFont(ThemeUtil.parseTextFont(theme)); | 486 m.setLabelFont(theme.parseTextFont()); |
488 } | 487 } |
489 Color paint = ThemeUtil.parseLineColorField(theme); | 488 Color paint = theme.parseLineColorField(); |
490 if (paint != null) { | 489 if (paint != null) { |
491 m.setPaint(paint); | 490 m.setPaint(paint); |
492 } | 491 } |
493 m.setLabelAnchor(RectangleAnchor.TOP_LEFT); | 492 m.setLabelAnchor(RectangleAnchor.TOP_LEFT); |
494 m.setLabelTextAnchor(TextAnchor.TOP_LEFT); | 493 m.setLabelTextAnchor(TextAnchor.TOP_LEFT); |
502 * Add W-Annotations to plot. | 501 * Add W-Annotations to plot. |
503 * @param wqkms actual data (double[][]). | 502 * @param wqkms actual data (double[][]). |
504 * @param theme theme to use. | 503 * @param theme theme to use. |
505 */ | 504 */ |
506 protected void doWAnnotations( | 505 protected void doWAnnotations( |
507 Object wqkms, | 506 Object wqkms, |
508 ArtifactAndFacet aandf, | 507 ArtifactAndFacet aandf, |
509 Document theme, | 508 ThemeDocument theme, |
510 boolean visible | 509 boolean visible |
511 ) { | 510 ) { |
512 Facet facet = aandf.getFacet(); | 511 Facet facet = aandf.getFacet(); |
513 | 512 |
514 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); | 513 List<StickyAxisAnnotation> xy = new ArrayList<StickyAxisAnnotation>(); |
515 if (wqkms instanceof double[][]) { | 514 if (wqkms instanceof double[][]) { |
547 */ | 546 */ |
548 protected void doDischargeOut( | 547 protected void doDischargeOut( |
549 WINFOArtifact artifact, | 548 WINFOArtifact artifact, |
550 Object o, | 549 Object o, |
551 String description, | 550 String description, |
552 Document theme, | 551 ThemeDocument theme, |
553 boolean visible) | 552 boolean visible) |
554 { | 553 { |
555 WQKms wqkms = (WQKms) o; | 554 WQKms wqkms = (WQKms) o; |
556 | 555 |
557 String gaugeName = wqkms.getName(); | 556 String gaugeName = wqkms.getName(); |
581 * @param wqkms data as double[][] | 580 * @param wqkms data as double[][] |
582 */ | 581 */ |
583 protected void doWQOut( | 582 protected void doWQOut( |
584 Object wqkms, | 583 Object wqkms, |
585 ArtifactAndFacet aaf, | 584 ArtifactAndFacet aaf, |
586 Document theme, | 585 ThemeDocument theme, |
587 boolean visible | 586 boolean visible |
588 ) { | 587 ) { |
589 logger.debug("FixWQCurveGenerator: doWQOut"); | 588 logger.debug("FixWQCurveGenerator: doWQOut"); |
590 if (wqkms instanceof WQKms) { | 589 if (wqkms instanceof WQKms) { |
591 // TODO As in doEventsOut, the value-searching should | 590 // TODO As in doEventsOut, the value-searching should |
607 | 606 |
608 | 607 |
609 protected void addQWSeries( | 608 protected void addQWSeries( |
610 QWI [] qws, | 609 QWI [] qws, |
611 ArtifactAndFacet aaf, | 610 ArtifactAndFacet aaf, |
612 Document theme, | 611 ThemeDocument theme, |
613 boolean visible | 612 boolean visible |
614 ) { | 613 ) { |
615 if (qws == null) { | 614 if (qws == null) { |
616 return; | 615 return; |
617 } | 616 } |
636 qw.getW()); | 635 qw.getW()); |
637 textAnnos.add(anno); | 636 textAnnos.add(anno); |
638 } | 637 } |
639 | 638 |
640 addAxisSeries(series, YAXIS.W.idx, visible); | 639 addAxisSeries(series, YAXIS.W.idx, visible); |
641 if (visible && ThemeUtil.parseShowPointLabel(theme)) { | 640 if (visible && theme.parseShowPointLabel()) { |
642 RiverAnnotation flysAnno = | 641 RiverAnnotation flysAnno = |
643 new RiverAnnotation(null, null, null, theme); | 642 new RiverAnnotation(null, null, null, theme); |
644 flysAnno.setTextAnnotations(textAnnos); | 643 flysAnno.setTextAnnotations(textAnnos); |
645 addAnnotations(flysAnno); | 644 addAnnotations(flysAnno); |
646 } | 645 } |