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.Main;
|
---|
10 | import org.openstreetmap.josm.data.Preferences.ColorKey;
|
---|
11 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
12 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
13 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
|
---|
14 |
|
---|
15 | public enum PaintColors implements ColorKey {
|
---|
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 |
|
---|
37 | private static Color backgroundColorCache = null;
|
---|
38 |
|
---|
39 | private static final MapPaintSylesUpdateListener styleOverrideListener = new MapPaintSylesUpdateListener() {
|
---|
40 |
|
---|
41 | @Override
|
---|
42 | public void mapPaintStylesUpdated() {
|
---|
43 | backgroundColorCache = null;
|
---|
44 | }
|
---|
45 |
|
---|
46 | @Override
|
---|
47 | public void mapPaintStyleEntryUpdated(int idx) {
|
---|
48 | mapPaintStylesUpdated();
|
---|
49 | }
|
---|
50 | };
|
---|
51 |
|
---|
52 | static {
|
---|
53 | MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener);
|
---|
54 | }
|
---|
55 |
|
---|
56 | private PaintColors(String name, Color defaultColor) {
|
---|
57 | this.name = name;
|
---|
58 | this.defaultColor = defaultColor;
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Override
|
---|
62 | public String getColorName() {
|
---|
63 | return name;
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | public Color getDefaultValue() {
|
---|
68 | return defaultColor;
|
---|
69 | }
|
---|
70 |
|
---|
71 | @Override
|
---|
72 | public String getSpecialName() {
|
---|
73 | return null;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public Color get() {
|
---|
77 | return Main.pref.getColor(this);
|
---|
78 | }
|
---|
79 |
|
---|
80 | public static void getColors() {
|
---|
81 | for (PaintColors c:values()) {
|
---|
82 | c.get();
|
---|
83 | }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public static Color getBackgroundColor() {
|
---|
87 | if (backgroundColorCache != null)
|
---|
88 | return backgroundColorCache;
|
---|
89 | List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources();
|
---|
90 | for (StyleSource s : sources) {
|
---|
91 | if (!s.active) {
|
---|
92 | continue;
|
---|
93 | }
|
---|
94 | Color backgroundColorOverride = s.getBackgroundColorOverride();
|
---|
95 | if (backgroundColorOverride != null) {
|
---|
96 | backgroundColorCache = backgroundColorOverride;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | if (backgroundColorCache == null) {
|
---|
100 | backgroundColorCache = BACKGROUND.get();
|
---|
101 | }
|
---|
102 | return backgroundColorCache;
|
---|
103 | }
|
---|
104 | }
|
---|