1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm.visitor.paint;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.marktr;
|
---|
5 |
|
---|
6 | import java.awt.Color;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.preferences.CachingProperty;
|
---|
10 | import org.openstreetmap.josm.data.preferences.ColorProperty;
|
---|
11 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
14 |
|
---|
15 | public enum PaintColors {
|
---|
16 |
|
---|
17 | INACTIVE(marktr("inactive"), Color.darkGray),
|
---|
18 | SELECTED(marktr("selected"), Color.red),
|
---|
19 | RELATIONSELECTED(marktr("Relation: selected"), Color.magenta),
|
---|
20 | NODE(marktr("Node: standard"), Color.yellow),
|
---|
21 | CONNECTION(marktr("Node: connection"), Color.yellow),
|
---|
22 | TAGGED(marktr("Node: tagged"), new Color(204, 255, 255)), // light cyan
|
---|
23 | DEFAULT_WAY(marktr("way"), new Color(0, 0, 128)), // dark blue
|
---|
24 | RELATION(marktr("relation"), new Color(0, 128, 128)), // teal
|
---|
25 | UNTAGGED_WAY(marktr("untagged way"), new Color(0, 128, 0)), // dark green
|
---|
26 | BACKGROUND(marktr("background"), Color.BLACK),
|
---|
27 | HIGHLIGHT(marktr("highlight"), SELECTED.get()),
|
---|
28 | HIGHLIGHT_WIREFRAME(marktr("highlight wireframe"), Color.orange),
|
---|
29 |
|
---|
30 | UNTAGGED(marktr("untagged"), Color.GRAY),
|
---|
31 | TEXT(marktr("text"), Color.WHITE),
|
---|
32 | AREA_TEXT(marktr("areatext"), Color.LIGHT_GRAY);
|
---|
33 |
|
---|
34 | private final String name;
|
---|
35 | private final Color defaultColor;
|
---|
36 | private final ColorProperty baseProperty;
|
---|
37 | private final CachingProperty<Color> property;
|
---|
38 |
|
---|
39 | private static volatile Color backgroundColorCache;
|
---|
40 |
|
---|
41 | private static final MapPaintSylesUpdateListener styleOverrideListener = new MapPaintSylesUpdateListener() {
|
---|
42 | //TODO: Listen to wireframe map mode changes.
|
---|
43 | @Override
|
---|
44 | public void mapPaintStylesUpdated() {
|
---|
45 | backgroundColorCache = null;
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | public void mapPaintStyleEntryUpdated(int idx) {
|
---|
50 | mapPaintStylesUpdated();
|
---|
51 | }
|
---|
52 | };
|
---|
53 |
|
---|
54 | static {
|
---|
55 | MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener);
|
---|
56 | }
|
---|
57 |
|
---|
58 | PaintColors(String name, Color defaultColor) {
|
---|
59 | baseProperty = new ColorProperty(name, defaultColor);
|
---|
60 | property = baseProperty.cached();
|
---|
61 | this.name = name;
|
---|
62 | this.defaultColor = defaultColor;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Gets the default value for this color.
|
---|
67 | * @return The default value
|
---|
68 | */
|
---|
69 | public Color getDefaultValue() {
|
---|
70 | return property.getDefaultValue();
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * Get the given color
|
---|
75 | * @return The color
|
---|
76 | */
|
---|
77 | public Color get() {
|
---|
78 | return property.get();
|
---|
79 | }
|
---|
80 |
|
---|
81 | public static Color getBackgroundColor() {
|
---|
82 | if (backgroundColorCache != null)
|
---|
83 | return backgroundColorCache;
|
---|
84 | List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources();
|
---|
85 | for (StyleSource s : sources) {
|
---|
86 | if (!s.active) {
|
---|
87 | continue;
|
---|
88 | }
|
---|
89 | Color backgroundColorOverride = s.getBackgroundColorOverride();
|
---|
90 | if (backgroundColorOverride != null) {
|
---|
91 | backgroundColorCache = backgroundColorOverride;
|
---|
92 | }
|
---|
93 | }
|
---|
94 | if (backgroundColorCache == null) {
|
---|
95 | return BACKGROUND.get();
|
---|
96 | } else {
|
---|
97 | return backgroundColorCache;
|
---|
98 | }
|
---|
99 | }
|
---|
100 |
|
---|
101 | /**
|
---|
102 | * Get the color property
|
---|
103 | * @return The property that is used to access the color.
|
---|
104 | * @since 10874
|
---|
105 | */
|
---|
106 | public ColorProperty getProperty() {
|
---|
107 | return baseProperty;
|
---|
108 | }
|
---|
109 | }
|
---|