source: josm/trunk/src/org/openstreetmap/josm/data/preferences/ColorInfo.java@ 14159

Last change on this file since 14159 was 14152, checked in by Don-vip, 6 years ago

see #15410, see #16604 - restore restart notification when mappaint colors are modified in preferences

File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.preferences;
3
4import java.awt.Color;
5import java.util.List;
6
7import org.openstreetmap.josm.tools.ColorHelper;
8
9/**
10 * Data class to hold information on a named color setting.
11 */
12public class ColorInfo {
13
14 private String category;
15 private String source;
16 private String name;
17 private Color value;
18 private Color defaultValue;
19
20 /**
21 * Constructs a new {@code ColorInfo}.
22 */
23 public ColorInfo() {
24 }
25
26 /**
27 * Constructs a new {@code ColorInfo}.
28 * @param category the category of the color setting
29 * @param source the source (related file), can be null
30 * @param name the color name
31 * @param value the color value set in the preferences, null if not set
32 * @param defaultValue the default value for this color setting, can be null
33 * @see org.openstreetmap.josm.data.preferences.NamedColorProperty
34 */
35 public ColorInfo(String category, String source, String name, Color value, Color defaultValue) {
36 this.category = category;
37 this.source = source;
38 this.name = name;
39 this.value = value;
40 this.defaultValue = defaultValue;
41 }
42
43 /**
44 * Get the category.
45 * @return the category
46 */
47 public String getCategory() {
48 return category;
49 }
50
51 /**
52 * Get the source.
53 * @return the source, can be null
54 */
55 public String getSource() {
56 return source;
57 }
58
59 /**
60 * Get the name.
61 * @return the name
62 */
63 public String getName() {
64 return name;
65 }
66
67 /**
68 * Get the color value in the preferences (if set).
69 * @return the color value, can be null
70 */
71 public Color getValue() {
72 return value;
73 }
74
75 /**
76 * Get the default value for this color setting.
77 * @return the default value, can be null
78 */
79 public Color getDefaultValue() {
80 return defaultValue;
81 }
82
83 /**
84 * Set the category.
85 * @param category the category
86 */
87 public void setCategory(String category) {
88 this.category = category;
89 }
90
91 /**
92 * Set the source.
93 * @param source the source
94 */
95 public void setSource(String source) {
96 this.source = source;
97 }
98
99 /**
100 * Set the name.
101 * @param name the name
102 */
103 public void setName(String name) {
104 this.name = name;
105 }
106
107 /**
108 * Set the color value.
109 * @param value the value
110 */
111 public void setValue(Color value) {
112 this.value = value;
113 }
114
115 /**
116 * Set the default value.
117 * @param defaultValue the default value
118 */
119 public void setDefaultValue(Color defaultValue) {
120 this.defaultValue = defaultValue;
121 }
122
123 /**
124 * Constructs a new {@code ColorInfo} from raw preference value.
125 * @param lst the list
126 * @param isDefault if the list represents a default value or not
127 * @return corresponding {@code ColorInfo} object or null in case of invalid input
128 */
129 public static ColorInfo fromPref(List<String> lst, boolean isDefault) {
130 if (lst == null || lst.size() < 4) {
131 return null;
132 }
133 Color clr = ColorHelper.html2color(lst.get(0));
134 if (clr == null) {
135 return null;
136 }
137 ColorInfo info = new ColorInfo();
138 if (isDefault) {
139 info.defaultValue = clr;
140 } else {
141 info.value = clr;
142 }
143 info.category = lst.get(1);
144 info.source = lst.get(2);
145 if (info.source.isEmpty()) {
146 info.source = null;
147 }
148 info.name = lst.get(3);
149 return info;
150 }
151
152 @Override
153 public String toString() {
154 return "ColorInfo [" + (category != null ? "category=" + category + ", " : "")
155 + (source != null ? "source=" + source + ", " : "") + (name != null ? "name=" + name + ", " : "")
156 + (value != null ? "value=" + value + ", " : "")
157 + (defaultValue != null ? "defaultValue=" + defaultValue : "") + "]";
158 }
159}
Note: See TracBrowser for help on using the repository browser.