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

Last change on this file since 3896 was 3896, checked in by bastiK, 13 years ago

allow a stylesource to override the background color. This may not be the ideal solution yet, but has to do for now.

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain
File size: 3.1 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.Main;
10import org.openstreetmap.josm.data.Preferences.ColorKey;
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 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 INCOMPLETE_WAY(marktr("incomplete way"), new Color(0,0,96)), // darker blue
27 BACKGROUND(marktr("background"), Color.BLACK),
28 HIGHLIGHT(marktr("highlight"), new Color(0, 255, 186)), // lighteal
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 public void mapPaintStylesUpdated() {
42 backgroundColorCache = null;
43 }
44
45 public void mapPaintStyleEntryUpdated(int idx) {
46 mapPaintStylesUpdated();
47 }
48 };
49
50 static {
51 MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener);
52 }
53
54 private PaintColors(String name, Color defaultColor) {
55 this.name = name;
56 this.defaultColor = defaultColor;
57 }
58
59 public String getColorName() {
60 return name;
61 }
62
63 public Color getDefault() {
64 return defaultColor;
65 }
66
67 public String getSpecialName() {
68 return null;
69 }
70
71 public Color get() {
72 return Main.pref.getColor(this);
73 }
74
75 public static void getColors() {
76 for (PaintColors c:values()) {
77 c.get();
78 }
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 backgroundColorCache = BACKGROUND.get();
96 }
97 return backgroundColorCache;
98 }
99}
Note: See TracBrowser for help on using the repository browser.