# HG changeset patch # User Ingo Weinzierl # Date 1259940620 0 # Node ID 1c427acb6c76243e4e5f3e7b73eb2a703786fff7 # Parent 477c0c46605e9a58e680d00b14d76d71be9a8306 Added subtitles to charts. gnv-artifacts/trunk@397 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/ressource/RessourceFactory.java Fri Dec 04 15:30:20 2009 +0000 @@ -147,15 +147,25 @@ return defaultValue; } + return getRessource(preferredLocales[0].getLocale(), key, defaultValue); + } + + + public String getRessource(Locale locale, String key, String defaultVal) { + if (key == null || locale == null) + return defaultVal; + try { - ResourceBundle rb = ResourceBundle.getBundle(ressourceDir + "/" - + ressourceName, - preferredLocales[0].getLocale()); + ResourceBundle rb = ResourceBundle.getBundle( + ressourceDir + "/" + ressourceName, + locale + ); return rb.getString(key); - } catch (MissingResourceException mre) { - log.warn(mre.getLocalizedMessage()); - return defaultValue; + } + catch (MissingResourceException mre) { + log.warn("No resource bundle: " + locale.toString(), mre); + return defaultVal; } } } diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/AbstractXYLineChart.java Fri Dec 04 15:30:20 2009 +0000 @@ -18,6 +18,7 @@ import org.jfree.chart.plot.PlotOrientation; import org.jfree.chart.plot.XYPlot; import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer; +import org.jfree.chart.title.TextTitle; import org.jfree.data.general.Series; import de.intevation.gnv.geobackend.base.Result; @@ -65,6 +66,8 @@ false ); + chart.addSubtitle(new TextTitle(labels.getSubtitle())); + theme.apply(chart); initData(); diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/chart/ChartLabels.java Fri Dec 04 15:30:20 2009 +0000 @@ -21,6 +21,12 @@ * */ private String title; + + /** + * + */ + private String subtitle; + /** * */ @@ -32,8 +38,9 @@ * @param title * @param domainAxisLabel */ - public ChartLabels(String title, String domainAxisLabel) { - this.title = title; + public ChartLabels(String title, String subtitle, String domainAxisLabel) { + this.title = title; + this.subtitle = subtitle; this.domainAxisLabel = domainAxisLabel; } @@ -44,10 +51,18 @@ return this.title; } + + /** + * @return the subtitle + */ + public String getSubtitle() { + return subtitle; + } + /** * @return the timeAxisLabel */ public String getDomainAxisLabel() { return this.domainAxisLabel; } -} \ No newline at end of file +} diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/OutputTransitionBase.java Fri Dec 04 15:30:20 2009 +0000 @@ -6,6 +6,7 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; +import java.util.Locale; import org.apache.log4j.Logger; @@ -17,6 +18,7 @@ import de.intevation.artifactdatabase.Config; import de.intevation.artifacts.CallMeta; import de.intevation.gnv.artifacts.cache.CacheFactory; +import de.intevation.gnv.artifacts.ressource.RessourceFactory; import de.intevation.gnv.geobackend.base.Result; import de.intevation.gnv.geobackend.base.query.QueryExecutor; import de.intevation.gnv.geobackend.base.query.QueryExecutorFactory; @@ -259,7 +261,13 @@ OutputStream outputStream, String uuid, CallMeta callMeta) throws TransitionException { } - - + + protected String getMessage(Locale locale, String key, String value) { + return RessourceFactory.getInstance().getRessource( + locale, + key, + value + ); + } } diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/horizontal/HorizontalProfileOutputTransition.java Fri Dec 04 15:30:20 2009 +0000 @@ -3,10 +3,17 @@ */ package de.intevation.gnv.transition.profile.horizontal; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.io.WKTReader; +import com.vividsolutions.jts.io.ParseException; + import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; +import java.text.SimpleDateFormat; import java.util.Collection; +import java.util.Date; +import java.util.Iterator; import java.util.Locale; import org.apache.log4j.Logger; @@ -24,6 +31,7 @@ import de.intevation.gnv.exports.ShapeDataCollector; import de.intevation.gnv.exports.DefaultProfile; import de.intevation.gnv.exports.Export.Profile; +import de.intevation.gnv.transition.describedata.KeyValueDescibeData; /** * @author Tim Englich @@ -39,6 +47,21 @@ private static Logger log = Logger .getLogger(HorizontalProfileOutputTransition.class); + public static final String DATE_FORMAT = "yyyy.MM.dd HH:mm:ss"; + + public static final String [] CHART_TITLE_META = { + "CRUISE", + "DEPTH", + "SHAPE" + }; + + + public static final String [] CHART_TITLE_META_RESSOURCES = { + "cruiseid", + "depth", + "coordinate" + }; + public static final String [] TIMESERIES_CSV_PROFILE_NAMES = { "SHAPE", "YORDINATE", @@ -132,4 +155,131 @@ export.create(TIMESERIES_CSV_PROFILE, outputStream, chartResult); } + + + protected String createChartTitle(Locale locale, String uuid) { + String fisName = getFisName(locale); + log.debug("created title for horizontal profile chart: " + fisName); + + return fisName; + } + + + protected String createChartSubtitle(Locale locale, String uuid) { + log.debug("create chart subtitle."); + String subtitle = createTimePeriod(locale, uuid); + + // ODV results contain meta information about cruise, station and so on + Collection results = getODVResult(uuid); + if (results != null) { + Iterator iter = results.iterator(); + Result result = iter.hasNext() ? (Result) iter.next() : null; + + subtitle += subtitle.length() != 0 ? "\n" : ""; + subtitle += createMetaChartSubtitle(locale, result); + } + + return subtitle; + } + + + protected String createMetaChartSubtitle(Locale locale, Result result) { + log.debug("Fetch meta information and put it into subtitle."); + if (result == null) + return ""; + + StringBuilder meta = new StringBuilder(); + WKTReader wktReader = new WKTReader(); + + + for (int i = 0; i < CHART_TITLE_META.length; i++) { + String qry = CHART_TITLE_META[i]; + + if (qry.equals("SHAPE")) { + try { + Point p = (Point) wktReader.read(result.getString(qry)); + + meta.append(getMessage(locale,"coordinate","coordinate")); + meta.append(": "); + + log.debug( + "Add " + qry + " to meta information of subtitle: " + + p.toString() + ); + meta.append(p.getX() + ", " + p.getY()); + } + catch (ParseException pe) { + log.warn("Error while parsing point.", pe); + } + } + else { + log.debug( + "Add " + qry + " to meta information of subtitle: " + + result.getString(qry) + ); + meta.append(getMessage( + locale, + CHART_TITLE_META_RESSOURCES[i], + CHART_TITLE_META_RESSOURCES[i] + )); + meta.append(": "); + meta.append(result.getString(qry)); + } + + if (i != CHART_TITLE_META.length-1) + meta.append("\n"); + } + + log.debug("Meta title for chart: " + meta.toString()); + return meta.toString(); + } + + + protected String createTimePeriod(Locale locale, String uuid) { + log.debug("create time period for chart subtitle."); + String subTitle = null; + Date startDate = null; + Date endDate = null; + + Collection dates = getDates(uuid); + if (dates == null) { + log.debug("No time period for subtitle."); + return ""; + } + + SimpleDateFormat format = new SimpleDateFormat(DATE_FORMAT); + KeyValueDescibeData data = null; + + Iterator iter = dates.iterator(); + while (iter.hasNext()) { + try { + data = (KeyValueDescibeData)iter.next(); + + if (!data.isSelected()) + continue; + + Date current = format.parse(data.getValue()); + long time = current.getTime(); + + if (startDate == null) { + startDate = current; + endDate = current; + } + else if (time < startDate.getTime()) { + startDate = current; + } + else if (time > endDate.getTime()) { + endDate = current; + } + } + catch (java.text.ParseException pe) { + log.warn("Error while parsing date: " + data.getValue(), pe); + } + } + + subTitle = format.format(startDate) + " - " + format.format(endDate); + log.debug("created title for horizontal profile chart: " + subTitle); + + return subTitle; + } } diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/profile/vertical/VerticalProfileOutputTransition.java Fri Dec 04 15:30:20 2009 +0000 @@ -83,6 +83,11 @@ } + protected String createChartSubtitle(Locale locale, String uuid) { + return getSelectedFeatureName(uuid); + } + + /** * @see de.intevation.gnv.transition.timeseries.TimeSeriesOutputTransition#getStatisticsGenerator() diff -r 477c0c46605e -r 1c427acb6c76 gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Fri Dec 04 09:04:10 2009 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/transition/timeseries/TimeSeriesOutputTransition.java Fri Dec 04 15:30:20 2009 +0000 @@ -210,17 +210,6 @@ log.error(e, e); throw new TransitionException(e); } - Collection parameters = this.getParameters(uuid); - Collection measurements = this.getMeasurements(uuid); - Collection dates = this.getDates(uuid); - ChartLabels chartLables = new ChartLabels(this.getFisName(callMeta.getLanguages())+" "+this - .getSelectedFeatureName(uuid), this.domainLable); - - String exportFormat = getExportFormat(mimeType); - - // TODO Remove this and parse input data - boolean linesVisible = true; - boolean shapesVisible = true; PreferredLocale[] locales = callMeta.getLanguages(); Locale[] serverLocales = @@ -233,6 +222,22 @@ "browser locales - is " + locale.toString() ); + Collection parameters = this.getParameters(uuid); + Collection measurements = this.getMeasurements(uuid); + Collection dates = this.getDates(uuid); + + ChartLabels chartLables = new ChartLabels( + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable + ); + + String exportFormat = getExportFormat(mimeType); + + // TODO Remove this and parse input data + boolean linesVisible = true; + boolean shapesVisible = true; + this.createChart( outputStream, parameters, @@ -271,9 +276,9 @@ getMeasurements(uuid), getDates(uuid), new ChartLabels( - this.getFisName(callMeta.getLanguages()) + - " "+ getSelectedFeatureName(uuid), - this.domainLable), + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable), uuid, "A4", true, @@ -307,9 +312,10 @@ getMeasurements(uuid), getDates(uuid), new ChartLabels( - this.getFisName(callMeta.getLanguages()) + - " "+ getSelectedFeatureName(uuid), - this.domainLable), + createChartTitle(locale, uuid), + createChartSubtitle(locale, uuid), + domainLable + ), uuid, locale, width, @@ -456,13 +462,16 @@ return doc; } + protected String getSelectedFeatureName(String uuid) { - Collection values = this - .getCollection(featureValuesName, uuid); + Collection values = getCollection(featureValuesName, uuid); + if (values != null) { - Iterator it = values.iterator(); + Iterator it = values.iterator(); + while (it.hasNext()) { - KeyValueDescibeData data = it.next(); + KeyValueDescibeData data = (KeyValueDescibeData) it.next(); + if (data.isSelected()) { return data.getValue(); } @@ -471,6 +480,7 @@ return null; } + /** * @param outputStream * @param parameters @@ -683,18 +693,35 @@ return theme; } - protected String getFisName(PreferredLocale[] preferredLocales){ - String returnValue = ""; - InputData inputData = this.inputData.get("fisname"); - if (inputData != null){ - returnValue = RessourceFactory.getInstance() - .getRessource(preferredLocales, - inputData.getValue(), - inputData.getValue()); + + protected String createChartTitle(Locale locale, String uuid) { + return getFisName(locale); + + } + + + protected String createChartSubtitle(Locale locale, String uuid) { + return getSelectedFeatureName(uuid); + } + + + protected String getFisName(Locale locale) { + String returnValue = ""; + InputData input = inputData.get("fisname"); + + if (input != null) { + String value = input.getValue(); + + returnValue = RessourceFactory.getInstance().getRessource( + locale, + value, + value + ); } return returnValue; } + protected Collection getParameters(String uuid) { return this.getCollection(parameterValuesName, uuid); }