Mercurial > dive4elements > river
comparison 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 |
comparison
equal
deleted
inserted
replaced
9495:bb278c927b66 | 9496:d8e753d0fdb9 |
---|---|
6 * documentation coming with Dive4Elements River for details. | 6 * documentation coming with Dive4Elements River for details. |
7 */ | 7 */ |
8 | 8 |
9 package org.dive4elements.river.java2d; | 9 package org.dive4elements.river.java2d; |
10 | 10 |
11 import java.awt.Color; | |
11 import java.awt.Shape; | 12 import java.awt.Shape; |
12 import java.awt.geom.Area; | 13 import java.awt.geom.Area; |
13 import java.awt.geom.Ellipse2D; | 14 import java.awt.geom.Ellipse2D; |
14 import java.awt.geom.GeneralPath; | 15 import java.awt.geom.GeneralPath; |
15 import java.awt.geom.Rectangle2D; | 16 import java.awt.geom.Rectangle2D; |
22 measured, digitized, interpolated, outlier | 23 measured, digitized, interpolated, outlier |
23 } | 24 } |
24 | 25 |
25 private static Map<Long, Shape> scaledShapesCache = new HashMap<>(); | 26 private static Map<Long, Shape> scaledShapesCache = new HashMap<>(); |
26 | 27 |
27 private static final Shape createCross(float size) { | 28 private static final Shape createCross(final float size) { |
28 | 29 |
29 final GeneralPath p = new GeneralPath(); | 30 final GeneralPath p = new GeneralPath(); |
30 | 31 |
31 p.moveTo(-size, -size); | 32 p.moveTo(-size, -size); |
32 p.lineTo(size, size); | 33 p.lineTo(size, size); |
36 p.closePath(); | 37 p.closePath(); |
37 | 38 |
38 return p; | 39 return p; |
39 } | 40 } |
40 | 41 |
41 private static Shape createBox(float size) { | 42 private static Shape createBox(final float size) { |
42 return new Rectangle2D.Double(-size, -size, size * 2, size * 2); | 43 return new Rectangle2D.Double(-size, -size, size * 2, size * 2); |
43 } | 44 } |
44 | 45 |
45 private static Shape createCircle(float size) { | 46 private static Shape createCircle(final float size) { |
46 return new Ellipse2D.Float(-size, -size, size * 2, size * 2); | 47 return new Ellipse2D.Float(-size, -size, size * 2, size * 2); |
47 } | 48 } |
48 | 49 |
49 private static final Shape createTriangle(float size) { | 50 private static final Shape createTriangle(final float size) { |
50 final GeneralPath p = new GeneralPath(); | 51 final GeneralPath p = new GeneralPath(); |
51 | 52 |
52 p.moveTo(-size, size); | 53 p.moveTo(-size, size); |
53 p.lineTo(size, size); | 54 p.lineTo(size, size); |
54 p.lineTo(0, -size); | 55 p.lineTo(0, -size); |
55 p.closePath(); | 56 p.closePath(); |
56 | 57 |
57 return new Area(p); | 58 return new Area(p); |
58 } | 59 } |
59 | 60 |
60 public static synchronized Shape getScaledShape(final ShapeType type, float size) { | 61 public static synchronized Shape getScaledShape(final ShapeType type, final float size) { |
61 | 62 |
62 final Long hash = Long.valueOf((((long) type.ordinal()) << 32) | Float.floatToIntBits(size)); | 63 final Long hash = Long.valueOf((((long) type.ordinal()) << 32) | Float.floatToIntBits(size)); |
63 | 64 |
64 final Shape shape = scaledShapesCache.get(hash); | 65 final Shape shape = scaledShapesCache.get(hash); |
65 if (shape != null) | 66 if (shape != null) |
68 final Shape newShape = createScaledShape(type, size); | 69 final Shape newShape = createScaledShape(type, size); |
69 scaledShapesCache.put(hash, newShape); | 70 scaledShapesCache.put(hash, newShape); |
70 return newShape; | 71 return newShape; |
71 } | 72 } |
72 | 73 |
73 private static Shape createScaledShape(ShapeType type, float size) { | 74 private static Shape createScaledShape(final ShapeType type, final float size) { |
74 switch (type) { | 75 switch (type) { |
75 case measured: | 76 case measured: |
76 return createBox(size); | 77 return createBox(size); |
77 | 78 |
78 case digitized: | 79 case digitized: |
84 case interpolated: | 85 case interpolated: |
85 default: | 86 default: |
86 return createCircle(size); | 87 return createCircle(size); |
87 } | 88 } |
88 } | 89 } |
90 | |
91 public static Color withAlpha(final Color color, final int transparencyPercent) { | |
92 | |
93 if (transparencyPercent <= 0 || transparencyPercent > 100 || color == null) | |
94 return color; | |
95 | |
96 return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) ((100 - transparencyPercent) * 2.55f)); | |
97 } | |
89 } | 98 } |