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

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

Move label / icon placement code to new package. Unify the handling of text label positioning (path / center)

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