[2666] | 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;
|
---|
[3896] | 7 | import java.util.List;
|
---|
[2666] | 8 |
|
---|
| 9 | import org.openstreetmap.josm.Main;
|
---|
| 10 | import org.openstreetmap.josm.data.Preferences.ColorKey;
|
---|
[3896] | 11 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
---|
[4327] | 12 | import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
---|
[3896] | 13 | import org.openstreetmap.josm.gui.mappaint.MapPaintStyles.MapPaintSylesUpdateListener;
|
---|
[2666] | 14 |
|
---|
| 15 | public enum PaintColors implements ColorKey {
|
---|
| 16 |
|
---|
| 17 | INACTIVE(marktr("inactive"), Color.darkGray),
|
---|
| 18 | SELECTED(marktr("selected"), Color.red),
|
---|
[3291] | 19 | RELATIONSELECTED(marktr("Relation: selected"), Color.magenta),
|
---|
[3180] | 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
|
---|
[2666] | 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),
|
---|
[4327] | 27 | HIGHLIGHT(marktr("highlight"), SELECTED.get()),
|
---|
[4952] | 28 | HIGHLIGHT_WIREFRAME(marktr("highlight wireframe"), Color.orange),
|
---|
[2666] | 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 |
|
---|
[3896] | 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 |
|
---|
[2666] | 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 | }
|
---|
[2675] | 74 |
|
---|
| 75 | public static void getColors() {
|
---|
| 76 | for (PaintColors c:values()) {
|
---|
| 77 | c.get();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
[3896] | 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 | }
|
---|
[2666] | 99 | }
|
---|