annotate artifacts/src/main/java/org/dive4elements/river/themes/TextStyle.java @ 6931:2c8e5bad8699

Fix NPE in case the artifact does not even have the master attribute Started happening with the new other.wqkms.w attribute condition and official lines in waterlevel calculations
author Andre Heinecke <aheinecke@intevation.de>
date Tue, 27 Aug 2013 18:35:51 +0200
parents 1f1acbe5f243
children 0a5239a1e46e
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3464
diff changeset
9 package org.dive4elements.river.themes;
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
10
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 3464
diff changeset
11 import org.dive4elements.river.jfree.StableXYDifferenceRenderer;
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
12
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
13 import java.awt.Color;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
14 import java.awt.Font;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
15
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
17 import org.jfree.chart.annotations.XYTextAnnotation;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
18
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
19 public class TextStyle {
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
20 @SuppressWarnings("unused")
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
21 private static Logger log = Logger.getLogger(TextStyle.class);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
22
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
23 protected Color textColor;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
24 protected Font font;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
25 protected Color bgColor;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
26 protected boolean showBg;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
27 protected boolean isVertical;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
28
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
29 public TextStyle(Color fgColor, Font font, Color bgColor,
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
30 boolean showBg, boolean isVertical
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
31 ) {
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
32 this.textColor = fgColor;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
33 this.font = font;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
34 this.bgColor = bgColor;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
35 this.showBg = showBg;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
36 this.isVertical = isVertical;
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
37 }
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
38
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
39 public void apply(XYTextAnnotation ta) {
6911
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
40 if (textColor != null) {
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
41 ta.setPaint(textColor);
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
42 }
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
43 if (font != null) {
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
44 ta.setFont(font);
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
45 }
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
46 if (showBg) {
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
47 ta.setBackgroundPaint(bgColor);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
48 }
6911
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
49 if (isVertical) {
3464
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
50 ta.setRotationAngle(270f*Math.PI/180f);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
51 }
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
52 else {
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
53 ta.setRotationAngle(0);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
54 }
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
55 }
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
56
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
57 public void apply(StableXYDifferenceRenderer renderer) {
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
58 renderer.setLabelColor(textColor);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
59 renderer.setLabelFont(font);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
60 if (this.showBg) {
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
61 renderer.setLabelBGColor(bgColor);
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
62 }
0b9b2a0c4e64 Point labels can have a background color now.
Christian Lins <christian.lins@intevation.de>
parents:
diff changeset
63 }
6911
1f1acbe5f243 Artifacts: Make TextStyle Make more robust.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5994
diff changeset
64 }

http://dive4elements.wald.intevation.org