comparison artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java @ 8202:e4606eae8ea5

sed src/**/*.java 's/logger/log/g'
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 05 Sep 2014 12:58:17 +0200
parents c9b82ffbb7dc
children 2b0ff11cef3f
comparison
equal deleted inserted replaced
8201:4b8c5a08de04 8202:e4606eae8ea5
87 * 87 *
88 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 88 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
89 */ 89 */
90 public abstract class ChartGenerator implements OutGenerator { 90 public abstract class ChartGenerator implements OutGenerator {
91 91
92 private static Logger logger = Logger.getLogger(ChartGenerator.class); 92 private static Logger log = Logger.getLogger(ChartGenerator.class);
93 93
94 public static final int DEFAULT_CHART_WIDTH = 600; 94 public static final int DEFAULT_CHART_WIDTH = 600;
95 public static final int DEFAULT_CHART_HEIGHT = 400; 95 public static final int DEFAULT_CHART_HEIGHT = 400;
96 public static final String DEFAULT_CHART_FORMAT = "png"; 96 public static final String DEFAULT_CHART_FORMAT = "png";
97 public static final Color DEFAULT_GRID_COLOR = Color.GRAY; 97 public static final Color DEFAULT_GRID_COLOR = Color.GRAY;
161 datasets = new TreeMap<Integer, AxisDataset>(); 161 datasets = new TreeMap<Integer, AxisDataset>();
162 } 162 }
163 163
164 @Override 164 @Override
165 public void setup(Object config) { 165 public void setup(Object config) {
166 logger.debug("ChartGenerator.setup"); 166 log.debug("ChartGenerator.setup");
167 } 167 }
168 168
169 /** 169 /**
170 * Adds annotations to list. The given annotation will be visible. 170 * Adds annotations to list. The given annotation will be visible.
171 */ 171 */
210 // might stick to the second y-axis). 210 // might stick to the second y-axis).
211 // FIXME: Remove dependency to XYChartGenerator here 211 // FIXME: Remove dependency to XYChartGenerator here
212 AxisDataset dataset = getAxisDataset( 212 AxisDataset dataset = getAxisDataset(
213 new Integer(annotation.getAxisSymbol())); 213 new Integer(annotation.getAxisSymbol()));
214 if (dataset == null) { 214 if (dataset == null) {
215 logger.warn("Annotation should stick to unfindable y-axis: " 215 log.warn("Annotation should stick to unfindable y-axis: "
216 + annotation.getAxisSymbol()); 216 + annotation.getAxisSymbol());
217 rendererIndex = 0; 217 rendererIndex = 0;
218 } 218 }
219 else { 219 else {
220 rendererIndex = dataset.getPlotAxisIndex(); 220 rendererIndex = dataset.getPlotAxisIndex();
420 * Add the annotations (Sticky, Text and hyk zones) stored 420 * Add the annotations (Sticky, Text and hyk zones) stored
421 * in the annotations field. 421 * in the annotations field.
422 * @param plot Plot to add annotations to. 422 * @param plot Plot to add annotations to.
423 */ 423 */
424 protected void addAnnotationsToRenderer(XYPlot plot) { 424 protected void addAnnotationsToRenderer(XYPlot plot) {
425 logger.debug("addAnnotationsToRenderer"); 425 log.debug("addAnnotationsToRenderer");
426 426
427 if (annotations == null || annotations.isEmpty()) { 427 if (annotations == null || annotations.isEmpty()) {
428 logger.debug("addAnnotationsToRenderer: no annotations."); 428 log.debug("addAnnotationsToRenderer: no annotations.");
429 return; 429 return;
430 } 430 }
431 431
432 // OPTMIMIZE: Pre-calculate positions 432 // OPTMIMIZE: Pre-calculate positions
433 ChartArea area = new ChartArea( 433 ChartArea area = new ChartArea(
608 RiverAnnotation annotations, 608 RiverAnnotation annotations,
609 ArtifactAndFacet aandf, 609 ArtifactAndFacet aandf,
610 ThemeDocument theme, 610 ThemeDocument theme,
611 boolean visible 611 boolean visible
612 ){ 612 ){
613 logger.debug("doAnnotations"); 613 log.debug("doAnnotations");
614 614
615 // Add all annotations to our annotation pool. 615 // Add all annotations to our annotation pool.
616 annotations.setTheme(theme); 616 annotations.setTheme(theme);
617 if (aandf != null) { 617 if (aandf != null) {
618 annotations.setLabel(aandf.getFacetDescription()); 618 annotations.setLabel(aandf.getFacetDescription());
619 } 619 }
620 else { 620 else {
621 logger.error( 621 log.error(
622 "Art/Facet for Annotations is null. " + 622 "Art/Facet for Annotations is null. " +
623 "This should never happen!"); 623 "This should never happen!");
624 } 624 }
625 625
626 if (visible) { 626 if (visible) {
634 */ 634 */
635 @Override 635 @Override
636 public void generate() 636 public void generate()
637 throws IOException 637 throws IOException
638 { 638 {
639 logger.debug("ChartGenerator.generate"); 639 log.debug("ChartGenerator.generate");
640 640
641 JFreeChart chart = generateChart(); 641 JFreeChart chart = generateChart();
642 642
643 String format = getFormat(); 643 String format = getFormat();
644 int[] size = getSize(); 644 int[] size = getSize();
685 } 685 }
686 686
687 687
688 @Override 688 @Override
689 public void init(String outName, Document request, OutputStream out, CallContext context) { 689 public void init(String outName, Document request, OutputStream out, CallContext context) {
690 logger.debug("ChartGenerator.init"); 690 log.debug("ChartGenerator.init");
691 691
692 this.outName = outName; 692 this.outName = outName;
693 this.request = request; 693 this.request = request;
694 this.out = out; 694 this.out = out;
695 this.context = context; 695 this.context = context;
1299 AxisDataset axisDataset = getAxisDataset(idx); 1299 AxisDataset axisDataset = getAxisDataset(idx);
1300 1300
1301 Bounds[] xyBounds = ChartHelper.getBounds(dataset); 1301 Bounds[] xyBounds = ChartHelper.getBounds(dataset);
1302 1302
1303 if (xyBounds == null) { 1303 if (xyBounds == null) {
1304 logger.warn("Skip XYDataset for Axis (invalid ranges): " + idx); 1304 log.warn("Skip XYDataset for Axis (invalid ranges): " + idx);
1305 return; 1305 return;
1306 } 1306 }
1307 1307
1308 if (visible) { 1308 if (visible) {
1309 if (logger.isDebugEnabled()) { 1309 if (log.isDebugEnabled()) {
1310 logger.debug("Add new AxisDataset at index: " + idx); 1310 log.debug("Add new AxisDataset at index: " + idx);
1311 logger.debug("X extent: " + xyBounds[0]); 1311 log.debug("X extent: " + xyBounds[0]);
1312 logger.debug("Y extent: " + xyBounds[1]); 1312 log.debug("Y extent: " + xyBounds[1]);
1313 } 1313 }
1314 1314
1315 axisDataset.addDataset(dataset); 1315 axisDataset.addDataset(dataset);
1316 } 1316 }
1317 1317
1459 try { 1459 try {
1460 size[0] = Integer.parseInt(w); 1460 size[0] = Integer.parseInt(w);
1461 size[1] = Integer.parseInt(h); 1461 size[1] = Integer.parseInt(h);
1462 } 1462 }
1463 catch (NumberFormatException nfe) { 1463 catch (NumberFormatException nfe) {
1464 logger.warn("Wrong values for chart width/height."); 1464 log.warn("Wrong values for chart width/height.");
1465 } 1465 }
1466 } 1466 }
1467 } 1467 }
1468 1468
1469 return size[0] > 0 && size[1] > 0 ? size : null; 1469 return size[0] > 0 && size[1] > 0 ? size : null;
1557 * datasets is mapped to a specific axis as well. 1557 * datasets is mapped to a specific axis as well.
1558 * 1558 *
1559 * @param plot plot to add datasets to. 1559 * @param plot plot to add datasets to.
1560 */ 1560 */
1561 protected void addDatasets(XYPlot plot) { 1561 protected void addDatasets(XYPlot plot) {
1562 logger.debug("addDatasets()"); 1562 log.debug("addDatasets()");
1563 1563
1564 // AxisDatasets are sorted, but some might be empty. 1564 // AxisDatasets are sorted, but some might be empty.
1565 // Thus, generate numbering on the fly. 1565 // Thus, generate numbering on the fly.
1566 int axisIndex = 0; 1566 int axisIndex = 0;
1567 int datasetIndex = 0; 1567 int datasetIndex = 0;
1629 * @param plot The plot. 1629 * @param plot The plot.
1630 * @param dataset The XYDataset which needs to support Series objects. 1630 * @param dataset The XYDataset which needs to support Series objects.
1631 * @param idx The index of the renderer / dataset. 1631 * @param idx The index of the renderer / dataset.
1632 */ 1632 */
1633 protected void applyLineTheme(XYPlot plot, XYDataset dataset, int idx) { 1633 protected void applyLineTheme(XYPlot plot, XYDataset dataset, int idx) {
1634 logger.debug("Apply LineTheme for dataset at index: " + idx); 1634 log.debug("Apply LineTheme for dataset at index: " + idx);
1635 1635
1636 LegendItemCollection lic = new LegendItemCollection(); 1636 LegendItemCollection lic = new LegendItemCollection();
1637 LegendItemCollection anno = plot.getFixedLegendItems(); 1637 LegendItemCollection anno = plot.getFixedLegendItems();
1638 1638
1639 Font legendFont = createLegendLabelFont(); 1639 Font legendFont = createLegendLabelFont();
1664 if (legendItem != null) { 1664 if (legendItem != null) {
1665 legendItem.setLabelFont(legendFont); 1665 legendItem.setLabelFont(legendFont);
1666 lic.add(legendItem); 1666 lic.add(legendItem);
1667 } 1667 }
1668 else { 1668 else {
1669 logger.warn("Could not get LegentItem for renderer: " 1669 log.warn("Could not get LegentItem for renderer: "
1670 + idx + ", series-idx " + s); 1670 + idx + ", series-idx " + s);
1671 } 1671 }
1672 } 1672 }
1673 1673
1674 if (anno != null) { 1674 if (anno != null) {
1694 LegendItemCollection lic = new LegendItemCollection(); 1694 LegendItemCollection lic = new LegendItemCollection();
1695 LegendItemCollection anno = plot.getFixedLegendItems(); 1695 LegendItemCollection anno = plot.getFixedLegendItems();
1696 1696
1697 Font legendFont = createLegendLabelFont(); 1697 Font legendFont = createLegendLabelFont();
1698 1698
1699 logger.debug("Registering an 'area'renderer at idx: " + idx); 1699 log.debug("Registering an 'area'renderer at idx: " + idx);
1700 1700
1701 StableXYDifferenceRenderer dRenderer = 1701 StableXYDifferenceRenderer dRenderer =
1702 new StableXYDifferenceRenderer(); 1702 new StableXYDifferenceRenderer();
1703 1703
1704 if (area.getMode() == StyledAreaSeriesCollection.FILL_MODE.UNDER) { 1704 if (area.getMode() == StyledAreaSeriesCollection.FILL_MODE.UNDER) {
1719 if (legendItem != null) { 1719 if (legendItem != null) {
1720 legendItem.setLabelFont(legendFont); 1720 legendItem.setLabelFont(legendFont);
1721 lic.add(legendItem); 1721 lic.add(legendItem);
1722 } 1722 }
1723 else { 1723 else {
1724 logger.warn("Could not get LegentItem for renderer: " 1724 log.warn("Could not get LegentItem for renderer: "
1725 + idx + ", series-idx " + 0); 1725 + idx + ", series-idx " + 0);
1726 } 1726 }
1727 1727
1728 if (anno != null) { 1728 if (anno != null) {
1729 lic.addAll(anno); 1729 lic.addAll(anno);
1760 * @param idx This value is not used in the current implementation. 1760 * @param idx This value is not used in the current implementation.
1761 * 1761 *
1762 * @return a new instance of EnhancedLineAndShapeRenderer. 1762 * @return a new instance of EnhancedLineAndShapeRenderer.
1763 */ 1763 */
1764 protected XYLineAndShapeRenderer createRenderer(XYPlot plot, int idx) { 1764 protected XYLineAndShapeRenderer createRenderer(XYPlot plot, int idx) {
1765 logger.debug("Create EnhancedLineAndShapeRenderer for idx: " + idx); 1765 log.debug("Create EnhancedLineAndShapeRenderer for idx: " + idx);
1766 1766
1767 EnhancedLineAndShapeRenderer r = 1767 EnhancedLineAndShapeRenderer r =
1768 new EnhancedLineAndShapeRenderer(true, false); 1768 new EnhancedLineAndShapeRenderer(true, false);
1769 1769
1770 r.setPlot(plot); 1770 r.setPlot(plot);

http://dive4elements.wald.intevation.org