Ignore:
Timestamp:
2016-08-17T20:14:58+02:00 (8 years ago)
Author:
Don-vip
Message:

fix #13306 - Make map paint code use double coordinates (patch by michael2402) - gsoc-core

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  
    77import java.awt.Stroke;
    88import java.util.Objects;
     9import java.util.Optional;
    910import java.util.stream.IntStream;
    1011
     
    2324import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.BoxProvider;
    2425import org.openstreetmap.josm.gui.mappaint.styleelement.BoxTextElement.SimpleBoxProvider;
     26import org.openstreetmap.josm.gui.mappaint.styleelement.Symbol.SymbolShape;
    2527import org.openstreetmap.josm.gui.util.RotationAngle;
    2628import org.openstreetmap.josm.tools.CheckParameterUtil;
     
    3335    public final MapImage mapImage;
    3436    public final RotationAngle mapImageAngle;
     37    /**
     38     * The symbol that should be used for drawing this node.
     39     */
    3540    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         @Override
    59         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         @Override
    71         public int hashCode() {
    72             return Objects.hash(symbol, size, stroke, strokeColor, fillColor);
    73         }
    74 
    75         @Override
    76         public String toString() {
    77             return "symbol=" + symbol + " size=" + size +
    78                     (stroke != null ? " stroke=" + stroke + " strokeColor=" + strokeColor : "") +
    79                     (fillColor != null ? " fillColor=" + fillColor : "");
    80         }
    81     }
    8241
    8342    private static final String[] ICON_KEYS = {ICON_IMAGE, ICON_WIDTH, ICON_HEIGHT, ICON_OPACITY, ICON_OFFSET_X, ICON_OFFSET_Y};
     
    194153    private static Symbol createSymbol(Environment env) {
    195154        Cascade c = env.mc.getCascade(env.layer);
    196         Cascade cDef = env.mc.getCascade("default");
    197 
    198         SymbolShape shape;
     155
    199156        Keyword shapeKW = c.get("symbol-shape", null, Keyword.class);
    200157        if (shapeKW == null)
    201158            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()) {
    221161            return null;
    222 
     162        }
     163
     164        Cascade cDef = env.mc.getCascade("default");
    223165        Float sizeOnDefault = cDef.get("symbol-size", null, Float.class);
    224166        if (sizeOnDefault != null && sizeOnDefault <= 0) {
     
    268210        }
    269211
    270         return new Symbol(shape, Math.round(size), stroke, strokeColor, fillColor);
     212        return new Symbol(shape.get(), Math.round(size), stroke, strokeColor, fillColor);
    271213    }
    272214
     
    280222                        mapImageAngle == null ? 0.0 : mapImageAngle.getRotationAngle(primitive));
    281223            } 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);
    303225            } else {
    304226                Color color;
     
    344266    }
    345267
     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
    346293    public BoxProvider getBoxProvider() {
    347294        if (mapImage != null)
Note: See TracChangeset for help on using the changeset viewer.