Changeset 11722 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
- Timestamp:
- 2017-03-13T17:04:29+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java
r11717 r11722 15 15 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy; 16 16 import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy; 17 import org.openstreetmap.josm.gui.mappaint.styleelement.PositionForAreaStrategy.CompletelyInsideAreaStrategy; 17 18 import org.openstreetmap.josm.tools.CheckParameterUtil; 18 19 import org.openstreetmap.josm.tools.Utils; … … 54 55 */ 55 56 public Color haloColor; 57 58 /** 59 * The position strategy for this text label. 60 */ 61 private final PositionForAreaStrategy labelPositionSteategy; 56 62 57 63 /** … … 66 72 * @param haloRadius halo radius 67 73 * @param haloColor halo color 68 */ 74 * @deprecated since 11722, To be removed in mid-2017 75 */ 76 @Deprecated 69 77 public TextLabel(LabelCompositionStrategy strategy, Font font, int xOffset, int yOffset, Color color, Float haloRadius, Color haloColor) { 70 CheckParameterUtil.ensureParameterNotNull(font); 71 CheckParameterUtil.ensureParameterNotNull(color); 72 labelCompositionStrategy = strategy; 73 this.font = font; 78 this(strategy, font, xOffset, yOffset, color, haloRadius, haloColor, new CompletelyInsideAreaStrategy()); 79 } 80 81 /** 82 * Creates a new text element 83 * 84 * @param strategy the strategy indicating how the text is composed for a specific {@link OsmPrimitive} to be rendered. 85 * If null, no label is rendered. 86 * @param font the font to be used. Must not be null. 87 * @param xOffset x offset 88 * @param yOffset y offset 89 * @param color the color to be used. Must not be null 90 * @param haloRadius halo radius 91 * @param haloColor halo color 92 * @param labelPositionSteategy The position in the area. 93 */ 94 protected TextLabel(LabelCompositionStrategy strategy, Font font, int xOffset, int yOffset, Color color, Float haloRadius, Color haloColor, PositionForAreaStrategy labelPositionSteategy) { 95 this.labelCompositionStrategy = strategy; 96 this.font = Objects.requireNonNull(font, "font"); 74 97 this.xOffset = xOffset; 75 98 this.yOffset = yOffset; 76 this.color = color;99 this.color = Objects.requireNonNull(color, "color"); 77 100 this.haloRadius = haloRadius; 78 101 this.haloColor = haloColor; 102 this.labelPositionSteategy = Objects.requireNonNull(labelPositionSteategy, "labelPositionSteategy"); 79 103 } 80 104 … … 92 116 this.haloColor = other.haloColor; 93 117 this.haloRadius = other.haloRadius; 118 this.labelPositionSteategy = other.labelPositionSteategy; 119 } 120 121 /** 122 * Copy constructor that changes the position strategy. 123 * 124 * @param other the other element. 125 * @param labelPositionSteategy the position 126 */ 127 private TextLabel(TextLabel other, PositionForAreaStrategy labelPositionSteategy) { 128 this.labelCompositionStrategy = other.labelCompositionStrategy; 129 this.font = other.font; 130 this.xOffset = other.xOffset; 131 this.yOffset = other.yOffset; 132 this.color = other.color; 133 this.haloColor = other.haloColor; 134 this.haloRadius = other.haloRadius; 135 this.labelPositionSteategy = labelPositionSteategy; 94 136 } 95 137 … … 177 219 } 178 220 179 return new TextLabel(strategy, font, (int) xOffset, -(int) yOffset, color, haloRadius, haloColor); 221 Keyword positionKeyword = c.get(AreaElement.TEXT_POSITION, null, Keyword.class); 222 PositionForAreaStrategy position = PositionForAreaStrategy.forKeyword(positionKeyword); 223 224 return new TextLabel(strategy, font, (int) xOffset, -(int) yOffset, color, haloRadius, haloColor, position); 180 225 } 181 226 … … 190 235 if (labelCompositionStrategy == null) return null; 191 236 return labelCompositionStrategy.compose(osm); 237 } 238 239 /** 240 * Gets the strategy that defines where to place the label. 241 * @return The strategy. Never null. 242 * @since 11722 243 */ 244 public PositionForAreaStrategy getLabelPositionSteategy() { 245 return labelPositionSteategy; 246 } 247 248 public TextLabel withPosition(PositionForAreaStrategy labelPositionSteategy) { 249 return new TextLabel(this, labelPositionSteategy); 192 250 } 193 251
Note:
See TracChangeset
for help on using the changeset viewer.