Mercurial > dive4elements > river
changeset 1753:741ba9e34c7d
Apply the attributes 'showpoints' and 'showline'.
flys-artifacts/trunk@3056 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Fri, 21 Oct 2011 14:02:07 +0000 (2011-10-21) |
parents | b7b424ae32a8 |
children | 8e6615ad60b8 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java |
diffstat | 4 files changed, 102 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri Oct 21 13:25:24 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Oct 21 14:02:07 2011 +0000 @@ -1,3 +1,14 @@ +2011-10-21 Raimund Renkert <raimund.renkert@intevation.de> + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: + Added methods to parse further attributes. + + * src/main/java/de/intevation/flys/exports/StyledXYSeries.java: + Apply the theme attributes and use ThemeUtils to get the attribute values. + + * src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java: + Removed the spamy debug output. + 2011-10-21 Sascha L. Teichmann <sascha.teichmann@intevation.de> To obtain the size of a diagram it is rendered twice. The
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java Fri Oct 21 13:25:24 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/StyledXYSeries.java Fri Oct 21 14:02:07 2011 +0000 @@ -2,6 +2,7 @@ import java.awt.BasicStroke; import java.awt.Color; +import java.awt.geom.Ellipse2D; import org.apache.log4j.Logger; @@ -11,6 +12,7 @@ import org.jfree.data.xy.XYSeries; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.utils.ThemeUtil; public class StyledXYSeries extends XYSeries { @@ -44,91 +46,58 @@ applyLineColor(r, idx); applyLineSize(r, idx); applyLineType(r, idx); - - r.setSeriesLinesVisible(idx, true); - r.setSeriesShapesVisible(idx, false); + applyShowLine(r, idx); + applyShowPoints(r, idx); return r; } protected void applyLineColor(XYLineAndShapeRenderer r, int idx) { - String color = XMLUtils.xpathString(theme, XPATH_LINE_COLOR, null); - - if (color == null || color.length() == 0) { - return; - } - - String[] rgb = color.split(","); - - try { - Color c = new Color( - Integer.valueOf(rgb[0].trim()), - Integer.valueOf(rgb[1].trim()), - Integer.valueOf(rgb[2].trim())); - - logger.debug("Set series paint color: " + c.toString()); - - r.setSeriesPaint(idx, c); - } - catch (NumberFormatException nfe) { - logger.warn("Unable to set color from string: '" + color + "'"); - } + Color c = ThemeUtil.parseLineColorField(theme); + r.setSeriesPaint(idx, c); } protected void applyLineSize(XYLineAndShapeRenderer r, int idx) { - String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); - - if (size == null || size.length() == 0) { - return; - } - - try { - r.setSeriesStroke( - idx, - new BasicStroke(Integer.valueOf(size))); - } - catch (NumberFormatException nfe) { - logger.warn("Unable to set line size from string: '" + size + "'"); - } + int size = ThemeUtil.parseLineWidth(theme); + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size))); } protected void applyLineType(XYLineAndShapeRenderer r, int idx) { - String dash = XMLUtils.xpathString(theme, XPATH_LINE_TYPE, null); - String size = XMLUtils.xpathString(theme, XPATH_LINE_SIZE, null); + int size = ThemeUtil.parseLineWidth(theme); + float[] dashes = ThemeUtil.parseLineStyle(theme); - if (dash == null || dash.length() == 0) { - return; - } - if (size == null || size.length() == 0) { - return; - } - - String[] pattern = dash.split(","); - if(pattern.length == 1) { + // Do not apply the dashed style. + if (dashes.length <= 1) { return; } - try { - float[] dashes = new float[pattern.length]; - for (int i = 0; i < pattern.length; i++) { - dashes[i] = Float.parseFloat(pattern[i]); - } + r.setSeriesStroke( + idx, + new BasicStroke(Integer.valueOf(size), + BasicStroke.CAP_BUTT, + BasicStroke.JOIN_ROUND, + 1.0f, + dashes, + 0.0f)); + } - r.setSeriesStroke( - idx, - new BasicStroke(Integer.valueOf(size), - BasicStroke.CAP_BUTT, - BasicStroke.JOIN_ROUND, - 1.0f, - dashes, - 0.0f)); - } - catch(NumberFormatException nfe) { - logger.warn("Unable to set dash from string: '" + dash + "'"); - } + + protected void applyShowPoints(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowPoints(theme); + r.setSeriesShape(idx, new Ellipse2D.Double(-2.0, -2.0, 4.0, 4.0)); + r.setSeriesShapesVisible(idx, show); + r.setDrawOutlines(true); + } + + + protected void applyShowLine(XYLineAndShapeRenderer r, int idx) { + boolean show = ThemeUtil.parseShowLine(theme); + r.setSeriesLinesVisible(idx, show); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Oct 21 13:25:24 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/StickyAxisAnnotation.java Fri Oct 21 14:02:07 2011 +0000 @@ -127,7 +127,6 @@ if(textOrientation.equals("horizontal")) { o = 0f; } - //logger.debug("orientation: " + o); this.setRotationAngle(o * (Math.PI / 180f)); this.setRotationAnchor(TextAnchor.CENTER_LEFT); this.setTextAnchor(TextAnchor.CENTER_LEFT);
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Oct 21 13:25:24 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Fri Oct 21 14:02:07 2011 +0000 @@ -24,9 +24,15 @@ public static final String XPATH_LINE_SIZE = "/theme/field[@name='linesize']/@default"; + public static final String XPATH_LINE_STYLE = + "/theme/field[@name='linetype']/@default"; + public final static String XPATH_SHOW_POINTS = "/theme/field[@name='showpoints']/@default"; + public final static String XPATH_SHOW_LINE = + "/theme/field[@name='showlines']/@default"; + public final static String XPATH_TEXT_COLOR = "/theme/field[@name='textcolor']/@default"; @@ -62,13 +68,44 @@ return Integer.valueOf(size); } catch (NumberFormatException nfe) { - //logger.warn("Unable to set line size from string: '" + size + "'"); + logger.warn("Unable to set line size from string: '" + size + "'"); } return 0; } /** + * Parses the line style, defaulting to '10'. + * @param theme The theme. + */ + public static float[] parseLineStyle(Document theme) { + String dash = XMLUtils.xpathString(theme, XPATH_LINE_STYLE, null); + + float[] def = {10}; + if (dash == null || dash.length() == 0) { + return def; + } + + String[] pattern = dash.split(","); + if(pattern.length == 1) { + return def; + } + + try { + float[] dashes = new float[pattern.length]; + for (int i = 0; i < pattern.length; i++) { + dashes[i] = Float.parseFloat(pattern[i]); + } + return dashes; + } + catch(NumberFormatException nfe) { + logger.warn("Unable to set dash from string: '" + dash + "'"); + return def; + } + } + + + /** * Parses text size, defaulting to 10. * @param theme The theme. */ @@ -106,6 +143,24 @@ /** + * Parses the attribute 'showlines', defaults to true. + * @param theme The theme. + */ + public static boolean parseShowLine(Document theme) { + String show = XMLUtils.xpathString(theme, XPATH_SHOW_LINE, null); + if (show == null || show.length() == 0) { + return true; + } + if (show.equals("false")) { + return false; + } + else { + return true; + } + } + + + /** * Parses text color. * @param theme The theme. */ @@ -211,7 +266,6 @@ * @return Color, null in case of issues. */ public static Color parseRGB(String rgbtext) { - logger.debug("parseColor: " + rgbtext); if (rgbtext == null) { return null; }