Changeset 10827 in josm for trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement
- Timestamp:
- 2016-08-17T20:14:58+02:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/NodeElement.java
r10760 r10827 7 7 import java.awt.Stroke; 8 8 import java.util.Objects; 9 import java.util.Optional; 9 10 import java.util.stream.IntStream; 10 11 … … 23 24 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider; 24 25 import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider; 26 import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape; 25 27 import org.openstreetmap.josm.gui.util.RotationAngle; 26 28 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 33 35 public final MapImage mapImage; 34 36 public final RotationAngle mapImageAngle; 37 /** 38 * The symbol that should be used for drawing this node. 39 */ 35 40 public final Symbol symbol; 36 37 public enum SymbolShape { SQUARE, CIRCLE, TRIANGLE, PENTAGON, HEXAGON, HEPTAGON, OCTAGON, NONAGON, DECAGON }38 39 public static class Symbol {40 public SymbolShape symbol;41 public int size;42 public Stroke stroke;43 public Color strokeColor;44 public Color fillColor;45 46 public Symbol(SymbolShape symbol, int size, Stroke stroke, Color strokeColor, Color fillColor) {47 if (stroke != null && strokeColor == null)48 throw new IllegalArgumentException("Stroke given without color");49 if (stroke == null && fillColor == null)50 throw new IllegalArgumentException("Either a stroke or a fill color must be given");51 this.symbol = symbol;52 this.size = size;53 this.stroke = stroke;54 this.strokeColor = strokeColor;55 this.fillColor = fillColor;56 }57 58 @Override59 public boolean equals(Object obj) {60 if (obj == null || getClass() != obj.getClass())61 return false;62 final Symbol other = (Symbol) obj;63 return symbol == other.symbol &&64 size == other.size &&65 Objects.equals(stroke, other.stroke) &&66 Objects.equals(strokeColor, other.strokeColor) &&67 Objects.equals(fillColor, other.fillColor);68 }69 70 @Override71 public int hashCode() {72 return Objects.hash(symbol, size, stroke, strokeColor, fillColor);73 }74 75 @Override76 public String toString() {77 return "symbol=" + symbol + " size=" + size +78 (stroke != null ? " stroke=" + stroke + " strokeColor=" + strokeColor : "") +79 (fillColor != null ? " fillColor=" + fillColor : "");80 }81 }82 41 83 42 private static final String[] ICON_KEYS = {ICON_IMAGE, ICON_WIDTH, ICON_HEIGHT, ICON_OPACITY, ICON_OFFSET_X, ICON_OFFSET_Y}; … … 194 153 private static Symbol createSymbol(Environment env) { 195 154 Cascade c = env.mc.getCascade(env.layer); 196 Cascade cDef = env.mc.getCascade("default"); 197 198 SymbolShape shape; 155 199 156 Keyword shapeKW = c.get("symbol-shape", null, Keyword.class); 200 157 if (shapeKW == null) 201 158 return null; 202 if ("square".equals(shapeKW.val)) { 203 shape = SymbolShape.SQUARE; 204 } else if ("circle".equals(shapeKW.val)) { 205 shape = SymbolShape.CIRCLE; 206 } else if ("triangle".equals(shapeKW.val)) { 207 shape = SymbolShape.TRIANGLE; 208 } else if ("pentagon".equals(shapeKW.val)) { 209 shape = SymbolShape.PENTAGON; 210 } else if ("hexagon".equals(shapeKW.val)) { 211 shape = SymbolShape.HEXAGON; 212 } else if ("heptagon".equals(shapeKW.val)) { 213 shape = SymbolShape.HEPTAGON; 214 } else if ("octagon".equals(shapeKW.val)) { 215 shape = SymbolShape.OCTAGON; 216 } else if ("nonagon".equals(shapeKW.val)) { 217 shape = SymbolShape.NONAGON; 218 } else if ("decagon".equals(shapeKW.val)) { 219 shape = SymbolShape.DECAGON; 220 } else 159 Optional<SymbolShape> shape = SymbolShape.forName(shapeKW.val); 160 if (!shape.isPresent()) { 221 161 return null; 222 162 } 163 164 Cascade cDef = env.mc.getCascade("default"); 223 165 Float sizeOnDefault = cDef.get("symbol-size", null, Float.class); 224 166 if (sizeOnDefault != null && sizeOnDefault <= 0) { … … 268 210 } 269 211 270 return new Symbol(shape, Math.round(size), stroke, strokeColor, fillColor); 212 return new Symbol(shape.get(), Math.round(size), stroke, strokeColor, fillColor); 271 213 } 272 214 … … 280 222 mapImageAngle == null ? 0.0 : mapImageAngle.getRotationAngle(primitive)); 281 223 } else if (symbol != null) { 282 Color fillColor = symbol.fillColor; 283 if (fillColor != null) { 284 if (painter.isInactiveMode() || n.isDisabled()) { 285 fillColor = settings.getInactiveColor(); 286 } else if (defaultSelectedHandling && selected) { 287 fillColor = settings.getSelectedColor(fillColor.getAlpha()); 288 } else if (member) { 289 fillColor = settings.getRelationSelectedColor(fillColor.getAlpha()); 290 } 291 } 292 Color strokeColor = symbol.strokeColor; 293 if (strokeColor != null) { 294 if (painter.isInactiveMode() || n.isDisabled()) { 295 strokeColor = settings.getInactiveColor(); 296 } else if (defaultSelectedHandling && selected) { 297 strokeColor = settings.getSelectedColor(strokeColor.getAlpha()); 298 } else if (member) { 299 strokeColor = settings.getRelationSelectedColor(strokeColor.getAlpha()); 300 } 301 } 302 painter.drawNodeSymbol(n, symbol, fillColor, strokeColor); 224 paintWithSymbol(settings, painter, selected, member, n); 303 225 } else { 304 226 Color color; … … 344 266 } 345 267 268 private void paintWithSymbol(MapPaintSettings settings, StyledMapRenderer painter, boolean selected, boolean member, 269 Node n) { 270 Color fillColor = symbol.fillColor; 271 if (fillColor != null) { 272 if (painter.isInactiveMode() || n.isDisabled()) { 273 fillColor = settings.getInactiveColor(); 274 } else if (defaultSelectedHandling && selected) { 275 fillColor = settings.getSelectedColor(fillColor.getAlpha()); 276 } else if (member) { 277 fillColor = settings.getRelationSelectedColor(fillColor.getAlpha()); 278 } 279 } 280 Color strokeColor = symbol.strokeColor; 281 if (strokeColor != null) { 282 if (painter.isInactiveMode() || n.isDisabled()) { 283 strokeColor = settings.getInactiveColor(); 284 } else if (defaultSelectedHandling && selected) { 285 strokeColor = settings.getSelectedColor(strokeColor.getAlpha()); 286 } else if (member) { 287 strokeColor = settings.getRelationSelectedColor(strokeColor.getAlpha()); 288 } 289 } 290 painter.drawNodeSymbol(n, symbol, fillColor, strokeColor); 291 } 292 346 293 public BoxProvider getBoxProvider() { 347 294 if (mapImage != null)
Note:
See TracChangeset
for help on using the changeset viewer.