1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.osm.visitor.paint;
|
---|
3 |
|
---|
4 | import java.awt.Color;
|
---|
5 |
|
---|
6 | import org.openstreetmap.josm.Main;
|
---|
7 | import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
|
---|
8 | import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * Global mappaint settings.
|
---|
12 | * @since 2675
|
---|
13 | */
|
---|
14 | public final class MapPaintSettings implements PreferenceChangedListener {
|
---|
15 |
|
---|
16 | /** The unique instance **/
|
---|
17 | public static final MapPaintSettings INSTANCE = new MapPaintSettings();
|
---|
18 |
|
---|
19 | private boolean useRealWidth;
|
---|
20 | /** Preference: should directional arrows be displayed */
|
---|
21 | private boolean showDirectionArrow;
|
---|
22 | /** Preference: should arrows for oneways be displayed */
|
---|
23 | private boolean showOnewayArrow;
|
---|
24 | /** Preference: default width for ways segments */
|
---|
25 | private int defaultSegmentWidth;
|
---|
26 | /** Preference: should the segment numbers of ways be displayed */
|
---|
27 | private boolean showOrderNumber;
|
---|
28 | /** Preference: should the segment numbers of ways be displayed on selected way */
|
---|
29 | private boolean showOrderNumberOnSelectedWay;
|
---|
30 | /** Preference: should only the last arrow of a way be displayed */
|
---|
31 | private boolean showHeadArrowOnly;
|
---|
32 | private int showNamesDistance;
|
---|
33 | private int useStrokesDistance;
|
---|
34 | private int showIconsDistance;
|
---|
35 | /** Preference: size of selected nodes */
|
---|
36 | private int selectedNodeSize;
|
---|
37 | /** Preference: size of multiply connected nodes */
|
---|
38 | private int connectionNodeSize;
|
---|
39 | /** Preference: size of unselected nodes */
|
---|
40 | private int unselectedNodeSize;
|
---|
41 | /** Preference: size of tagged nodes */
|
---|
42 | private int taggedNodeSize;
|
---|
43 | /** Preference: should selected nodes be filled */
|
---|
44 | private boolean fillSelectedNode;
|
---|
45 | /** Preference: should unselected nodes be filled */
|
---|
46 | private boolean fillUnselectedNode;
|
---|
47 | /** Preference: should tagged nodes be filled */
|
---|
48 | private boolean fillTaggedNode;
|
---|
49 | /** Preference: should multiply connected nodes be filled */
|
---|
50 | private boolean fillConnectionNode;
|
---|
51 | /** Preference: should only the data area outline be drawn */
|
---|
52 | private boolean outlineOnly;
|
---|
53 | /** Color Preference for selected objects */
|
---|
54 | private Color selectedColor;
|
---|
55 | private Color relationSelectedColor;
|
---|
56 | /** Color Preference for hightlighted objects */
|
---|
57 | private Color highlightColor;
|
---|
58 | /** Color Preference for inactive objects */
|
---|
59 | private Color inactiveColor;
|
---|
60 | /** Color Preference for nodes */
|
---|
61 | private Color nodeColor;
|
---|
62 | /** Color Preference for tagged nodes */
|
---|
63 | private Color taggedColor;
|
---|
64 | /** Color Preference for multiply connected nodes */
|
---|
65 | private Color connectionColor;
|
---|
66 | /** Color Preference for tagged and multiply connected nodes */
|
---|
67 | private Color taggedConnectionColor;
|
---|
68 |
|
---|
69 | private MapPaintSettings() {
|
---|
70 | load();
|
---|
71 | Main.pref.addPreferenceChangeListener(this);
|
---|
72 | }
|
---|
73 |
|
---|
74 | private void load() {
|
---|
75 | showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", false);
|
---|
76 | showOnewayArrow = Main.pref.getBoolean("draw.oneway", true);
|
---|
77 | useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth", false);
|
---|
78 | defaultSegmentWidth = Main.pref.getInt("mappaint.segment.default-width", 2);
|
---|
79 |
|
---|
80 | selectedColor = PaintColors.SELECTED.get();
|
---|
81 | relationSelectedColor = PaintColors.RELATIONSELECTED.get();
|
---|
82 | highlightColor = PaintColors.HIGHLIGHT.get();
|
---|
83 | inactiveColor = PaintColors.INACTIVE.get();
|
---|
84 | nodeColor = PaintColors.NODE.get();
|
---|
85 | taggedColor = PaintColors.TAGGED.get();
|
---|
86 | connectionColor = PaintColors.CONNECTION.get();
|
---|
87 | if (taggedColor != nodeColor) {
|
---|
88 | taggedConnectionColor = taggedColor;
|
---|
89 | } else {
|
---|
90 | taggedConnectionColor = connectionColor;
|
---|
91 | }
|
---|
92 |
|
---|
93 | showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false);
|
---|
94 | showOrderNumberOnSelectedWay = Main.pref.getBoolean("draw.segment.order_number.on_selected", false);
|
---|
95 | showHeadArrowOnly = Main.pref.getBoolean("draw.segment.head_only", false);
|
---|
96 |
|
---|
97 | showNamesDistance = Main.pref.getInt("mappaint.shownames", 10_000_000);
|
---|
98 | useStrokesDistance = Main.pref.getInt("mappaint.strokes", 10_000_000);
|
---|
99 | showIconsDistance = Main.pref.getInt("mappaint.showicons", 10_000_000);
|
---|
100 |
|
---|
101 | selectedNodeSize = Main.pref.getInt("mappaint.node.selected-size", 5);
|
---|
102 | unselectedNodeSize = Main.pref.getInt("mappaint.node.unselected-size", 3);
|
---|
103 | connectionNodeSize = Main.pref.getInt("mappaint.node.connection-size", 5);
|
---|
104 | taggedNodeSize = Main.pref.getInt("mappaint.node.tagged-size", 3);
|
---|
105 | fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);
|
---|
106 | fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
|
---|
107 | fillTaggedNode = Main.pref.getBoolean("mappaint.node.fill-tagged", true);
|
---|
108 | fillConnectionNode = Main.pref.getBoolean("mappaint.node.fill-connection", false);
|
---|
109 |
|
---|
110 | outlineOnly = Main.pref.getBoolean("draw.data.area_outline_only", false);
|
---|
111 | }
|
---|
112 |
|
---|
113 | @Override
|
---|
114 | public void preferenceChanged(PreferenceChangeEvent e) {
|
---|
115 | load();
|
---|
116 | }
|
---|
117 |
|
---|
118 | /**
|
---|
119 | * Determines if the real width of ways should be used
|
---|
120 | * @return {@code true} if the real width of ways should be used
|
---|
121 | */
|
---|
122 | public boolean isUseRealWidth() {
|
---|
123 | return useRealWidth;
|
---|
124 | }
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Determines if directional arrows should be displayed
|
---|
128 | * @return {@code true} if directional arrows should be displayed
|
---|
129 | */
|
---|
130 | public boolean isShowDirectionArrow() {
|
---|
131 | return showDirectionArrow;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Determines if arrows for oneways should be displayed
|
---|
136 | * @return {@code true} if arrows for oneways should be displayed
|
---|
137 | */
|
---|
138 | public boolean isShowOnewayArrow() {
|
---|
139 | return showOnewayArrow;
|
---|
140 | }
|
---|
141 |
|
---|
142 | /**
|
---|
143 | * Returns color for selected objects (nodes and ways)
|
---|
144 | * @return color for selected objects
|
---|
145 | */
|
---|
146 | public Color getSelectedColor() {
|
---|
147 | return selectedColor;
|
---|
148 | }
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Returns color for selected objects (nodes and ways) with a given alpha
|
---|
152 | * @param alpha alpha component in the range 0-255
|
---|
153 | * @return color for selected objects
|
---|
154 | */
|
---|
155 | public Color getSelectedColor(int alpha) {
|
---|
156 | return new Color((selectedColor.getRGB() & 0x00ffffff) | (alpha << 24), true);
|
---|
157 | }
|
---|
158 |
|
---|
159 | /**
|
---|
160 | * Returns default width for ways segments
|
---|
161 | * @return default width for ways segments
|
---|
162 | */
|
---|
163 | public int getDefaultSegmentWidth() {
|
---|
164 | return defaultSegmentWidth;
|
---|
165 | }
|
---|
166 |
|
---|
167 | /**
|
---|
168 | * Returns color for selected relations
|
---|
169 | * @return color for selected relations
|
---|
170 | */
|
---|
171 | public Color getRelationSelectedColor() {
|
---|
172 | return relationSelectedColor;
|
---|
173 | }
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Returns color for selected relations with a given alpha
|
---|
177 | * @param alpha alpha component in the range 0-255
|
---|
178 | * @return color for selected relations
|
---|
179 | */
|
---|
180 | public Color getRelationSelectedColor(int alpha) {
|
---|
181 | return new Color((relationSelectedColor.getRGB() & 0x00ffffff) | (alpha << 24), true);
|
---|
182 | }
|
---|
183 |
|
---|
184 | /**
|
---|
185 | * Returns color for hightlighted objects
|
---|
186 | * @return color for hightlighted objects
|
---|
187 | */
|
---|
188 | public Color getHighlightColor() {
|
---|
189 | return highlightColor;
|
---|
190 | }
|
---|
191 |
|
---|
192 | /**
|
---|
193 | * Returns color for inactive objects
|
---|
194 | * @return color for inactive objects
|
---|
195 | */
|
---|
196 | public Color getInactiveColor() {
|
---|
197 | return inactiveColor;
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * Returns color for nodes
|
---|
202 | * @return color for nodes
|
---|
203 | */
|
---|
204 | public Color getNodeColor() {
|
---|
205 | return nodeColor;
|
---|
206 | }
|
---|
207 |
|
---|
208 | /**
|
---|
209 | * Returns color for tagged nodes
|
---|
210 | * @return color for tagged nodes
|
---|
211 | */
|
---|
212 | public Color getTaggedColor() {
|
---|
213 | return taggedColor;
|
---|
214 | }
|
---|
215 |
|
---|
216 | /**
|
---|
217 | * Returns color for multiply connected nodes
|
---|
218 | * @return color for multiply connected nodes
|
---|
219 | */
|
---|
220 | public Color getConnectionColor() {
|
---|
221 | return connectionColor;
|
---|
222 | }
|
---|
223 |
|
---|
224 | /**
|
---|
225 | * Returns color for tagged and multiply connected nodes
|
---|
226 | * @return color for tagged and multiply connected nodes
|
---|
227 | */
|
---|
228 | public Color getTaggedConnectionColor() {
|
---|
229 | return taggedConnectionColor;
|
---|
230 | }
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * Determines if the segment numbers of ways should be displayed
|
---|
234 | * @return {@code true} if the segment numbers of ways should be displayed
|
---|
235 | */
|
---|
236 | public boolean isShowOrderNumber() {
|
---|
237 | return showOrderNumber;
|
---|
238 | }
|
---|
239 |
|
---|
240 | /**
|
---|
241 | * Determines if the segment numbers of the selected way should be displayed
|
---|
242 | * @return {@code true} if the segment numbers of the selected way should be displayed
|
---|
243 | */
|
---|
244 | public boolean isShowOrderNumberOnSelectedWay() {
|
---|
245 | return showOrderNumberOnSelectedWay;
|
---|
246 | }
|
---|
247 |
|
---|
248 | /**
|
---|
249 | * Specifies if only the last arrow of a way should be displayed
|
---|
250 | * @param showHeadArrowOnly {@code true} if only the last arrow of a way should be displayed
|
---|
251 | */
|
---|
252 | public void setShowHeadArrowOnly(boolean showHeadArrowOnly) {
|
---|
253 | this.showHeadArrowOnly = showHeadArrowOnly;
|
---|
254 | }
|
---|
255 |
|
---|
256 | /**
|
---|
257 | * Determines if only the last arrow of a way should be displayed
|
---|
258 | * @return {@code true} if only the last arrow of a way should be displayed
|
---|
259 | */
|
---|
260 | public boolean isShowHeadArrowOnly() {
|
---|
261 | return showHeadArrowOnly;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /**
|
---|
265 | * Returns the distance at which names should be drawn
|
---|
266 | * @return the distance at which names should be drawn
|
---|
267 | */
|
---|
268 | public int getShowNamesDistance() {
|
---|
269 | return showNamesDistance;
|
---|
270 | }
|
---|
271 |
|
---|
272 | /**
|
---|
273 | * Returns the distance at which strokes should be used
|
---|
274 | * @return the distance at which strokes should be used
|
---|
275 | */
|
---|
276 | public int getUseStrokesDistance() {
|
---|
277 | return useStrokesDistance;
|
---|
278 | }
|
---|
279 |
|
---|
280 | /**
|
---|
281 | * Returns the distance at which icons should be drawn
|
---|
282 | * @return the distance at which icons should be drawn
|
---|
283 | */
|
---|
284 | public int getShowIconsDistance() {
|
---|
285 | return showIconsDistance;
|
---|
286 | }
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * Returns the size of selected nodes
|
---|
290 | * @return the size of selected nodes
|
---|
291 | */
|
---|
292 | public int getSelectedNodeSize() {
|
---|
293 | return selectedNodeSize;
|
---|
294 | }
|
---|
295 |
|
---|
296 | /**
|
---|
297 | * Returns the size of multiply connected nodes
|
---|
298 | * @return the size of multiply connected nodes
|
---|
299 | */
|
---|
300 | public int getConnectionNodeSize() {
|
---|
301 | return connectionNodeSize;
|
---|
302 | }
|
---|
303 |
|
---|
304 | /**
|
---|
305 | * Returns the size of unselected nodes
|
---|
306 | * @return the size of unselected nodes
|
---|
307 | */
|
---|
308 | public int getUnselectedNodeSize() {
|
---|
309 | return unselectedNodeSize;
|
---|
310 | }
|
---|
311 |
|
---|
312 | /**
|
---|
313 | * Returns the size of tagged nodes
|
---|
314 | * @return the size of tagged nodes
|
---|
315 | */
|
---|
316 | public int getTaggedNodeSize() {
|
---|
317 | return taggedNodeSize;
|
---|
318 | }
|
---|
319 |
|
---|
320 | /**
|
---|
321 | * Determines if selected nodes should be filled
|
---|
322 | * @return {@code true} if selected nodes should be filled
|
---|
323 | */
|
---|
324 | public boolean isFillSelectedNode() {
|
---|
325 | return fillSelectedNode;
|
---|
326 | }
|
---|
327 |
|
---|
328 | /**
|
---|
329 | * Determines if unselected nodes should be filled
|
---|
330 | * @return {@code true} if unselected nodes should be filled
|
---|
331 | */
|
---|
332 | public boolean isFillUnselectedNode() {
|
---|
333 | return fillUnselectedNode;
|
---|
334 | }
|
---|
335 |
|
---|
336 | /**
|
---|
337 | * Determines if multiply connected nodes should be filled
|
---|
338 | * @return {@code true} if multiply connected nodes should be filled
|
---|
339 | */
|
---|
340 | public boolean isFillConnectionNode() {
|
---|
341 | return fillConnectionNode;
|
---|
342 | }
|
---|
343 |
|
---|
344 | /**
|
---|
345 | * Determines if tagged nodes should be filled
|
---|
346 | * @return {@code true} if tagged nodes should be filled
|
---|
347 | */
|
---|
348 | public boolean isFillTaggedNode() {
|
---|
349 | return fillTaggedNode;
|
---|
350 | }
|
---|
351 |
|
---|
352 | /**
|
---|
353 | * Determines if only the data area outline should be drawn
|
---|
354 | * @return {@code true} if only the data area outline should be drawn
|
---|
355 | */
|
---|
356 | public boolean isOutlineOnly() {
|
---|
357 | return outlineOnly;
|
---|
358 | }
|
---|
359 |
|
---|
360 | @Override
|
---|
361 | public String toString() {
|
---|
362 | // This is used for debugging exceptions.
|
---|
363 | return "MapPaintSettings [useRealWidth=" + useRealWidth + ", showDirectionArrow=" + showDirectionArrow
|
---|
364 | + ", showOnewayArrow=" + showOnewayArrow + ", defaultSegmentWidth=" + defaultSegmentWidth
|
---|
365 | + ", showOrderNumber=" + showOrderNumber + ", showHeadArrowOnly=" + showHeadArrowOnly
|
---|
366 | + ", showNamesDistance=" + showNamesDistance + ", useStrokesDistance=" + useStrokesDistance
|
---|
367 | + ", showIconsDistance=" + showIconsDistance + ", selectedNodeSize=" + selectedNodeSize
|
---|
368 | + ", connectionNodeSize=" + connectionNodeSize + ", unselectedNodeSize=" + unselectedNodeSize
|
---|
369 | + ", taggedNodeSize=" + taggedNodeSize + ", fillSelectedNode=" + fillSelectedNode
|
---|
370 | + ", fillUnselectedNode=" + fillUnselectedNode + ", fillTaggedNode=" + fillTaggedNode
|
---|
371 | + ", fillConnectionNode=" + fillConnectionNode + ", outlineOnly=" + outlineOnly + ", selectedColor="
|
---|
372 | + selectedColor + ", relationSelectedColor=" + relationSelectedColor + ", highlightColor="
|
---|
373 | + highlightColor + ", inactiveColor=" + inactiveColor + ", nodeColor=" + nodeColor + ", taggedColor="
|
---|
374 | + taggedColor + ", connectionColor=" + connectionColor + ", taggedConnectionColor="
|
---|
375 | + taggedConnectionColor + "]";
|
---|
376 | }
|
---|
377 |
|
---|
378 | }
|
---|