1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint;
|
---|
3 |
|
---|
4 | import javax.swing.ImageIcon;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
7 | import org.openstreetmap.josm.data.osm.Way;
|
---|
8 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
|
---|
9 | import org.openstreetmap.josm.data.osm.visitor.paint.MapPainter;
|
---|
10 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * similar to mapnik's LinePatternSymbolizer
|
---|
14 | */
|
---|
15 | public class LinePatternElemStyle extends ElemStyle {
|
---|
16 |
|
---|
17 | public ImageIcon pattern;
|
---|
18 |
|
---|
19 | public LinePatternElemStyle(Cascade c, ImageIcon pattern) {
|
---|
20 | super(c, -1f);
|
---|
21 | this.pattern = pattern;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public static LinePatternElemStyle create(Environment env) {
|
---|
25 | Cascade c = env.mc.getCascade(env.layer);
|
---|
26 |
|
---|
27 | IconReference iconRef = c.get("pattern-image", null, IconReference.class);
|
---|
28 | if (iconRef == null)
|
---|
29 | return null;
|
---|
30 | ImageIcon icon = MapPaintStyles.getIcon(iconRef, -1, -1);
|
---|
31 | if (icon == null)
|
---|
32 | return null;
|
---|
33 | return new LinePatternElemStyle(c, icon);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void paintPrimitive(OsmPrimitive primitive, MapPaintSettings paintSettings, MapPainter painter, boolean selected, boolean member) {
|
---|
38 | Way w = (Way)primitive;
|
---|
39 | painter.drawLinePattern(w, pattern);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public boolean isProperLineStyle() {
|
---|
44 | return true;
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Override
|
---|
48 | public boolean equals(Object obj) {
|
---|
49 | if (obj == null || getClass() != obj.getClass())
|
---|
50 | return false;
|
---|
51 | if (!super.equals(obj))
|
---|
52 | return false;
|
---|
53 | final LinePatternElemStyle other = (LinePatternElemStyle) obj;
|
---|
54 | return pattern.getImage() == other.pattern.getImage();
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | public int hashCode() {
|
---|
59 | return pattern.hashCode();
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Override
|
---|
63 | public String toString() {
|
---|
64 | return "LinePatternElemStyle{" + super.toString() + "pattern=" + pattern + '}';
|
---|
65 | }
|
---|
66 | }
|
---|