source: josm/trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapPaintSettings.java@ 10656

Last change on this file since 10656 was 10656, checked in by Don-vip, 8 years ago

see #12472 - fix warning "ReferenceEquality"

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