Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java @ 9496:d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
author | gernotbelger |
---|---|
date | Wed, 26 Sep 2018 15:48:05 +0200 |
parents | ddcd52d239cd |
children |
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:
3162
diff
changeset
|
9 package org.dive4elements.river.java2d; |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
11 import java.awt.Color; |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 import java.awt.Shape; |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
13 import java.awt.geom.Area; |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.awt.geom.Ellipse2D; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 import java.awt.geom.GeneralPath; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import java.awt.geom.Rectangle2D; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import java.util.HashMap; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 import java.util.Map; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
20 public class ShapeUtils { |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
22 public static enum ShapeType { |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
23 measured, digitized, interpolated, outlier |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
24 } |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
26 private static Map<Long, Shape> scaledShapesCache = new HashMap<>(); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
27 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
28 private static final Shape createCross(final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
29 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
30 final GeneralPath p = new GeneralPath(); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
31 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
32 p.moveTo(-size, -size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
33 p.lineTo(size, size); |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 p.closePath(); |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
35 p.moveTo(-size, size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
36 p.lineTo(size, -size); |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 p.closePath(); |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
38 |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 return p; |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 } |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
42 private static Shape createBox(final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
43 return new Rectangle2D.Double(-size, -size, size * 2, size * 2); |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 } |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
46 private static Shape createCircle(final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
47 return new Ellipse2D.Float(-size, -size, size * 2, size * 2); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
48 } |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
50 private static final Shape createTriangle(final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
51 final GeneralPath p = new GeneralPath(); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
52 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
53 p.moveTo(-size, size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
54 p.lineTo(size, size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
55 p.lineTo(0, -size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
56 p.closePath(); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
57 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
58 return new Area(p); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
59 } |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
60 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
61 public static synchronized Shape getScaledShape(final ShapeType type, final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
62 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
63 final Long hash = Long.valueOf((((long) type.ordinal()) << 32) | Float.floatToIntBits(size)); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
64 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
65 final Shape shape = scaledShapesCache.get(hash); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
66 if (shape != null) |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
67 return shape; |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
68 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
69 final Shape newShape = createScaledShape(type, size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
70 scaledShapesCache.put(hash, newShape); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
71 return newShape; |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
72 } |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
73 |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
74 private static Shape createScaledShape(final ShapeType type, final float size) { |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
75 switch (type) { |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
76 case measured: |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
77 return createBox(size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
78 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
79 case digitized: |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
80 return createCross(size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
81 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
82 case outlier: |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
83 return createTriangle(size); |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
84 |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
85 case interpolated: |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
86 default: |
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
87 return createCircle(size); |
3162
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 } |
0d8146989012
Added labeling for Q/W points FixingsKMChartService.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 } |
9496
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
90 |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
91 public static Color withAlpha(final Color color, final int transparencyPercent) { |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
92 |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
93 if (transparencyPercent <= 0 || transparencyPercent > 100 || color == null) |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
94 return color; |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
95 |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
96 return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) ((100 - transparencyPercent) * 2.55f)); |
d8e753d0fdb9
stripedArea introduced for Assessment Scheme/Bewertungsschema
gernotbelger
parents:
9360
diff
changeset
|
97 } |
9360
ddcd52d239cd
Outliers in fixation calculation are now shown within the other 'B' event themes and get a separate symbol (triangle).
gernotbelger
parents:
5994
diff
changeset
|
98 } |