# HG changeset patch # User Ingo Weinzierl # Date 1324972345 0 # Node ID 4ba5036109d223215e840888d300afeee72338d7 # Parent c4e0e433f825b36d4dcd71172c5011e2d3d05e2d Make use of user defined axes labels during chart creation. flys-artifacts/trunk@3541 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Dec 27 07:52:25 2011 +0000 @@ -1,3 +1,23 @@ +2011-12-27 Ingo Weinzierl + + * src/main/java/de/intevation/flys/exports/AxisSection.java: Added + getLabel() to retrieve the axis label. + + * src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java, + src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java, + src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java: + Override getDefaultXAxisLabel() and getDefaultYAxisLabel() defined in + XYChartGenerator. + + * src/main/java/de/intevation/flys/exports/XYChartGenerator.java: Implement + getXAxisLabel() and getYAxisLabel(int). Both methods search for an axis + label defined in the ChartSettings first. If no label is specified or if + no ChartSettings is set, getDefaultXAxisLabel() or + getDefaultYAxisLabel(int) is called to retrieve the initial/default axis + label. + 2011-12-27 Ingo Weinzierl * src/main/java/de/intevation/flys/exports/ChartSettings.java: Modified the diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/AxisSection.java Tue Dec 27 07:52:25 2011 +0000 @@ -66,6 +66,12 @@ } + public String getLabel() { + StringAttribute attr = (StringAttribute) getAttribute(LABEL_ATTR); + return attr != null ? (String) attr.getValue() : null; + } + + public void setFontSize(int fontSize) { if (fontSize <= 0) { return; diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/ComputedDischargeCurveGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -87,7 +87,7 @@ @Override - protected String getYAxisLabel() { + protected String getDefaultYAxisLabel(int pos) { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/CrossSectionGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -95,9 +95,6 @@ } - /** - * Add localized subtitle to chart. - */ @Override protected void addSubtitles(JFreeChart chart) { String subtitle = getChartSubtitle(); @@ -105,18 +102,14 @@ } - /** - * Get localized X Axis label. - */ - protected String getXAxisLabel() { + @Override + protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } - /** - * Get localized Y Axis label. - */ - protected String getYAxisLabel() { + @Override + protected String getDefaultYAxisLabel(int pos) { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DischargeCurveGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -100,17 +100,13 @@ } - /** - * i18n-Label for X-Axis. - */ - protected String getXAxisLabel() { + @Override + protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } - /** - * i18n-Label for X-Axis (W). - */ - protected String getYAxisLabel() { + @Override + protected String getDefaultYAxisLabel(int pos) { return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } @@ -136,7 +132,7 @@ Font labelFont = new Font("Tahoma", Font.BOLD, 14); String label = "default"; if (index == YAXIS.W.idx) { - label = getYAxisLabel(); + label = getYAxisLabel(0); } NumberAxis axis = createNumberAxis(index, label); axis.setLabelFont(labelFont); diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/DurationCurveGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -125,22 +125,16 @@ @Override - protected String getXAxisLabel() { + protected String getDefaultXAxisLabel() { return msg(I18N_XAXIS_LABEL, I18N_XAXIS_LABEL_DEFAULT); } @Override - protected String getYAxisLabel() { - return msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); - } - - - @Override - protected String getYAxisLabel(int index) { + protected String getDefaultYAxisLabel(int index) { String label = "default"; if (index == YAXIS.W.idx) { - label = getYAxisLabel(); + label = msg(I18N_YAXIS_LABEL, I18N_YAXIS_LABEL_DEFAULT); } else if (index == YAXIS.Q.idx) { // TODO i18n for this label diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -182,7 +182,8 @@ /** * Get internationalized label for the x axis. */ - protected String getXAxisLabel() { + @Override + protected String getDefaultXAxisLabel() { FLYSArtifact flys = (FLYSArtifact) master; return msg( @@ -193,10 +194,23 @@ @Override - protected String getYAxisLabel() { - return getWAxisLabel(); + protected String getDefaultYAxisLabel(int index) { + String label = "default"; + + if (index == YAXIS.W.idx) { + label = getWAxisLabel(); + } + else if (index == YAXIS.Q.idx) { + label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); + } + else if (index == YAXIS.D.idx) { + label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); + } + + return label; } + /** * Get internationalized label for the y axis. */ @@ -234,23 +248,6 @@ } - protected String getYAxisLabel(int index) { - String label = "default"; - - if (index == YAXIS.W.idx) { - label = getWAxisLabel(); - } - else if (index == YAXIS.Q.idx) { - label = msg(getQAxisLabelKey(), getQAxisDefaultLabel()); - } - else if (index == YAXIS.D.idx) { - label = msg(I18N_WDIFF_YAXIS_LABEL, I18N_WDIFF_YAXIS_LABEL_DEFAULT); - } - - return label; - } - - /** * Get default value for the second Y-Axis' label (if no translation was * found). diff -r c4e0e433f825 -r 4ba5036109d2 flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java --- a/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 07:17:07 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/XYChartGenerator.java Tue Dec 27 07:52:25 2011 +0000 @@ -290,15 +290,31 @@ * * @return the X-Axis label of a chart. */ - protected abstract String getXAxisLabel(); + protected String getXAxisLabel() { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultXAxisLabel(); + } + + AxisSection as = chartSettings.getAxisSection("X"); + if (as != null) { + String label = as.getLabel(); + + if (label != null) { + return label; + } + } + + return getDefaultXAxisLabel(); + } /** - * Returns the Y-Axis label of a chart. + * Returns the default X-Axis label of a chart. * - * @return the Y-Axis label of a chart. + * @return the default X-Axis label of a chart. */ - protected abstract String getYAxisLabel(); + protected abstract String getDefaultXAxisLabel(); /** @@ -307,9 +323,36 @@ * @return the Y-Axis label of a chart at position 0. */ protected String getYAxisLabel(int pos) { - return getYAxisLabel(); + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultYAxisLabel(pos); + } + + YAxisWalker walker = getYAxisWalker(); + AxisSection as = chartSettings.getAxisSection(walker.getId(pos)); + if (as != null) { + String label = as.getLabel(); + + if (label != null) { + return label; + } + } + + return getDefaultYAxisLabel(pos); } + + /** + * This method is called to retrieve the default label for an Y axis at + * position pos. + * + * @param pos The position of an Y axis. + * + * @return the default Y axis label at position pos. + */ + protected abstract String getDefaultYAxisLabel(int pos); + + /** * Generate chart. */ @@ -370,7 +413,7 @@ JFreeChart chart = ChartFactory.createXYLineChart( getChartTitle(), getXAxisLabel(), - getYAxisLabel(), + getYAxisLabel(0), null, PlotOrientation.VERTICAL, isLegendVisible(), @@ -586,7 +629,7 @@ * Shall be overriden by subclasses. */ protected NumberAxis createYAxis(int index) { - NumberAxis axis = new NumberAxis(getYAxisLabel()); + NumberAxis axis = new NumberAxis(getYAxisLabel(index)); axis.setAutoRangeIncludesZero(false); return axis; }