diff artifacts/src/main/java/org/dive4elements/river/jfree/AreaFillPattern.java @ 8910:d9c89651bd67

Area chart layers may now have an 'arebgpattern'. Real pattern yet to be defined.
author gernotbelger
date Thu, 22 Feb 2018 18:46:37 +0100
parents
children 924cd9943337
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/artifacts/src/main/java/org/dive4elements/river/jfree/AreaFillPattern.java	Thu Feb 22 18:46:37 2018 +0100
@@ -0,0 +1,75 @@
+/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
+ * Software engineering by
+ *  Björnsen Beratende Ingenieure GmbH
+ *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
+ *
+ * This file is Free Software under the GNU AGPL (>=v3)
+ * and comes with ABSOLUTELY NO WARRANTY! Check out the
+ * documentation coming with Dive4Elements River for details.
+ */
+package org.dive4elements.river.jfree;
+
+import java.awt.Color;
+import java.awt.image.BufferedImage;
+import java.awt.image.BufferedImageOp;
+import java.awt.image.LookupOp;
+import java.io.IOException;
+
+import javax.imageio.ImageIO;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Fill patterns for area styles.
+ * REMARK: if this enum is changed, probably the ui in StyleEditorWindow must be changed too
+ *
+ * @author Gernot Belger
+ */
+public enum AreaFillPattern {
+
+    pattern1("/images/areapatterns/pattern1.png");
+
+    private static Logger log = Logger.getLogger(AreaFillPattern.class);
+
+    private static final BufferedImage MISSING_IMAGE = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
+
+    private final String imagePath;
+
+    private BufferedImage image = null;
+
+    AreaFillPattern(final String imagePath) {
+        this.imagePath = imagePath;
+    }
+
+    public BufferedImage getImage(final Color color) {
+
+        if (this.image == null)
+            this.image = loadImage();
+
+        if (color == null)
+            return this.image;
+
+        /*
+         * apply color and transparency, the .png must be encoded as 32bit images (rgba), with only black as non transparent
+         * color
+         */
+        final int numComponents = this.image.getColorModel().getNumComponents();
+        if (numComponents != 4) {
+            log.warn(String.format("Pattern image must be a 32bit image (rgba): %s", this.imagePath));
+            return this.image;
+        }
+
+        final BufferedImageOp lookup = new LookupOp(new ColorMapper(Color.black, color), null);
+        return lookup.filter(this.image, null);
+    }
+
+    private BufferedImage loadImage() {
+        try {
+            return ImageIO.read(getClass().getResource(this.imagePath));
+        }
+        catch (final IOException e) {
+            log.error(String.format("failed ot load pattern: %s", this.imagePath), e);
+            return MISSING_IMAGE;
+        }
+    }
+}
\ No newline at end of file

http://dive4elements.wald.intevation.org