Mercurial > dive4elements > river
changeset 2660:1a044c51abe4
Respect colors of theme for linelabels.
flys-artifacts/trunk@4334 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 02 May 2012 22:30:27 +0000 |
parents | 4d8959a4b49d |
children | 17927c60ac1c |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java |
diffstat | 4 files changed, 120 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed May 02 19:54:58 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed May 02 22:30:27 2012 +0000 @@ -1,3 +1,16 @@ +2012-05-03 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Use the colors specified in theme document for linelabel. + + * src/main/java/de/intevation/flys/utils/ThemeUtil.java: + New methods to find colors specified for linelabels. + + * src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java: + Store and use background and foreground color for linelabels. + + * src/main/java/de/intevation/flys/jfree/XYStyle.java: + Communicate colors of linelabels to renderer. + 2012-05-02 Felix Wolfsteller <felix.wolfsteller@intevation.de> Actually use the font specified in theme document for linelabel.
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java Wed May 02 19:54:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java Wed May 02 22:30:27 2012 +0000 @@ -46,6 +46,9 @@ protected Map<Integer, Double> seriesMaximum; protected Map<Integer, Font> lineLabelFonts; + protected Map<Integer, Color> lineLabelTextColors; + protected BooleanList showLineLabelBG; + protected Map<Integer, Color> lineLabelBGColors; public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) { @@ -53,10 +56,25 @@ this.isMinimumShapeVisible = new BooleanList(); this.isMaximumShapeVisible = new BooleanList(); this.showLineLabel = new BooleanList(); + this.showLineLabelBG = new BooleanList(); this.seriesMinimum = new HashMap<Integer, Double>(); this.seriesMaximum = new HashMap<Integer, Double>(); this.seriesMinimumX = new HashMap<Integer, Double>(); this.lineLabelFonts = new HashMap<Integer, Font>(); + this.lineLabelTextColors = new HashMap<Integer, Color>(); + this.lineLabelBGColors = new HashMap<Integer, Color>(); + } + + + /** Draw a background-box of a text to render. */ + public static void drawTextBox(Graphics2D g2, String text, float textX, float textY, Color bgColor) { + Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2); + float w = (float) hotspotBox.getWidth(), h = (float) hotspotBox.getHeight(); + hotspotBox.setRect(textX, textY-h, w, h); + Color oldColor = g2.getColor(); + g2.setColor(bgColor); + g2.fill(hotspotBox); + g2.setColor(oldColor); } @@ -253,10 +271,21 @@ : xYSeries.getKey().toString(); // TODO Force water of some German rivers to flow direction mountains. Font oldFont = g2.getFont(); + // or do we have to do it via getPaint? + + Color oldColor = g2.getColor(); g2.setFont(this.getLineLabelFont(series)); - // TODO set color + g2.setColor(this.getLineLabelTextColor(series)); + g2.setBackground(Color.black); + + // TODO if bg-bool ... + drawTextBox(g2, waterlevelLabel, (float)xx, (float)yy-3f, + getLineLabelBGColor(series)); + g2.drawString(waterlevelLabel, (float)xx, (float)yy-3f); + g2.setFont(oldFont); + g2.setColor(oldColor); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); @@ -314,6 +343,43 @@ this.showLineLabel.setBoolean(series, showLineLabel); } + /** Whether or not a label should be shown for series. */ + public boolean isShowLineLabelBG(int series) { + if (this.showLineLabelBG.size() <= series) { + return false; + } + + return showLineLabelBG.getBoolean(series); + } + + public void setShowLineLabelBG(int series, boolean doShow) { + this.showLineLabelBG.setBoolean(series, doShow); + } + + public Color getLineLabelBGColor(int series) { + if (this.lineLabelBGColors.size() <= series) { + return null; + } + + return this.lineLabelBGColors.get(series); + } + + public void setLineLabelBGColor(int series, Color color) { + this.lineLabelBGColors.put(series, color); + } + + public Color getLineLabelTextColor(int series) { + if (this.lineLabelTextColors.size() <= series) { + return null; + } + + return this.lineLabelTextColors.get(series); + } + + public void setLineLabelTextColor(int series, Color color) { + this.lineLabelTextColors.put(series, color); + } + public void setLineLabelFont(Font font, int series) { this.lineLabelFonts.put(series, font); }
--- a/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java Wed May 02 19:54:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java Wed May 02 22:30:27 2012 +0000 @@ -41,6 +41,8 @@ applyShowMaximum(r, idx); applyShowLineLabel(r, idx); applyLineLabelFont(r, idx); + applyLineLabelColor(r, idx); + applyLineLabelBGColor(r, idx); return r; } @@ -72,6 +74,24 @@ ((EnhancedLineAndShapeRenderer)r).setLineLabelFont(ThemeUtil.parseLineLabelFont(theme), idx); } + /** Tell the renderer which color to use for + * linelabels. */ + protected void applyLineLabelColor(XYLineAndShapeRenderer r, int idx) { + if (!(r instanceof EnhancedLineAndShapeRenderer)) { + return; + } + ((EnhancedLineAndShapeRenderer)r).setLineLabelTextColor(idx, ThemeUtil.parseLineLabelTextColor(theme)); + } + + /** Tell the renderer which color to use for bg of + * linelabels. */ + protected void applyLineLabelBGColor(XYLineAndShapeRenderer r, int idx) { + if (!(r instanceof EnhancedLineAndShapeRenderer)) { + return; + } + ((EnhancedLineAndShapeRenderer)r).setLineLabelBGColor(idx, + ThemeUtil.parseLineLabelBGColor(theme)); + } /** Set stroke of series. */ protected void applyLineSize(XYLineAndShapeRenderer r, int idx) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed May 02 19:54:58 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java Wed May 02 22:30:27 2012 +0000 @@ -266,6 +266,19 @@ return parseRGB(getTextColorString(theme)); } + + /** Parse color for line label(s text). */ + public static Color parseLineLabelTextColor(Document theme) { + return parseRGB(getLineLabelTextColorString(theme)); + } + + /** Parse bg color for line label(s text). */ + public static Color parseLineLabelBGColor(Document theme) { + return parseRGB(getLineLabelBGColorString(theme)); + } + + // TODO showbg and bg color for linelabels + /** * Parses the font. @@ -419,6 +432,13 @@ return XMLUtils.xpathString(theme, XPATH_TEXT_COLOR, null); } + public static String getLineLabelTextColorString(Document theme) { + return XMLUtils.xpathString(theme, XPATH_LINE_LABEL_COLOR, null); + } + + public static String getLineLabelBGColorString(Document theme) { + return XMLUtils.xpathString(theme, XPATH_LINE_LABEL_BGCOLOR, null); + } public static String getSymbol(Document theme) { return XMLUtils.xpathString(theme, XPATH_SYMBOL, null);