Ignore:
Timestamp:
2017-03-13T17:04:29+01:00 (8 years ago)
Author:
michael2402
Message:

Do not include text label in area style - use a separate class and start merging code for on-line and in-area drawing.

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r11608 r11722  
    2626import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement;
    2727import org.openstreetmap.josm.gui.mappaint.styleelement.LineElement;
    28 import org.openstreetmap.josm.gui.mappaint.styleelement.LineTextElement;
    2928import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement;
    3029import org.openstreetmap.josm.gui.mappaint.styleelement.RepeatImageElement;
    3130import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
     31import org.openstreetmap.josm.gui.mappaint.styleelement.TextElement;
    3232import org.openstreetmap.josm.gui.mappaint.styleelement.TextLabel;
    3333import org.openstreetmap.josm.gui.util.GuiHelper;
     
    366366            env.layer = e.getKey();
    367367            if (osm instanceof Way) {
    368                 addIfNotNull(sl, AreaElement.create(env));
     368                AreaElement areaStyle = AreaElement.create(env);
     369                addIfNotNull(sl, areaStyle);
    369370                addIfNotNull(sl, RepeatImageElement.create(env));
    370371                addIfNotNull(sl, LineElement.createLine(env));
     
    372373                addIfNotNull(sl, LineElement.createRightCasing(env));
    373374                addIfNotNull(sl, LineElement.createCasing(env));
    374                 addIfNotNull(sl, LineTextElement.create(env));
     375                addIfNotNull(sl, TextElement.create(env));
     376                if (areaStyle != null) {
     377                    //TODO: Warn about this, or even remove it completely
     378                    addIfNotNull(sl, TextElement.createForContent(env));
     379                }
    375380            } else if (osm instanceof Node) {
    376381                NodeElement nodeStyle = NodeElement.create(env);
     
    383388            } else if (osm instanceof Relation) {
    384389                if (((Relation) osm).isMultipolygon()) {
    385                     addIfNotNull(sl, AreaElement.create(env));
     390                    AreaElement areaStyle = AreaElement.create(env);
     391                    addIfNotNull(sl, areaStyle);
    386392                    addIfNotNull(sl, RepeatImageElement.create(env));
    387393                    addIfNotNull(sl, LineElement.createLine(env));
    388394                    addIfNotNull(sl, LineElement.createCasing(env));
    389                     addIfNotNull(sl, LineTextElement.create(env));
     395                    addIfNotNull(sl, TextElement.create(env));
     396                    if (areaStyle != null) {
     397                        //TODO: Warn about this, or even remove it completely
     398                        addIfNotNull(sl, TextElement.createForContent(env));
     399                    }
    390400                } else if (osm.hasTag("type", "restriction")) {
    391401                    addIfNotNull(sl, NodeElement.create(env));
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java

    r11720 r11722  
    1010import org.openstreetmap.josm.data.osm.Way;
    1111import org.openstreetmap.josm.data.osm.visitor.paint.MapPaintSettings;
    12 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors;
    1312import org.openstreetmap.josm.data.osm.visitor.paint.StyledMapRenderer;
    1413import org.openstreetmap.josm.data.preferences.IntegerProperty;
    1514import org.openstreetmap.josm.gui.mappaint.Cascade;
    1615import org.openstreetmap.josm.gui.mappaint.Environment;
    17 import org.openstreetmap.josm.gui.mappaint.Keyword;
    1816import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.IconReference;
    1917import org.openstreetmap.josm.gui.util.RotationAngle;
     
    120118        }
    121119
    122         TextLabel text = null;
    123         Keyword textPos = c.get(TEXT_POSITION, null, Keyword.class);
    124         if (textPos == null || "center".equals(textPos.val)) {
    125             text = TextLabel.create(env, PaintColors.AREA_TEXT.get(), true);
    126         }
     120        TextLabel text = null; // <- text is handled by TextElement
    127121        MapImage iconImage = NodeElement.createIcon(env);
    128122        RotationAngle rotationAngle = NodeElement.createRotationAngle(env);
    129123
    130         if (iconImage != null || text != null) {
     124        if (iconImage != null) {
    131125            // fake a transparent color.
    132126            color = new Color(0, 0, 0, 0);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineTextElement.java

    r9371 r11722  
    1313import org.openstreetmap.josm.gui.mappaint.Keyword;
    1414
     15/**
     16 * A text that is only on the line
     17 * @deprecated since 11722. To be removed summer 2017
     18 */
     19@Deprecated
    1520public class LineTextElement extends StyleElement {
    1621
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/TextLabel.java

    r11717 r11722  
    1515import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.StaticLabelCompositionStrategy;
    1616import org.openstreetmap.josm.gui.mappaint.styleelement.LabelCompositionStrategy.TagLookupCompositionStrategy;
     17import org.openstreetmap.josm.gui.mappaint.styleelement.PositionForAreaStrategy.CompletelyInsideAreaStrategy;
    1718import org.openstreetmap.josm.tools.CheckParameterUtil;
    1819import org.openstreetmap.josm.tools.Utils;
     
    5455     */
    5556    public Color haloColor;
     57
     58    /**
     59     * The position strategy for this text label.
     60     */
     61    private final PositionForAreaStrategy labelPositionSteategy;
    5662
    5763    /**
     
    6672     * @param haloRadius halo radius
    6773     * @param haloColor halo color
    68      */
     74     * @deprecated since 11722, To be removed in mid-2017
     75     */
     76    @Deprecated
    6977    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");
    7497        this.xOffset = xOffset;
    7598        this.yOffset = yOffset;
    76         this.color = color;
     99        this.color = Objects.requireNonNull(color, "color");
    77100        this.haloRadius = haloRadius;
    78101        this.haloColor = haloColor;
     102        this.labelPositionSteategy = Objects.requireNonNull(labelPositionSteategy, "labelPositionSteategy");
    79103    }
    80104
     
    92116        this.haloColor = other.haloColor;
    93117        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;
    94136    }
    95137
     
    177219        }
    178220
    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);
    180225    }
    181226
     
    190235        if (labelCompositionStrategy == null) return null;
    191236        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);
    192250    }
    193251
Note: See TracChangeset for help on using the changeset viewer.