Mercurial > dive4elements > river
changeset 7084:f0731aa7b735 generator-refactoring
Implement Label handling
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Fri, 20 Sep 2013 19:18:04 +0200 |
parents | 74ebe5e7fa69 |
children | ceec5b6541e8 |
files | artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java |
diffstat | 7 files changed, 106 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 19:18:04 2013 +0200 @@ -204,12 +204,7 @@ */ protected abstract String getDefaultChartTitle(); - /** - * Returns the default Y-Axis label of a chart. - * - * @return the default Y-Axis label of a chart. - */ - protected abstract String getDefaultYAxisLabel(int index); + protected abstract String getDefaultYAxisLabel(String axisName); /** @@ -345,7 +340,7 @@ } - InfoGeneratorHelper helper = new InfoGeneratorHelper(this); + InfoGeneratorHelper2 helper = new InfoGeneratorHelper2(this); Document doc = helper.createInfoDocument(chart, info); XMLUtils.toStream(doc, out); @@ -903,33 +898,7 @@ return new int[] { 600, 400 }; } - - /** - * Returns the Y-Axis label of a chart at position <i>pos</i>. - * - * @return the Y-Axis label of a chart at position <i>0</i>. - */ - protected String getYAxisLabel(int pos) { - return "TODO lalal"; - /* - 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);*/ - } - + protected abstract String getYAxisLabel(String axisName); /** * This method searches for a specific axis in the <i>settings</i> if @@ -1086,7 +1055,7 @@ * @param def default, returned if lookup failed. * @return value found in i18n dictionary, \param def if no value found. */ - protected String msg(String key, String def) { + public String msg(String key, String def) { return Resources.getMsg(context.getMeta(), key, def); } @@ -1095,11 +1064,11 @@ * @param key key for which to find i18nd version. * @return value found in i18n dictionary, key itself if failed. */ - protected String msg(String key) { + public String msg(String key) { return Resources.getMsg(context.getMeta(), key, key); } - protected String msg(String key, String def, Object[] args) { + public String msg(String key, String def, Object[] args) { return Resources.getMsg(context.getMeta(), key, def, args); } @@ -1484,9 +1453,10 @@ Font.BOLD, getYAxisFontSize(index)); + String axisName = axisIndexToName(index); + IdentifiableNumberAxis axis = new IdentifiableNumberAxis( - axisIndexToName(index), - getYAxisLabel(index)); + axisName, getYAxisLabel(axisName)); axis.setAutoRangeIncludesZero(false); axis.setLabelFont(labelFont);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramAttributes.java Fri Sep 20 19:18:04 2013 +0200 @@ -285,6 +285,15 @@ return -1; } + public Processor getProcessorForAxisName(String axisName) { + for (Processor pr: processors) { + if (pr.getAxisName().equals(axisName)) { + return pr; + } + } + return null; + } + public String getAxisName(int index) { AxisAttributes att = axesAttrs.get(index); if (att == null) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DiagramGenerator.java Fri Sep 20 19:18:04 2013 +0200 @@ -118,8 +118,8 @@ JFreeChart chart = ChartFactory.createXYLineChart( getChartTitle(), - getXAxisLabel(), - getYAxisLabel(0), + "", + "", null, PlotOrientation.VERTICAL, isLegendVisible(), @@ -173,6 +173,9 @@ return chart; } + public String getOutName() { + return outName; + } /** * Return left most data points x value (on first axis). @@ -1021,31 +1024,18 @@ */ @Override protected String getDefaultXAxisLabel() { - return "TODO X axis label"; -/* D4EArtifact flys = (D4EArtifact) master; + DiagramAttributes.Title dTitle = diagramAttributes.getDomainAxisTitle(); + if (dTitle == null) { + return "Domain Axis Title not configured in conf.xml"; + } - return msg( - I18N_XAXIS_LABEL, - I18N_XAXIS_LABEL_DEFAULT, - new Object[] { RiverUtils.getRiver(flys).getName() }); */ + return dTitle.evaluate((D4EArtifact)getMaster(), context); } @Override - protected String getDefaultYAxisLabel(int index) { - return "TODO Y Axis label"; -/* 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;*/ + protected String getDefaultYAxisLabel(String axisName) { + Processor pr = diagramAttributes.getProcessorForAxisName(axisName); + return pr == null ? "" : pr.getAxisLabel(this); } @@ -1061,8 +1051,9 @@ for (int i = 0, n = axesAttrs.size(); i < n; i++) { AxisSection ySection = new AxisSection(); - ySection.setIdentifier(diagramAttributes.getAxisName(i)); - ySection.setLabel(getYAxisLabel(i)); + String axisName = diagramAttributes.getAxisName(i); + ySection.setIdentifier(axisName); + ySection.setLabel(getYAxisLabel(axisName)); ySection.setFontSize(14); ySection.setFixed(false); @@ -1079,6 +1070,27 @@ return axisSections; } + /** + * Returns the Y-Axis label of a chart at position <i>pos</i>. + * + * @return the Y-Axis label of a chart at position <i>0</i>. + */ + protected String getYAxisLabel(String axisName) { + ChartSettings chartSettings = getChartSettings(); + if (chartSettings == null) { + return getDefaultYAxisLabel(axisName); + } + AxisSection as = chartSettings.getAxisSection(axisName); + if (as != null) { + String label = as.getLabel(); + if (label != null) { + return label; + } + } + + return getDefaultYAxisLabel(axisName); + } + protected String axisIndexToName(int index) { return diagramAttributes.getAxisName(index); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/DefaultProcessor.java Fri Sep 20 19:18:04 2013 +0200 @@ -55,6 +55,12 @@ return; } + @Override + public String getAxisLabel(DiagramGenerator generator) { + return "Please overwrite me in the implementation"; + } + + /** * Returns true if the Processor class is able to generate output for a facet type *
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/Processor.java Fri Sep 20 19:18:04 2013 +0200 @@ -12,6 +12,8 @@ import org.dive4elements.river.exports.XYChartGenerator; import org.dive4elements.river.themes.ThemeDocument; import org.dive4elements.river.exports.DiagramGenerator; +import org.dive4elements.river.artifacts.D4EArtifact; +import org.dive4elements.artifacts.CallContext; /** * A processor is intended to generate an output e.g. curve in a chart diagramm from @@ -36,6 +38,13 @@ public String getAxisName(); /** + * Get the axis label for this processor. + * + * @return The label of the axis. + */ + public String getAxisLabel(DiagramGenerator generator); + + /** * Processes data to generate e.g. a chart. * * @param generator XYChartGenerator to add output on.
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/QOutProcessor.java Fri Sep 20 19:18:04 2013 +0200 @@ -31,6 +31,12 @@ */ public class QOutProcessor extends DefaultProcessor { + public static final String I18N_LONGITUDINAL_LABEL = + "chart.longitudinal.section.yaxis.second.label"; + + public static final String + I18N_LONGITUDINAL_LABEL_DEFAULT = "Q [m\u00b3/s]"; + /** Private logger. */ private static final Logger logger = Logger.getLogger(QOutProcessor.class); @@ -75,6 +81,15 @@ generator.setInverted(wqkms.guessRTLData()); } + @Override + public String getAxisLabel(DiagramGenerator generator) { + if (generator.getOutName().startsWith("longitudinal_section")) { + return generator.msg(I18N_LONGITUDINAL_LABEL, + I18N_LONGITUDINAL_LABEL_DEFAULT); + } + return "Please overwrite me in the implementation"; + } + /** * Returns true if facettype is q-type. */
--- a/artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java Fri Sep 20 19:17:49 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/process/WOutProcessor.java Fri Sep 20 19:18:04 2013 +0200 @@ -13,6 +13,7 @@ import org.dive4elements.artifactdatabase.state.ArtifactAndFacet; import org.dive4elements.artifacts.CallContext; +import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.model.FacetTypes; import org.dive4elements.river.artifacts.model.WKms; import org.dive4elements.river.exports.StyledSeriesBuilder; @@ -22,6 +23,7 @@ import org.dive4elements.river.jfree.StyledXYSeries; import org.dive4elements.river.themes.ThemeDocument; import org.dive4elements.river.utils.DataUtil; +import org.dive4elements.river.utils.RiverUtils; /** * Add data to chart/generator. @@ -34,6 +36,11 @@ private static final Logger logger = Logger.getLogger(WOutProcessor.class); + public static final String I18N_AXIS_LABEL = + "chart.longitudinal.section.yaxis.label"; + + public static final String I18N_AXIS_LABEL_DEFAULT = "W [NN + m]"; + @Override public void doOut( DiagramGenerator generator, @@ -120,6 +127,20 @@ } } + @Override + public String getAxisLabel(DiagramGenerator generator) { + D4EArtifact flys = (D4EArtifact) generator.getMaster(); + + String unit = RiverUtils.getRiver(flys).getWstUnit().getName(); + + logger.debug("HALLO ANDRE LABEL"); + + return generator.msg( + I18N_AXIS_LABEL, + I18N_AXIS_LABEL_DEFAULT, + new Object[] { unit }); + } + /** * Returns true if facettype is longitutinal_section.w . */