Mercurial > dive4elements > river
changeset 1700:13a9ee6cebef
Fix most labels in w-diff diagrams; refactoring to allow easier adoption of
labels in LongitudinalSectionGenerator subclasses.
flys-artifacts/trunk@2934 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 11 Oct 2011 10:44:12 +0000 (2011-10-11) |
parents | 608859aa5a7e |
children | 6e59208839ae |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java |
diffstat | 3 files changed, 118 insertions(+), 55 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Oct 11 10:38:54 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Oct 11 10:44:12 2011 +0000 @@ -1,3 +1,13 @@ +2011-10-11 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Fix most labels in w-differences charts. + + * src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java, + src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java: + Remove most static final i18n-variables in favor of direct String + usage or usage of methods. By this, allow easier adoption of labels + in subclasses. + 2011-10-11 Ingo Weinzierl <ingo@intevation.de> flys/issue383 (Zweite Y-Achse wird beim Zoomen/Verschieben nicht angepasst.)
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Tue Oct 11 10:38:54 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/LongitudinalSectionGenerator.java Tue Oct 11 10:44:12 2011 +0000 @@ -42,30 +42,11 @@ private static Logger logger = Logger.getLogger(LongitudinalSectionGenerator.class); - public static final String I18N_CHART_TITLE = - "chart.longitudinal.section.title"; - + /** Key to look up internationalized String for annotations label. */ public static final String I18N_ANNOTATIONS_LABEL = "chart.longitudinal.annotations.label"; - public static final String I18N_CHART_SUBTITLE = - "chart.longitudinal.section.subtitle"; - - public static final String I18N_XAXIS_LABEL = - "chart.longitudinal.section.xaxis.label"; - - public static final String I18N_YAXIS_LABEL = - "chart.longitudinal.section.yaxis.label"; - - public static final String I18N_2YAXIS_LABEL = - "chart.longitudinal.section.yaxis.second.label"; - - public static final String I18N_CHART_TITLE_DEFAULT = "W-L\u00e4ngsschnitt"; - public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; - public static final String I18N_YAXIS_LABEL_DEFAULT = "W [NN + m]"; - public static final String I18N_2YAXIS_LABEL_DEFAULT = "Q [m\u00b3/s]"; - - + /** Whether or not the plot is inverted (left-right). */ protected boolean inverted; @@ -74,60 +55,108 @@ } - protected String getChartTitle() { - return msg(I18N_CHART_TITLE, I18N_CHART_TITLE_DEFAULT); - } - public boolean isInverted() { return inverted; } + public void setInverted(boolean inverted) { this.inverted = inverted; } + + /** + * Get internationalized title for chart. + */ + public String getChartTitle() { + return msg("chart.longitudinal.section.title", "W-L\u00e4ngsschnitt"); + } + + + /** + * Gets key to look up internationalized String for the charts subtitle. + * @return key to look up translated subtitle. + */ + protected String getChartSubtitleKey() { + return "chart.longitudinal.section.subtitle"; + } + + + /** + * Add (internationalized) subtitle to chart. + * @see getChartSubtitleKey + */ @Override protected void addSubtitles(JFreeChart chart) { - double[] dist = getRange(); - + double[] dist = getRange(); Object[] args = new Object[] { getRiverName(), dist[0], dist[1] }; - String subtitle = msg(I18N_CHART_SUBTITLE, "", args); + String subtitle = msg(getChartSubtitleKey(), "", args); chart.addSubtitle(new TextTitle(subtitle)); } + /** + * Get internationalized label for the x axis. + */ protected String getXAxisLabel() { FLYSArtifact flys = (FLYSArtifact) master; return msg( - I18N_XAXIS_LABEL, - I18N_XAXIS_LABEL_DEFAULT, + "chart.longitudinal.section.xaxis.label", + "km", new Object[] { FLYSUtils.getRiver(flys).getName() }); } + /** + * Get internationalized label for the y axis. + */ protected String getYAxisLabel() { FLYSArtifact flys = (FLYSArtifact) master; String unit = FLYSUtils.getRiver(flys).getWstUnit().getName(); return msg( - I18N_YAXIS_LABEL, - I18N_YAXIS_LABEL_DEFAULT, + "chart.longitudinal.section.yaxis.label", + "W [NN + m]", new Object[] { unit }); } + /** + * Get default value for the second Y-Axis' label (if no translation was + * found). + */ + protected String get2YAxisDefaultLabel() { + return "Q [m\u00b3/s]"; + } + + + /** + * Get key for internationalization of the second Y-Axis' label. + */ + protected String get2YAxisLabelKey() { + return "chart.longitudinal.section.yaxis.second.label"; + } + + + /** + * Adjust the axis to meet LongitudinalSection diagram demands. + * (e.g. add second Y-axis with internationalized label, trigger + * inversion). + * @param see get2YAxisLabelKey, get2YAxisDefaultLabel + */ + @Override protected void adjustAxes(XYPlot plot) { super.adjustAxes(plot); NumberAxis qAxis = new NumberAxis( - msg(I18N_2YAXIS_LABEL, I18N_2YAXIS_LABEL_DEFAULT)); + msg(get2YAxisLabelKey(), get2YAxisDefaultLabel())); plot.setRangeAxis(1, qAxis);
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Tue Oct 11 10:38:54 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/WDifferencesCurveGenerator.java Tue Oct 11 10:44:12 2011 +0000 @@ -21,7 +21,7 @@ import de.intevation.flys.utils.DataUtil; import de.intevation.flys.artifacts.model.WQKms; - +import de.intevation.flys.utils.FLYSUtils; /** @@ -35,33 +35,57 @@ private static Logger logger = Logger.getLogger(WDifferencesCurveGenerator.class); - public static final String I18N_CHART_TITLE = - "chart.w_differences.title"; - - public static final String I18N_CHART_SUBTITLE = - "chart.w_differences.subtitle"; - public static final String I18N_YAXIS_LABEL = - "chart.w_differences.yaxis.label"; - - public static final String I18N_2YAXIS_LABEL = - "chart.w_differences.yaxis.second.label"; - - // TODO proper i18n. - public static final String I18N_CHART_TITLE_DEFAULT = "W-Differenzen"; - public static final String I18N_XAXIS_LABEL_DEFAULT = "km"; - public static final String I18N_YAXIS_LABEL_DEFAULT = "W [m]"; - public static final String I18N_2YAXIS_LABEL_DEFAULT = "W [NN + m]"; + /** + * Get internationalized title for chart. + */ + public String getChartTitle() { + return msg("chart.w_differences.title", "Differences"); + } /** - * Add a subtitle to Chart. - * @param chart Chart to add subtitle to. + * Get default value for the second Y-Axis' label (if no translation was + * found). */ @Override - protected void addSubtitles(JFreeChart chart) { - String subtitle = msg(I18N_CHART_SUBTITLE, ""); - chart.addSubtitle(new TextTitle(subtitle)); + protected String get2YAxisDefaultLabel() { + return "W [NN + m]"; + } + + + /** + * Gets key to look up internationalized String for the charts subtitle. + * @return key to look up translated subtitle. + */ + @Override + protected String getChartSubtitleKey() { + return "chart.w_differences.subtitle"; + } + + + /** + * Get key for internationalization of the second Y-Axis' label. + */ + @Override + protected String get2YAxisLabelKey() { + return "chart.w_differences.yaxis.second.label"; + } + + + /** + * Get internationalized label for the y axis. + */ + @Override + protected String getYAxisLabel() { + FLYSArtifact flys = (FLYSArtifact) master; + + String unit = FLYSUtils.getRiver(flys).getWstUnit().getName(); + + return msg( + "chart.w_differences.yaxis.label", + "m", + new Object[] { unit }); }