# HG changeset patch # User Felix Wolfsteller # Date 1335997827 0 # Node ID 1a044c51abe4e5bafa413ffa7c5dffcb4e45b39c # Parent 4d8959a4b49d358b4542698cf97d9b50e8d8c128 Respect colors of theme for linelabels. flys-artifacts/trunk@4334 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 4d8959a4b49d -r 1a044c51abe4 flys-artifacts/ChangeLog --- 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 + + 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 Actually use the font specified in theme document for linelabel. diff -r 4d8959a4b49d -r 1a044c51abe4 flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java --- 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 seriesMaximum; protected Map lineLabelFonts; + protected Map lineLabelTextColors; + protected BooleanList showLineLabelBG; + protected Map 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(); this.seriesMaximum = new HashMap(); this.seriesMinimumX = new HashMap(); this.lineLabelFonts = new HashMap(); + this.lineLabelTextColors = new HashMap(); + this.lineLabelBGColors = new HashMap(); + } + + + /** 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); } diff -r 4d8959a4b49d -r 1a044c51abe4 flys-artifacts/src/main/java/de/intevation/flys/jfree/XYStyle.java --- 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) { diff -r 4d8959a4b49d -r 1a044c51abe4 flys-artifacts/src/main/java/de/intevation/flys/utils/ThemeUtil.java --- 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);