Changeset 9341 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-01-07T18:13:44+01:00 (9 years ago)
- 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 23 23 24 24 private Map<String, Object> prop = new HashMap<>(); 25 26 private boolean defaultSelectedHandling = true; 25 27 26 28 private static final Pattern HEX_COLOR_PATTERN = Pattern.compile("#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})"); … … 225 227 return prop.containsKey(key); 226 228 } 229 230 public boolean isDefaultSelectedHandling() { 231 return defaultSelectedHandling; 232 } 233 234 public void setDefaultSelectedHandling(boolean defaultSelectedHandling) { 235 this.defaultSelectedHandling = defaultSelectedHandling; 236 } 227 237 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/DividedScale.java
r9284 r9341 124 124 if (bd.get(i) == lower) { 125 125 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)"); 127 127 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"); 129 129 130 130 if (bd.get(i+1) == upper) { … … 142 142 } else { 143 143 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)"); 145 145 if (data.get(i-1) != null) 146 146 throw new AssertionError(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java
r9284 r9341 21 21 import org.openstreetmap.josm.data.osm.visitor.paint.relations.MultipolygonCache; 22 22 import org.openstreetmap.josm.gui.NavigatableComponent; 23 import org.openstreetmap.josm.gui.mappaint.DividedScale.RangeViolatedError; 23 24 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 24 25 import org.openstreetmap.josm.gui.mappaint.styleelement.AreaElement; … … 97 98 osm.mappaintStyle = StyleCache.EMPTY_STYLECACHE; 98 99 } else { 99 Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale );100 Pair<StyleElementList, Range> lst = osm.mappaintStyle.getWithRange(scale, osm.isSelected()); 100 101 if (lst.a != null) 101 102 return lst; … … 146 147 StyleCache style = osm.mappaintStyle != null ? osm.mappaintStyle : StyleCache.EMPTY_STYLECACHE; 147 148 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) { 150 151 throw new AssertionError("Range violated: " + e.getMessage() 151 152 + " (object: " + osm.getPrimitiveId() + ", current style: "+osm.mappaintStyle -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleCache.java
r9284 r9341 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import java.util.Arrays; 5 4 6 import org.openstreetmap.josm.data.osm.Storage; 7 import org.openstreetmap.josm.tools.Pair; 5 8 6 9 /** 7 10 * Caches styles for a single primitive. 8 11 */ 9 public final class StyleCache extends DividedScale<StyleElementList>{12 public final class StyleCache { 10 13 11 14 // TODO: clean up the intern pool from time to time (after purge or layer removal) … … 14 17 public static final StyleCache EMPTY_STYLECACHE = (new StyleCache()).intern(); 15 18 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 16 25 private StyleCache(StyleCache sc) { 17 super(sc); 26 states[0] = sc.states[0]; 27 states[1] = sc.states[1]; 18 28 } 19 29 20 30 private StyleCache() { 21 super();22 31 } 23 32 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) { 35 34 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(); 38 43 s.intern(); 39 44 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); 40 74 } 41 75 -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleKeys.java
r9099 r9341 54 54 String TEXT_OPACITY = "text-opacity"; 55 55 String TEXT_POSITION = "text-position"; 56 String WAY_DIRECTION_ARROWS = "way-direction-arrows"; 56 57 String WIDTH = "width"; 57 58 String Z_INDEX = "z-index"; -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java
r9099 r9341 649 649 return false; 650 650 } 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 } 651 657 } 652 658 -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/AreaElement.java
r9323 r9341 138 138 @Override 139 139 public int hashCode() { 140 int hash = 3;140 int hash = super.hashCode(); 141 141 hash = 61 * hash + color.hashCode(); 142 142 hash = 61 * hash + (extent != null ? Float.floatToIntBits(extent) : 0); -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineElement.java
r9278 r9341 32 32 c.put(Z_INDEX, -3f); 33 33 } 34 return createLine(new Environment(null, mc, "default", null)); 34 Way w = new Way(); 35 return createLine(new Environment(w, mc, "default", null)); 35 36 } 36 37 … … 42 43 public float offset; 43 44 public float realWidth; // the real width of this line in meter 45 public boolean wayDirectionArrows; 44 46 45 47 private BasicStroke dashesLine; … … 61 63 62 64 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) { 64 66 super(c, default_major_z_index); 65 67 this.line = line; … … 69 71 this.offset = offset; 70 72 this.realWidth = realWidth; 73 this.wayDirectionArrows = wayDirectionArrows; 71 74 } 72 75 … … 264 267 } 265 268 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); 267 273 } 268 274 … … 274 280 the way is tagged with a direction key 275 281 (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 } 277 288 boolean showOneway = !isModifier && !selected && 278 289 !paintSettings.isUseRealWidth() && … … 300 311 301 312 Color myColor = color; 302 if ( selected) {313 if (defaultSelectedHandling && selected) { 303 314 myColor = paintSettings.getSelectedColor(color.getAlpha()); 304 315 } else if (member || outermember) { … … 342 353 Objects.equals(dashesBackground, other.dashesBackground) && 343 354 offset == other.offset && 344 realWidth == other.realWidth; 355 realWidth == other.realWidth && 356 wayDirectionArrows == other.wayDirectionArrows; 345 357 } 346 358 … … 354 366 hash = 29 * hash + Float.floatToIntBits(offset); 355 367 hash = 29 * hash + Float.floatToIntBits(realWidth); 368 hash = 29 * hash + (this.wayDirectionArrows ? 1 : 0); 356 369 return hash; 357 370 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/LineTextElement.java
r9278 r9341 54 54 @Override 55 55 public int hashCode() { 56 return text.hashCode(); 56 int hash = super.hashCode(); 57 hash = 43 * hash + text.hashCode(); 58 return hash; 57 59 } 58 60 -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r9284 r9341 285 285 if (painter.isInactiveMode() || n.isDisabled()) { 286 286 fillColor = settings.getInactiveColor(); 287 } else if ( selected) {287 } else if (defaultSelectedHandling && selected) { 288 288 fillColor = settings.getSelectedColor(fillColor.getAlpha()); 289 289 } else if (member) { … … 295 295 if (painter.isInactiveMode() || n.isDisabled()) { 296 296 strokeColor = settings.getInactiveColor(); 297 } else if ( selected) {297 } else if (defaultSelectedHandling && selected) { 298 298 strokeColor = settings.getSelectedColor(strokeColor.getAlpha()); 299 299 } else if (member) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/RepeatImageElement.java
r9278 r9341 81 81 @Override 82 82 public int hashCode() { 83 int hash = 7;83 int hash = super.hashCode(); 84 84 hash = 83 * hash + this.pattern.hashCode(); 85 85 hash = 83 * hash + Float.floatToIntBits(this.offset); -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/StyleElement.java
r9278 r9341 32 32 public boolean isModifier; // false, if style can serve as main style for the 33 33 // 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) { 36 37 this.majorZIndex = major_z_index; 37 38 this.zIndex = z_index; 38 39 this.objectZIndex = object_z_index; 39 40 this.isModifier = isModifier; 41 this.defaultSelectedHandling = defaultSelectedHandling; 40 42 } 41 43 … … 45 47 objectZIndex = c.get(OBJECT_Z_INDEX, 0f, Float.class); 46 48 isModifier = c.get(MODIFIER, Boolean.FALSE, Boolean.class); 49 defaultSelectedHandling = c.isDefaultSelectedHandling(); 47 50 } 48 51
Note:
See TracChangeset
for help on using the changeset viewer.