Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/jfree/EnhancedLineAndShapeRenderer.java @ 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 | bdc86e61428c |
line wrap: on
line diff
--- 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); }