comparison flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java @ 2053:f9a972d375ba

Use the user defined font size to set Y axes label fonts sizes. flys-artifacts/trunk@3543 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 27 Dec 2011 08:22:07 +0000
parents c7f18fa0d685
children a653295c9ac0
comparison
equal deleted inserted replaced
2052:c7f18fa0d685 2053:f9a972d375ba
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import java.awt.BasicStroke; 3 import java.awt.BasicStroke;
4 import java.awt.Color; 4 import java.awt.Color;
5 import java.awt.Font;
5 import java.awt.Paint; 6 import java.awt.Paint;
6 import java.awt.Stroke; 7 import java.awt.Stroke;
7 import java.awt.TexturePaint; 8 import java.awt.TexturePaint;
8 9
9 import java.awt.geom.Rectangle2D; 10 import java.awt.geom.Rectangle2D;
170 protected Map<Integer, Range> xRanges; 171 protected Map<Integer, Range> xRanges;
171 172
172 /** The max Y range to include all Y values of all series for each axis. */ 173 /** The max Y range to include all Y values of all series for each axis. */
173 protected Map<Integer, Range> yRanges; 174 protected Map<Integer, Range> yRanges;
174 175
175 public static final Color DEFAULT_GRID_COLOR = Color.GRAY; 176 public static final Color DEFAULT_GRID_COLOR = Color.GRAY;
176 public static final float DEFAULT_GRID_LINE_WIDTH = 0.3f; 177 public static final float DEFAULT_GRID_LINE_WIDTH = 0.3f;
178 public static final int DEFAULT_FONT_SIZE = 12;
179 public static final String DEFAULT_FONT_NAME = "Tahoma";
177 180
178 181
179 public XYChartGenerator() { 182 public XYChartGenerator() {
180 xRanges = new HashMap<Integer, Range>(); 183 xRanges = new HashMap<Integer, Range>();
181 yRanges = new HashMap<Integer, Range>(); 184 yRanges = new HashMap<Integer, Range>();
268 ChartSettings chartSettings = getChartSettings(); 271 ChartSettings chartSettings = getChartSettings();
269 if (chartSettings != null) { 272 if (chartSettings != null) {
270 fontSize = getLegendFontSize(chartSettings); 273 fontSize = getLegendFontSize(chartSettings);
271 } 274 }
272 275
273 return fontSize != null ? fontSize : 12; 276 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
274 } 277 }
275 278
276 279
277 /** 280 /**
278 * This method is used to determine if the resulting chart should display 281 * This method is used to determine if the resulting chart should display
349 * @param pos The position of an Y axis. 352 * @param pos The position of an Y axis.
350 * 353 *
351 * @return the default Y axis label at position <i>pos</i>. 354 * @return the default Y axis label at position <i>pos</i>.
352 */ 355 */
353 protected abstract String getDefaultYAxisLabel(int pos); 356 protected abstract String getDefaultYAxisLabel(int pos);
357
358
359 /**
360 * This method returns the font size for the X axis. If the font size is
361 * specified in ChartSettings (if <i>chartSettings</i> is set), this size is
362 * returned. Otherwise the default font size 12 is returned.
363 *
364 * @return the font size for the x axis.
365 */
366 protected int getXAxisLabelFontSize() {
367 ChartSettings chartSettings = getChartSettings();
368 if (chartSettings == null) {
369 return DEFAULT_FONT_SIZE;
370 }
371
372 AxisSection as = chartSettings.getAxisSection("X");
373 Integer fontSize = as.getFontSize();
374
375 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
376 }
377
378
379 /**
380 * This method returns the font size for an Y axis. If the font size is
381 * specified in ChartSettings (if <i>chartSettings</i> is set), this size is
382 * returned. Otherwise the default font size 12 is returned.
383 *
384 * @return the font size for the x axis.
385 */
386 protected int getYAxisFontSize(int pos) {
387 ChartSettings chartSettings = getChartSettings();
388 if (chartSettings == null) {
389 return DEFAULT_FONT_SIZE;
390 }
391
392 YAxisWalker walker = getYAxisWalker();
393
394 AxisSection as = chartSettings.getAxisSection(walker.getId(pos));
395 Integer fontSize = as.getFontSize();
396
397 return fontSize != null ? fontSize : DEFAULT_FONT_SIZE;
398 }
354 399
355 400
356 /** 401 /**
357 * Generate chart. 402 * Generate chart.
358 */ 403 */
629 * Shall be overriden by subclasses. 674 * Shall be overriden by subclasses.
630 */ 675 */
631 protected NumberAxis createYAxis(int index) { 676 protected NumberAxis createYAxis(int index) {
632 YAxisWalker walker = getYAxisWalker(); 677 YAxisWalker walker = getYAxisWalker();
633 678
679 Font labelFont = new Font(
680 DEFAULT_FONT_NAME,
681 Font.BOLD,
682 getYAxisFontSize(index));
683
634 IdentifiableNumberAxis axis = new IdentifiableNumberAxis( 684 IdentifiableNumberAxis axis = new IdentifiableNumberAxis(
635 walker.getId(index), 685 walker.getId(index),
636 getYAxisLabel(index)); 686 getYAxisLabel(index));
637 687
638 axis.setAutoRangeIncludesZero(false); 688 axis.setAutoRangeIncludesZero(false);
689 axis.setLabelFont(labelFont);
690
639 return axis; 691 return axis;
640 } 692 }
641 693
642 694
643 /** 695 /**

http://dive4elements.wald.intevation.org