001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm.visitor.paint; 003 004import static org.openstreetmap.josm.tools.I18n.marktr; 005 006import java.awt.Color; 007import java.util.List; 008 009import org.openstreetmap.josm.data.preferences.CachingProperty; 010import org.openstreetmap.josm.data.preferences.ColorProperty; 011import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 012import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener; 013import org.openstreetmap.josm.gui.mappaint.StyleSource; 014 015public enum PaintColors { 016 017 INACTIVE(marktr("inactive"), Color.darkGray), 018 SELECTED(marktr("selected"), Color.red), 019 RELATIONSELECTED(marktr("Relation: selected"), Color.magenta), 020 NODE(marktr("Node: standard"), Color.yellow), 021 CONNECTION(marktr("Node: connection"), Color.yellow), 022 TAGGED(marktr("Node: tagged"), new Color(204, 255, 255)), // light cyan 023 DEFAULT_WAY(marktr("way"), new Color(0, 0, 128)), // dark blue 024 RELATION(marktr("relation"), new Color(0, 128, 128)), // teal 025 UNTAGGED_WAY(marktr("untagged way"), new Color(0, 128, 0)), // dark green 026 BACKGROUND(marktr("background"), Color.BLACK), 027 HIGHLIGHT(marktr("highlight"), SELECTED.get()), 028 HIGHLIGHT_WIREFRAME(marktr("highlight wireframe"), Color.orange), 029 030 UNTAGGED(marktr("untagged"), Color.GRAY), 031 TEXT(marktr("text"), Color.WHITE), 032 AREA_TEXT(marktr("areatext"), Color.LIGHT_GRAY); 033 034 private final String name; 035 private final Color defaultColor; 036 private final ColorProperty baseProperty; 037 private final CachingProperty<Color> property; 038 039 private static volatile Color backgroundColorCache; 040 041 private static final MapPaintSylesUpdateListener styleOverrideListener = new MapPaintSylesUpdateListener() { 042 //TODO: Listen to wireframe map mode changes. 043 @Override 044 public void mapPaintStylesUpdated() { 045 backgroundColorCache = null; 046 } 047 048 @Override 049 public void mapPaintStyleEntryUpdated(int idx) { 050 mapPaintStylesUpdated(); 051 } 052 }; 053 054 static { 055 MapPaintStyles.addMapPaintSylesUpdateListener(styleOverrideListener); 056 } 057 058 PaintColors(String name, Color defaultColor) { 059 baseProperty = new ColorProperty(name, defaultColor); 060 property = baseProperty.cached(); 061 this.name = name; 062 this.defaultColor = defaultColor; 063 } 064 065 /** 066 * Gets the default value for this color. 067 * @return The default value 068 */ 069 public Color getDefaultValue() { 070 return property.getDefaultValue(); 071 } 072 073 /** 074 * Get the given color 075 * @return The color 076 */ 077 public Color get() { 078 return property.get(); 079 } 080 081 public static Color getBackgroundColor() { 082 if (backgroundColorCache != null) 083 return backgroundColorCache; 084 List<StyleSource> sources = MapPaintStyles.getStyles().getStyleSources(); 085 for (StyleSource s : sources) { 086 if (!s.active) { 087 continue; 088 } 089 Color backgroundColorOverride = s.getBackgroundColorOverride(); 090 if (backgroundColorOverride != null) { 091 backgroundColorCache = backgroundColorOverride; 092 } 093 } 094 if (backgroundColorCache == null) { 095 return BACKGROUND.get(); 096 } else { 097 return backgroundColorCache; 098 } 099 } 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}