Changeset 9341 in josm for trunk/src


Ignore:
Timestamp:
2016-01-07T18:13:44+01:00 (4 years ago)
Author:
bastiK
Message:

mapcss: basic support for :selected pseudoclass (see #9891)

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
12 edited

Legend:

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

    r8846 r9341  
    2323
    2424    private Map<String, Object> prop = new HashMap<>();
     25
     26    private boolean defaultSelectedHandling = true;
    2527
    2628    private static final Pattern HEX_COLOR_PATTERN = Pattern.compile("#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})");
     
    225227        return prop.containsKey(key);
    226228    }
     229
     230    public boolean isDefaultSelectedHandling() {
     231        return defaultSelectedHandling;
     232    }
     233
     234    public void setDefaultSelectedHandling(boolean defaultSelectedHandling) {
     235        this.defaultSelectedHandling = defaultSelectedHandling;
     236    }
    227237}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/DividedScale.java

    r9284 r9341  
    124124        if (bd.get(i) == lower) {
    125125            if (upper > bd.get(i+1))
    126                 throw new StyleCache.RangeViolatedError("the new range must be within a single subrange (1)");
     126                throw new RangeViolatedError("the new range must be within a single subrange (1)");
    127127            if (data.get(i) != null)
    128                 throw new StyleCache.RangeViolatedError("the new range must be within a subrange that has no data");
     128                throw new RangeViolatedError("the new range must be within a subrange that has no data");
    129129
    130130            if (bd.get(i+1) == upper) {
     
    142142        } else {
    143143            if (bd.get(i) < upper)
    144                 throw new StyleCache.RangeViolatedError("the new range must be within a single subrange (2)");
     144                throw new RangeViolatedError("the new range must be within a single subrange (2)");
    145145            if (data.get(i-1) != null)
    146146                throw new AssertionError();
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r9284 r9341  
    2121import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache;
    2222import org.openstreetmap.josm.gui.NavigatableComponent;
     23import org.openstreetmap.josm.gui.mappaint.DividedScale.RangeViolatedError;
    2324import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2425import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement;
     
    9798            osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE;
    9899        } else {
    99             Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale);
     100            Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale, osm.isSelected());
    100101            if (lst.a != null)
    101102                return lst;
     
    146147        StyleCache style = osm.mappaintStyle != null ? osm.mappaintStyle : StyleCache.EMPTY_STYLECACHE;
    147148        try {
    148             osm.mappaintStyle = style.put(p.a, p.b);
    149         } catch (StyleCache.RangeViolatedError e) {
     149            osm.mappaintStyle = style.put(p.a, p.b, osm.isSelected());
     150        } catch (RangeViolatedError e) {
    150151            throw new AssertionError("Range violated: " + e.getMessage()
    151152                    + " (object: " + osm.getPrimitiveId() + ", current style: "+osm.mappaintStyle
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java

    r9284 r9341  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import java.util.Arrays;
     5
    46import org.openstreetmap.josm.data.osm.Storage;
     7import org.openstreetmap.josm.tools.Pair;
    58
    69/**
    710 * Caches styles for a single primitive.
    811 */
    9 public final class StyleCache extends DividedScale<StyleElementList> {
     12public final class StyleCache {
    1013
    1114    // TODO: clean up the intern pool from time to time (after purge or layer removal)
     
    1417    public static final StyleCache EMPTY_STYLECACHE = (new StyleCache()).intern();
    1518
     19    private static final int PLAIN = 0;
     20    private static final int SELECTED = 1;
     21
     22    @SuppressWarnings("unchecked")
     23    private final DividedScale<StyleElementList>[] states = (DividedScale<StyleElementList>[]) new DividedScale[2];
     24
    1625    private StyleCache(StyleCache sc) {
    17         super(sc);
     26        states[0] = sc.states[0];
     27        states[1] = sc.states[1];
    1828    }
    1929
    2030    private StyleCache() {
    21         super();
    2231    }
    2332
    24     /**
    25      * Add data object which is valid for the given range.
    26      *
    27      * This is only possible, if there is no data for the given range yet.
    28      *
    29      * @param o data object
    30      * @param r the valid range
    31      * @return a new, updated, <code>DividedScale</code> object
    32      */
    33     @Override
    34     public StyleCache put(StyleElementList o, Range r) {
     33    public StyleCache put(StyleElementList o, Range r, boolean selected) {
    3534        StyleCache s = new StyleCache(this);
    36         s.putImpl(o, r.getLower(), r.getUpper());
    37         s.consistencyTest();
     35
     36        int idx = getIndex(selected);
     37        DividedScale<StyleElementList> ds = s.states[idx];
     38        if (ds == null) {
     39            ds = s.states[idx] = new DividedScale<>();
     40        }
     41        ds.putImpl(o, r.getLower(), r.getUpper());
     42        ds.consistencyTest();
    3843        s.intern();
    3944        return s;
     45    }
     46
     47    public Pair<StyleElementList, Range> getWithRange(double scale, boolean selected) {
     48        int idx = getIndex(selected);
     49        if (states[idx] == null) {
     50            return Pair.create(null, Range.ZERO_TO_INFINITY);
     51        }
     52        return states[idx].getWithRange(scale);
     53    }
     54
     55    private int getIndex(boolean selected) {
     56        return selected ? SELECTED : PLAIN;
     57    }
     58
     59    @Override
     60    public int hashCode() {
     61        return Arrays.deepHashCode(this.states);
     62    }
     63
     64    @Override
     65    public boolean equals(Object obj) {
     66        if (obj == null) {
     67            return false;
     68        }
     69        if (getClass() != obj.getClass()) {
     70            return false;
     71        }
     72        final StyleCache other = (StyleCache) obj;
     73        return Arrays.deepEquals(this.states, other.states);
    4074    }
    4175
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java

    r9099 r9341  
    5454    String TEXT_OPACITY = "text-opacity";
    5555    String TEXT_POSITION = "text-position";
     56    String WAY_DIRECTION_ARROWS = "way-direction-arrows";
    5657    String WIDTH = "width";
    5758    String Z_INDEX = "z-index";
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r9099 r9341  
    649649            return false;
    650650        }
     651
     652        static boolean selected(Environment e) {
     653            Cascade c = e.mc.getCascade(e.layer);
     654            c.setDefaultSelectedHandling(false);
     655            return e.osm.isSelected();
     656        }
    651657    }
    652658
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java

    r9323 r9341  
    138138    @Override
    139139    public int hashCode() {
    140         int hash = 3;
     140        int hash = super.hashCode();
    141141        hash = 61 * hash + color.hashCode();
    142142        hash = 61 * hash + (extent != null ? Float.floatToIntBits(extent) : 0);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java

    r9278 r9341  
    3232            c.put(Z_INDEX, -3f);
    3333        }
    34         return createLine(new Environment(null, mc, "default", null));
     34        Way w = new Way();
     35        return createLine(new Environment(w, mc, "default", null));
    3536    }
    3637
     
    4243    public float offset;
    4344    public float realWidth; // the real width of this line in meter
     45    public boolean wayDirectionArrows;
    4446
    4547    private BasicStroke dashesLine;
     
    6163
    6264    protected LineElement(Cascade c, float default_major_z_index, BasicStroke line, Color color, BasicStroke dashesLine,
    63             Color dashesBackground, float offset, float realWidth) {
     65            Color dashesBackground, float offset, float realWidth, boolean wayDirectionArrows) {
    6466        super(c, default_major_z_index);
    6567        this.line = line;
     
    6971        this.offset = offset;
    7072        this.realWidth = realWidth;
     73        this.wayDirectionArrows = wayDirectionArrows;
    7174    }
    7275
     
    264267        }
    265268
    266         return new LineElement(c, type.defaultMajorZIndex, line, color, dashesLine, dashesBackground, offset, realWidth);
     269        boolean wayDirectionArrows = c.get(type.prefix + WAY_DIRECTION_ARROWS, env.osm.isSelected(), Boolean.class);
     270
     271        return new LineElement(c, type.defaultMajorZIndex, line, color, dashesLine, dashesBackground,
     272                offset, realWidth, wayDirectionArrows);
    267273    }
    268274
     
    274280        the way is tagged with a direction key
    275281        (even if the tag is negated as in oneway=false) or the way is selected */
    276         boolean showOrientation = !isModifier && (selected || paintSettings.isShowDirectionArrow()) && !paintSettings.isUseRealWidth();
     282        boolean showOrientation;
     283        if (defaultSelectedHandling) {
     284            showOrientation = !isModifier && (selected || paintSettings.isShowDirectionArrow()) && !paintSettings.isUseRealWidth();
     285        } else {
     286            showOrientation = wayDirectionArrows;
     287        }
    277288        boolean showOneway = !isModifier && !selected &&
    278289                !paintSettings.isUseRealWidth() &&
     
    300311
    301312        Color myColor = color;
    302         if (selected) {
     313        if (defaultSelectedHandling && selected) {
    303314            myColor = paintSettings.getSelectedColor(color.getAlpha());
    304315        } else if (member || outermember) {
     
    342353            Objects.equals(dashesBackground, other.dashesBackground) &&
    343354            offset == other.offset &&
    344             realWidth == other.realWidth;
     355            realWidth == other.realWidth &&
     356            wayDirectionArrows == other.wayDirectionArrows;
    345357    }
    346358
     
    354366        hash = 29 * hash + Float.floatToIntBits(offset);
    355367        hash = 29 * hash + Float.floatToIntBits(realWidth);
     368        hash = 29 * hash + (this.wayDirectionArrows ? 1 : 0);
    356369        return hash;
    357370    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineTextElement.java

    r9278 r9341  
    5454    @Override
    5555    public int hashCode() {
    56         return text.hashCode();
     56        int hash = super.hashCode();
     57        hash = 43 * hash + text.hashCode();
     58        return hash;
    5759    }
    5860
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java

    r9284 r9341  
    285285                    if (painter.isInactiveMode() || n.isDisabled()) {
    286286                        fillColor = settings.getInactiveColor();
    287                     } else if (selected) {
     287                    } else if (defaultSelectedHandling && selected) {
    288288                        fillColor = settings.getSelectedColor(fillColor.getAlpha());
    289289                    } else if (member) {
     
    295295                    if (painter.isInactiveMode() || n.isDisabled()) {
    296296                        strokeColor = settings.getInactiveColor();
    297                     } else if (selected) {
     297                    } else if (defaultSelectedHandling && selected) {
    298298                        strokeColor = settings.getSelectedColor(strokeColor.getAlpha());
    299299                    } else if (member) {
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/RepeatImageElement.java

    r9278 r9341  
    8181    @Override
    8282    public int hashCode() {
    83         int hash = 7;
     83        int hash = super.hashCode();
    8484        hash = 83 * hash + this.pattern.hashCode();
    8585        hash = 83 * hash + Float.floatToIntBits(this.offset);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/StyleElement.java

    r9278 r9341  
    3232    public boolean isModifier;  // false, if style can serve as main style for the
    3333    // primitive; true, if it is a highlight or modifier
    34 
    35     public StyleElement(float major_z_index, float z_index, float object_z_index, boolean isModifier) {
     34    public boolean defaultSelectedHandling;
     35
     36    public StyleElement(float major_z_index, float z_index, float object_z_index, boolean isModifier, boolean defaultSelectedHandling) {
    3637        this.majorZIndex = major_z_index;
    3738        this.zIndex = z_index;
    3839        this.objectZIndex = object_z_index;
    3940        this.isModifier = isModifier;
     41        this.defaultSelectedHandling = defaultSelectedHandling;
    4042    }
    4143
     
    4547        objectZIndex = c.get(OBJECT_Z_INDEX, 0f, Float.class);
    4648        isModifier = c.get(MODIFIER, Boolean.FALSE, Boolean.class);
     49        defaultSelectedHandling = c.isDefaultSelectedHandling();
    4750    }
    4851
Note: See TracChangeset for help on using the changeset viewer.