Mercurial > dive4elements > river
diff 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 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java Tue Sep 25 16:43:51 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/java2d/ShapeUtils.java Wed Sep 26 15:48:05 2018 +0200 @@ -8,6 +8,7 @@ package org.dive4elements.river.java2d; +import java.awt.Color; import java.awt.Shape; import java.awt.geom.Area; import java.awt.geom.Ellipse2D; @@ -24,7 +25,7 @@ private static Map<Long, Shape> scaledShapesCache = new HashMap<>(); - private static final Shape createCross(float size) { + private static final Shape createCross(final float size) { final GeneralPath p = new GeneralPath(); @@ -38,15 +39,15 @@ return p; } - private static Shape createBox(float size) { + private static Shape createBox(final float size) { return new Rectangle2D.Double(-size, -size, size * 2, size * 2); } - private static Shape createCircle(float size) { + private static Shape createCircle(final float size) { return new Ellipse2D.Float(-size, -size, size * 2, size * 2); } - private static final Shape createTriangle(float size) { + private static final Shape createTriangle(final float size) { final GeneralPath p = new GeneralPath(); p.moveTo(-size, size); @@ -57,7 +58,7 @@ return new Area(p); } - public static synchronized Shape getScaledShape(final ShapeType type, float size) { + public static synchronized Shape getScaledShape(final ShapeType type, final float size) { final Long hash = Long.valueOf((((long) type.ordinal()) << 32) | Float.floatToIntBits(size)); @@ -70,7 +71,7 @@ return newShape; } - private static Shape createScaledShape(ShapeType type, float size) { + private static Shape createScaledShape(final ShapeType type, final float size) { switch (type) { case measured: return createBox(size); @@ -86,4 +87,12 @@ return createCircle(size); } } + + public static Color withAlpha(final Color color, final int transparencyPercent) { + + if (transparencyPercent <= 0 || transparencyPercent > 100 || color == null) + return color; + + return new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) ((100 - transparencyPercent) * 2.55f)); + } } \ No newline at end of file