source: josm/trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/PaintColors.java@ 10869

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

fix #13402 - Shift+P (make parallel ways copy) causes crash (patch by michael2402, modified) - regression - gsoc-core

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.osm.visitor.paint;
3
4import static org.openstreetmap.josm.tools.I18n.marktr;
5
6import java.awt.Color;
7import java.util.List;
8
9import org.openstreetmap.josm.data.preferences.CachingProperty;
10import org.openstreetmap.josm.data.preferences.ColorProperty;
11import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
12import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
13import org.openstreetmap.josm.gui.mappaint.StyleSource;
14
15public 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 CachingProperty<Color> property;
37
38 private static volatile Color backgroundColorCache;
39
40 private static final MapPaintSylesUpdateListener styleOverrideListener = new MapPaintSylesUpdateListener() {
41 //TODO: Listen to wireframe map mode changes.
42 @Override
43 public void mapPaintStylesUpdated() {
44 backgroundColorCache = null;
45 }
46
47 @Override
48 public void mapPaintStyleEntryUpdated(int idx) {
49 mapPaintStylesUpdated();
50 }
51 };
52
53 static {
54 MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener);
55 }
56
57 PaintColors(String name, Color defaultColor) {
58 property = new ColorProperty(name, defaultColor).cached();
59 this.name = name;
60 this.defaultColor = defaultColor;
61 }
62
63 /**
64 * Gets the default value for this color.
65 * @return The default value
66 */
67 public Color getDefaultValue() {
68 return property.getDefaultValue();
69 }
70
71 /**
72 * Get the given color
73 * @return The color
74 */
75 public Color get() {
76 return property.get();
77 }
78
79 public static Color getBackgroundColor() {
80 if (backgroundColorCache != null)
81 return backgroundColorCache;
82 List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources();
83 for (StyleSource s : sources) {
84 if (!s.active) {
85 continue;
86 }
87 Color backgroundColorOverride = s.getBackgroundColorOverride();
88 if (backgroundColorOverride != null) {
89 backgroundColorCache = backgroundColorOverride;
90 }
91 }
92 if (backgroundColorCache == null) {
93 return BACKGROUND.get();
94 } else {
95 return backgroundColorCache;
96 }
97 }
98}
Note: See TracBrowser for help on using the repository browser.