comparison 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
comparison
equal deleted inserted replaced
2659:4d8959a4b49d 2660:1a044c51abe4
44 protected Map<Integer, Double> seriesMinimum; 44 protected Map<Integer, Double> seriesMinimum;
45 protected Map<Integer, Double> seriesMinimumX; 45 protected Map<Integer, Double> seriesMinimumX;
46 protected Map<Integer, Double> seriesMaximum; 46 protected Map<Integer, Double> seriesMaximum;
47 47
48 protected Map<Integer, Font> lineLabelFonts; 48 protected Map<Integer, Font> lineLabelFonts;
49 protected Map<Integer, Color> lineLabelTextColors;
50 protected BooleanList showLineLabelBG;
51 protected Map<Integer, Color> lineLabelBGColors;
49 52
50 53
51 public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) { 54 public EnhancedLineAndShapeRenderer(boolean lines, boolean shapes) {
52 super(lines, shapes); 55 super(lines, shapes);
53 this.isMinimumShapeVisible = new BooleanList(); 56 this.isMinimumShapeVisible = new BooleanList();
54 this.isMaximumShapeVisible = new BooleanList(); 57 this.isMaximumShapeVisible = new BooleanList();
55 this.showLineLabel = new BooleanList(); 58 this.showLineLabel = new BooleanList();
59 this.showLineLabelBG = new BooleanList();
56 this.seriesMinimum = new HashMap<Integer, Double>(); 60 this.seriesMinimum = new HashMap<Integer, Double>();
57 this.seriesMaximum = new HashMap<Integer, Double>(); 61 this.seriesMaximum = new HashMap<Integer, Double>();
58 this.seriesMinimumX = new HashMap<Integer, Double>(); 62 this.seriesMinimumX = new HashMap<Integer, Double>();
59 this.lineLabelFonts = new HashMap<Integer, Font>(); 63 this.lineLabelFonts = new HashMap<Integer, Font>();
64 this.lineLabelTextColors = new HashMap<Integer, Color>();
65 this.lineLabelBGColors = new HashMap<Integer, Color>();
66 }
67
68
69 /** Draw a background-box of a text to render. */
70 public static void drawTextBox(Graphics2D g2, String text, float textX, float textY, Color bgColor) {
71 Rectangle2D hotspotBox = g2.getFontMetrics().getStringBounds(text, g2);
72 float w = (float) hotspotBox.getWidth(), h = (float) hotspotBox.getHeight();
73 hotspotBox.setRect(textX, textY-h, w, h);
74 Color oldColor = g2.getColor();
75 g2.setColor(bgColor);
76 g2.fill(hotspotBox);
77 g2.setColor(oldColor);
60 } 78 }
61 79
62 80
63 public boolean getItemShapeVisible(XYDataset dataset, int series, int item){ 81 public boolean getItemShapeVisible(XYDataset dataset, int series, int item){
64 if (super.getItemShapeVisible(series, item)) { 82 if (super.getItemShapeVisible(series, item)) {
251 String waterlevelLabel = (xYSeries instanceof HasLabel) 269 String waterlevelLabel = (xYSeries instanceof HasLabel)
252 ? ((HasLabel)xYSeries).getLabel() 270 ? ((HasLabel)xYSeries).getLabel()
253 : xYSeries.getKey().toString(); 271 : xYSeries.getKey().toString();
254 // TODO Force water of some German rivers to flow direction mountains. 272 // TODO Force water of some German rivers to flow direction mountains.
255 Font oldFont = g2.getFont(); 273 Font oldFont = g2.getFont();
274 // or do we have to do it via getPaint?
275
276 Color oldColor = g2.getColor();
256 g2.setFont(this.getLineLabelFont(series)); 277 g2.setFont(this.getLineLabelFont(series));
257 // TODO set color 278 g2.setColor(this.getLineLabelTextColor(series));
279 g2.setBackground(Color.black);
280
281 // TODO if bg-bool ...
282 drawTextBox(g2, waterlevelLabel, (float)xx, (float)yy-3f,
283 getLineLabelBGColor(series));
284
258 g2.drawString(waterlevelLabel, (float)xx, (float)yy-3f); 285 g2.drawString(waterlevelLabel, (float)xx, (float)yy-3f);
286
259 g2.setFont(oldFont); 287 g2.setFont(oldFont);
288 g2.setColor(oldColor);
260 } 289 }
261 290
262 int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); 291 int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
263 int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); 292 int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
264 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, 293 updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex,
312 /** Sets whether or not a label should be shown for series. */ 341 /** Sets whether or not a label should be shown for series. */
313 public void setShowLineLabel(boolean showLineLabel, int series) { 342 public void setShowLineLabel(boolean showLineLabel, int series) {
314 this.showLineLabel.setBoolean(series, showLineLabel); 343 this.showLineLabel.setBoolean(series, showLineLabel);
315 } 344 }
316 345
346 /** Whether or not a label should be shown for series. */
347 public boolean isShowLineLabelBG(int series) {
348 if (this.showLineLabelBG.size() <= series) {
349 return false;
350 }
351
352 return showLineLabelBG.getBoolean(series);
353 }
354
355 public void setShowLineLabelBG(int series, boolean doShow) {
356 this.showLineLabelBG.setBoolean(series, doShow);
357 }
358
359 public Color getLineLabelBGColor(int series) {
360 if (this.lineLabelBGColors.size() <= series) {
361 return null;
362 }
363
364 return this.lineLabelBGColors.get(series);
365 }
366
367 public void setLineLabelBGColor(int series, Color color) {
368 this.lineLabelBGColors.put(series, color);
369 }
370
371 public Color getLineLabelTextColor(int series) {
372 if (this.lineLabelTextColors.size() <= series) {
373 return null;
374 }
375
376 return this.lineLabelTextColors.get(series);
377 }
378
379 public void setLineLabelTextColor(int series, Color color) {
380 this.lineLabelTextColors.put(series, color);
381 }
382
317 public void setLineLabelFont(Font font, int series) { 383 public void setLineLabelFont(Font font, int series) {
318 this.lineLabelFonts.put(series, font); 384 this.lineLabelFonts.put(series, font);
319 } 385 }
320 386
321 public Font getLineLabelFont(int series) { 387 public Font getLineLabelFont(int series) {

http://dive4elements.wald.intevation.org