source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaIconElement.java@ 11731

Last change on this file since 11731 was 11731, checked in by michael2402, 7 years ago

Clean icon drawing code style.

File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.styleelement;
3
4import java.util.Objects;
5
6import org.openstreetmap.josm.data.osm.OsmPrimitive;
7import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
8import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
9import org.openstreetmap.josm.gui.mappaint.Cascade;
10import org.openstreetmap.josm.gui.mappaint.Environment;
11import org.openstreetmap.josm.gui.util.RotationAngle;
12
13/**
14 * This class defines how an icon is rendered onto the area.
15 * @author Michael Zangl
16 * @since 11730
17 */
18public class AreaIconElement extends StyleElement {
19 /**
20 * The icon that is displayed on the center of the area.
21 */
22 private final MapImage iconImage;
23
24 /**
25 * The rotation of the {@link #iconImageAngle}
26 */
27 private final RotationAngle iconImageAngle;
28
29 /**
30 * The position of the icon inside the area.
31 */
32 private final PositionForAreaStrategy iconPosition = PositionForAreaStrategy.PARTIALY_INSIDE;
33
34 protected AreaIconElement(Cascade c, MapImage iconImage, RotationAngle iconImageAngle) {
35 super(c, 4.8f);
36 this.iconImage = Objects.requireNonNull(iconImage, "iconImage");
37 this.iconImageAngle = Objects.requireNonNull(iconImageAngle, "iconImageAngle");
38 }
39
40 @Override
41 public void paintPrimitive(OsmPrimitive osm, MapPaintSettings paintSettings, StyledMapRenderer painter,
42 boolean selected, boolean outermember, boolean member) {
43 if (painter.isShowIcons()) {
44 painter.drawAreaIcon(osm, iconImage, painter.isInactiveMode() || osm.isDisabled(), selected, member,
45 iconImageAngle.getRotationAngle(osm), iconPosition);
46 }
47 }
48
49 /**
50 * Create a new {@link AreaIconElement}
51 * @param env The current style definitions
52 * @return The area element or <code>null</code> if there is no icon.
53 */
54 public static AreaIconElement create(final Environment env) {
55 final Cascade c = env.mc.getCascade(env.layer);
56 MapImage iconImage = NodeElement.createIcon(env);
57 if (iconImage != null) {
58 RotationAngle rotationAngle = NodeElement.createRotationAngle(env);
59
60 return new AreaIconElement(c, iconImage, rotationAngle);
61 } else {
62 return null;
63 }
64 }
65
66 @Override
67 public int hashCode() {
68 final int prime = 31;
69 int result = super.hashCode();
70 result = prime * result + ((iconImage == null) ? 0 : iconImage.hashCode());
71 result = prime * result + ((iconImageAngle == null) ? 0 : iconImageAngle.hashCode());
72 result = prime * result + ((iconPosition == null) ? 0 : iconPosition.hashCode());
73 return result;
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj) {
79 return true;
80 }
81 if (!super.equals(obj)) {
82 return false;
83 }
84 if (getClass() != obj.getClass()) {
85 return false;
86 }
87 AreaIconElement other = (AreaIconElement) obj;
88 return Objects.equals(iconImage, other.iconImage) &&
89 Objects.equals(iconImageAngle, other.iconImageAngle) &&
90 Objects.equals(iconPosition, other.iconPosition);
91 }
92
93 @Override
94 public String toString() {
95 return "AreaIconElement{" + super.toString() + "iconImage=[" + iconImage + "] iconImageAngle=[" + iconImageAngle + "]}";
96 }
97}
Note: See TracBrowser for help on using the repository browser.