comparison 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
comparison
equal deleted inserted replaced
8909:31dff17c6828 8910:d9c89651bd67
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
2 * Software engineering by
3 * Björnsen Beratende Ingenieure GmbH
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
5 *
6 * This file is Free Software under the GNU AGPL (>=v3)
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the
8 * documentation coming with Dive4Elements River for details.
9 */
10 package org.dive4elements.river.jfree;
11
12 import java.awt.Color;
13 import java.awt.image.BufferedImage;
14 import java.awt.image.BufferedImageOp;
15 import java.awt.image.LookupOp;
16 import java.io.IOException;
17
18 import javax.imageio.ImageIO;
19
20 import org.apache.log4j.Logger;
21
22 /**
23 * Fill patterns for area styles.
24 * REMARK: if this enum is changed, probably the ui in StyleEditorWindow must be changed too
25 *
26 * @author Gernot Belger
27 */
28 public enum AreaFillPattern {
29
30 pattern1("/images/areapatterns/pattern1.png");
31
32 private static Logger log = Logger.getLogger(AreaFillPattern.class);
33
34 private static final BufferedImage MISSING_IMAGE = new BufferedImage(16, 16, BufferedImage.TYPE_INT_RGB);
35
36 private final String imagePath;
37
38 private BufferedImage image = null;
39
40 AreaFillPattern(final String imagePath) {
41 this.imagePath = imagePath;
42 }
43
44 public BufferedImage getImage(final Color color) {
45
46 if (this.image == null)
47 this.image = loadImage();
48
49 if (color == null)
50 return this.image;
51
52 /*
53 * apply color and transparency, the .png must be encoded as 32bit images (rgba), with only black as non transparent
54 * color
55 */
56 final int numComponents = this.image.getColorModel().getNumComponents();
57 if (numComponents != 4) {
58 log.warn(String.format("Pattern image must be a 32bit image (rgba): %s", this.imagePath));
59 return this.image;
60 }
61
62 final BufferedImageOp lookup = new LookupOp(new ColorMapper(Color.black, color), null);
63 return lookup.filter(this.image, null);
64 }
65
66 private BufferedImage loadImage() {
67 try {
68 return ImageIO.read(getClass().getResource(this.imagePath));
69 }
70 catch (final IOException e) {
71 log.error(String.format("failed ot load pattern: %s", this.imagePath), e);
72 return MISSING_IMAGE;
73 }
74 }
75 }

http://dive4elements.wald.intevation.org