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

Last change on this file since 9082 was 9082, checked in by bastiK, 8 years ago

mapcss partial fill: remove [9061] code & turn it on again (see #12104)

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