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

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

PMD - VariableNamingConventions

  • Property svn:eol-style set to native
File size: 4.5 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;
8import java.util.Optional;
9
10import org.openstreetmap.josm.data.preferences.CachingProperty;
11import org.openstreetmap.josm.data.preferences.ColorProperty;
12import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
13import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
14import org.openstreetmap.josm.gui.mappaint.StyleSource;
15
16/**
17 * The colors used to paint the map, especially with the wireframe renderer
18 * <p>
19 * This enum stores the colors to be set in the preferences
20 */
21public enum PaintColors {
22
23 /**
24 * Inactive objects
25 */
26 INACTIVE(marktr("inactive"), Color.darkGray),
27 /**
28 * Currently selected objects
29 */
30 SELECTED(marktr("selected"), Color.red),
31 /**
32 * Objects that are part of a selected relation
33 */
34 RELATIONSELECTED(marktr("Relation: selected"), Color.magenta),
35 /**
36 * Normal nodes
37 */
38 NODE(marktr("Node: standard"), Color.yellow),
39 /**
40 * Connected nodes
41 */
42 CONNECTION(marktr("Node: connection"), Color.yellow),
43 /**
44 * A tagged node
45 */
46 TAGGED(marktr("Node: tagged"), new Color(204, 255, 255)), // light cyan
47 /**
48 * Default way color
49 */
50 DEFAULT_WAY(marktr("way"), new Color(0, 0, 128)), // dark blue
51 /**
52 * Relation color
53 */
54 RELATION(marktr("relation"), new Color(0, 128, 128)), // teal
55 /**
56 * Color for untagged way
57 */
58 UNTAGGED_WAY(marktr("untagged way"), new Color(0, 128, 0)), // dark green
59 /**
60 * Background of the map
61 */
62 BACKGROUND(marktr("background"), Color.BLACK),
63 /**
64 * Highlight around a selected node/way, MapCSS renderer
65 */
66 HIGHLIGHT(marktr("highlight"), SELECTED.get()),
67 /**
68 * Highlight around a selected node/way, Wireframe renderer
69 */
70 HIGHLIGHT_WIREFRAME(marktr("highlight wireframe"), Color.orange),
71
72 /**
73 * Untagged way
74 */
75 UNTAGGED(marktr("untagged"), Color.GRAY),
76 /**
77 * Default text color
78 */
79 TEXT(marktr("text"), Color.WHITE),
80 /**
81 * Default text color for areas
82 */
83 AREA_TEXT(marktr("areatext"), Color.LIGHT_GRAY);
84
85 /**
86 * The name of the color
87 */
88 private final String name;
89 private final Color defaultColor;
90 private final ColorProperty baseProperty;
91 private final CachingProperty<Color> property;
92
93 private static volatile Color backgroundColorCache;
94
95 private static final MapPaintSylesUpdateListener STYLE_OVERRIDE_LISTENER = new MapPaintSylesUpdateListener() {
96 //TODO: Listen to wireframe map mode changes.
97 @Override
98 public void mapPaintStylesUpdated() {
99 backgroundColorCache = null;
100 }
101
102 @Override
103 public void mapPaintStyleEntryUpdated(int idx) {
104 mapPaintStylesUpdated();
105 }
106 };
107
108 static {
109 MapPaintStyles.addMapPaintSylesUpdateListener(STYLE_OVERRIDE_LISTENER);
110 }
111
112 PaintColors(String name, Color defaultColor) {
113 baseProperty = new ColorProperty(name, defaultColor);
114 property = baseProperty.cached();
115 this.name = name;
116 this.defaultColor = defaultColor;
117 }
118
119 /**
120 * Gets the default value for this color.
121 * @return The default value
122 */
123 public Color getDefaultValue() {
124 return property.getDefaultValue();
125 }
126
127 /**
128 * Get the given color
129 * @return The color
130 */
131 public Color get() {
132 return property.get();
133 }
134
135 /**
136 * Returns the background color.
137 * @return the background color
138 */
139 public static Color getBackgroundColor() {
140 if (backgroundColorCache != null)
141 return backgroundColorCache;
142 List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources();
143 for (StyleSource s : sources) {
144 if (!s.active) {
145 continue;
146 }
147 Color backgroundColorOverride = s.getBackgroundColorOverride();
148 if (backgroundColorOverride != null) {
149 backgroundColorCache = backgroundColorOverride;
150 }
151 }
152 return Optional.ofNullable(backgroundColorCache).orElseGet(BACKGROUND::get);
153 }
154
155 /**
156 * Get the color property
157 * @return The property that is used to access the color.
158 * @since 10874
159 */
160 public ColorProperty getProperty() {
161 return baseProperty;
162 }
163}
Note: See TracBrowser for help on using the repository browser.