1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.mappaint.styleelement;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 | import java.awt.Shape;
|
---|
6 | import java.awt.Stroke;
|
---|
7 | import java.util.Objects;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.gui.draw.SymbolShape;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * The definition of a symbol that should be rendered at the node position.
|
---|
13 | * @since 10827 Extracted from {@link NodeElement}
|
---|
14 | */
|
---|
15 | public class Symbol {
|
---|
16 | private final SymbolShape symbolShape;
|
---|
17 | /**
|
---|
18 | * The width and height of this symbol
|
---|
19 | */
|
---|
20 | public final int size;
|
---|
21 | /**
|
---|
22 | * The stroke to use for the outline
|
---|
23 | */
|
---|
24 | public final Stroke stroke;
|
---|
25 | /**
|
---|
26 | * The color to draw the stroke with
|
---|
27 | */
|
---|
28 | public final Color strokeColor;
|
---|
29 | /**
|
---|
30 | * The color to fill the interiour of the shape.
|
---|
31 | */
|
---|
32 | public final Color fillColor;
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * Create a new symbol
|
---|
36 | * @param symbol The symbol type
|
---|
37 | * @param size The overall size of the symbol, both width and height are the same
|
---|
38 | * @param stroke The stroke to use for the outline
|
---|
39 | * @param strokeColor The color to draw the stroke with
|
---|
40 | * @param fillColor The color to fill the interiour of the shape.
|
---|
41 | */
|
---|
42 | public Symbol(SymbolShape symbol, int size, Stroke stroke, Color strokeColor, Color fillColor) {
|
---|
43 | if (stroke != null && strokeColor == null)
|
---|
44 | throw new IllegalArgumentException("Stroke given without color");
|
---|
45 | if (stroke == null && fillColor == null)
|
---|
46 | throw new IllegalArgumentException("Either a stroke or a fill color must be given");
|
---|
47 | this.symbolShape = symbol;
|
---|
48 | this.size = size;
|
---|
49 | this.stroke = stroke;
|
---|
50 | this.strokeColor = strokeColor;
|
---|
51 | this.fillColor = fillColor;
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public boolean equals(Object obj) {
|
---|
56 | if (obj == null || getClass() != obj.getClass())
|
---|
57 | return false;
|
---|
58 | final Symbol other = (Symbol) obj;
|
---|
59 | return symbolShape == other.symbolShape &&
|
---|
60 | size == other.size &&
|
---|
61 | Objects.equals(stroke, other.stroke) &&
|
---|
62 | Objects.equals(strokeColor, other.strokeColor) &&
|
---|
63 | Objects.equals(fillColor, other.fillColor);
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public int hashCode() {
|
---|
68 | return Objects.hash(symbolShape, size, stroke, strokeColor, fillColor);
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public String toString() {
|
---|
73 | return "symbolShape=" + symbolShape + " size=" + size +
|
---|
74 | (stroke != null ? (" stroke=" + stroke + " strokeColor=" + strokeColor) : "") +
|
---|
75 | (fillColor != null ? (" fillColor=" + fillColor) : "");
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Builds the shape for this symbol
|
---|
80 | * @param x The center x coordinate
|
---|
81 | * @param y The center y coordinate
|
---|
82 | * @return The symbol shape.
|
---|
83 | */
|
---|
84 | public Shape buildShapeAround(double x, double y) {
|
---|
85 | return symbolShape.shapeAround(x, y, size);
|
---|
86 | }
|
---|
87 | }
|
---|