001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm.visitor.paint; 003 004import java.awt.Color; 005 006import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; 007import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener; 008import org.openstreetmap.josm.spi.preferences.Config; 009 010/** 011 * Global mappaint settings. 012 * @since 2675 013 */ 014public final class MapPaintSettings implements PreferenceChangedListener { 015 016 /** The unique instance **/ 017 public static final MapPaintSettings INSTANCE = new MapPaintSettings(); 018 019 private boolean useRealWidth; 020 /** Preference: should directional arrows be displayed */ 021 private boolean showDirectionArrow; 022 /** Preference: should arrows for oneways be displayed */ 023 private boolean showOnewayArrow; 024 /** Preference: default width for ways segments */ 025 private int defaultSegmentWidth; 026 /** Preference: should the segment numbers of ways be displayed */ 027 private boolean showOrderNumber; 028 /** Preference: should the segment numbers of ways be displayed on selected way */ 029 private boolean showOrderNumberOnSelectedWay; 030 /** Preference: should only the last arrow of a way be displayed */ 031 private boolean showHeadArrowOnly; 032 private int showNamesDistance; 033 private int useStrokesDistance; 034 private int showIconsDistance; 035 /** Preference: size of selected nodes */ 036 private int selectedNodeSize; 037 /** Preference: size of multiply connected nodes */ 038 private int connectionNodeSize; 039 /** Preference: size of unselected nodes */ 040 private int unselectedNodeSize; 041 /** Preference: size of tagged nodes */ 042 private int taggedNodeSize; 043 /** Preference: should selected nodes be filled */ 044 private boolean fillSelectedNode; 045 /** Preference: should unselected nodes be filled */ 046 private boolean fillUnselectedNode; 047 /** Preference: should tagged nodes be filled */ 048 private boolean fillTaggedNode; 049 /** Preference: should multiply connected nodes be filled */ 050 private boolean fillConnectionNode; 051 /** Preference: should only the data area outline be drawn */ 052 private boolean outlineOnly; 053 /** Color Preference for selected objects */ 054 private Color selectedColor; 055 private Color relationSelectedColor; 056 /** Color Preference for highlighted objects */ 057 private Color highlightColor; 058 /** Color Preference for inactive objects */ 059 private Color inactiveColor; 060 /** Color Preference for nodes */ 061 private Color nodeColor; 062 /** Color Preference for tagged nodes */ 063 private Color taggedColor; 064 /** Color Preference for multiply connected nodes */ 065 private Color connectionColor; 066 /** Color Preference for tagged and multiply connected nodes */ 067 private Color taggedConnectionColor; 068 069 private MapPaintSettings() { 070 load(); 071 Config.getPref().addPreferenceChangeListener(this); 072 } 073 074 private void load() { 075 showDirectionArrow = Config.getPref().getBoolean("draw.segment.direction", false); 076 showOnewayArrow = Config.getPref().getBoolean("draw.oneway", true); 077 useRealWidth = Config.getPref().getBoolean("mappaint.useRealWidth", false); 078 defaultSegmentWidth = Config.getPref().getInt("mappaint.segment.default-width", 2); 079 080 selectedColor = PaintColors.SELECTED.get(); 081 relationSelectedColor = PaintColors.RELATIONSELECTED.get(); 082 highlightColor = PaintColors.HIGHLIGHT.get(); 083 inactiveColor = PaintColors.INACTIVE.get(); 084 nodeColor = PaintColors.NODE.get(); 085 taggedColor = PaintColors.TAGGED.get(); 086 connectionColor = PaintColors.CONNECTION.get(); 087 if (taggedColor != nodeColor) { 088 taggedConnectionColor = taggedColor; 089 } else { 090 taggedConnectionColor = connectionColor; 091 } 092 093 showOrderNumber = Config.getPref().getBoolean("draw.segment.order_number", false); 094 showOrderNumberOnSelectedWay = Config.getPref().getBoolean("draw.segment.order_number.on_selected", false); 095 showHeadArrowOnly = Config.getPref().getBoolean("draw.segment.head_only", false); 096 097 showNamesDistance = Config.getPref().getInt("mappaint.shownames", 10_000_000); 098 useStrokesDistance = Config.getPref().getInt("mappaint.strokes", 10_000_000); 099 showIconsDistance = Config.getPref().getInt("mappaint.showicons", 10_000_000); 100 101 selectedNodeSize = Config.getPref().getInt("mappaint.node.selected-size", 5); 102 unselectedNodeSize = Config.getPref().getInt("mappaint.node.unselected-size", 3); 103 connectionNodeSize = Config.getPref().getInt("mappaint.node.connection-size", 5); 104 taggedNodeSize = Config.getPref().getInt("mappaint.node.tagged-size", 3); 105 fillSelectedNode = Config.getPref().getBoolean("mappaint.node.fill-selected", true); 106 fillUnselectedNode = Config.getPref().getBoolean("mappaint.node.fill-unselected", false); 107 fillTaggedNode = Config.getPref().getBoolean("mappaint.node.fill-tagged", true); 108 fillConnectionNode = Config.getPref().getBoolean("mappaint.node.fill-connection", false); 109 110 outlineOnly = Config.getPref().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}