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