source: josm/trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/Symbol.java@ 11797

Last change on this file since 11797 was 10875, checked in by Don-vip, 8 years ago

fix #13413 - Clean ImproveWayAccuracyAction, add new class MapViewPath (patch by michael2402, modified) - gsoc-core

  • Property svn:eol-style set to native
File size: 2.8 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.mappaint.styleelement;
3
4import java.awt.Color;
5import java.awt.Shape;
6import java.awt.Stroke;
7import java.util.Objects;
8
9import 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 */
15public 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}
Note: See TracBrowser for help on using the repository browser.