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.Main;
007import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent;
008import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener;
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 only the last arrow of a way be displayed */
029    private boolean showHeadArrowOnly;
030    private int showNamesDistance;
031    private int useStrokesDistance;
032    private int showIconsDistance;
033    /** Preference: size of selected nodes */
034    private int selectedNodeSize;
035    /** Preference: size of multiply connected nodes */
036    private int connectionNodeSize;
037    /** Preference: size of unselected nodes */
038    private int unselectedNodeSize;
039    /** Preference: size of tagged nodes */
040    private int taggedNodeSize;
041    /** Preference: should selected nodes be filled */
042    private boolean fillSelectedNode;
043    /** Preference: should unselected nodes be filled */
044    private boolean fillUnselectedNode;
045    /** Preference: should tagged nodes be filled */
046    private boolean fillTaggedNode;
047    /** Preference: should multiply connected nodes be filled */
048    private boolean fillConnectionNode;
049    /** Preference: should only the data area outline be drawn */
050    private boolean outlineOnly;
051    /** Color Preference for selected objects */
052    private Color selectedColor;
053    private Color relationSelectedColor;
054    /** Color Preference for hightlighted objects */
055    private Color highlightColor;
056    /** Color Preference for inactive objects */
057    private Color inactiveColor;
058    /** Color Preference for nodes */
059    private Color nodeColor;
060    /** Color Preference for tagged nodes */
061    private Color taggedColor;
062    /** Color Preference for multiply connected nodes */
063    private Color connectionColor;
064    /** Color Preference for tagged and multiply connected nodes */
065    private Color taggedConnectionColor;
066
067    private MapPaintSettings() {
068        load();
069        Main.pref.addPreferenceChangeListener(this);
070    }
071
072    private void load() {
073        showDirectionArrow = Main.pref.getBoolean("draw.segment.direction", false);
074        showOnewayArrow = Main.pref.getBoolean("draw.oneway", true);
075        useRealWidth = Main.pref.getBoolean("mappaint.useRealWidth", false);
076        defaultSegmentWidth = Main.pref.getInteger("mappaint.segment.default-width", 2);
077
078        selectedColor = PaintColors.SELECTED.get();
079        relationSelectedColor = PaintColors.RELATIONSELECTED.get();
080        highlightColor = PaintColors.HIGHLIGHT.get();
081        inactiveColor = PaintColors.INACTIVE.get();
082        nodeColor = PaintColors.NODE.get();
083        taggedColor = PaintColors.TAGGED.get();
084        connectionColor = PaintColors.CONNECTION.get();
085        if (taggedColor != nodeColor) {
086            taggedConnectionColor = taggedColor;
087        } else {
088            taggedConnectionColor = connectionColor;
089        }
090
091        showOrderNumber = Main.pref.getBoolean("draw.segment.order_number", false);
092        showHeadArrowOnly = Main.pref.getBoolean("draw.segment.head_only", false);
093
094        showNamesDistance = Main.pref.getInteger("mappaint.shownames", 10000000);
095        useStrokesDistance = Main.pref.getInteger("mappaint.strokes", 10000000);
096        showIconsDistance = Main.pref.getInteger("mappaint.showicons", 10000000);
097
098        selectedNodeSize = Main.pref.getInteger("mappaint.node.selected-size", 5);
099        unselectedNodeSize = Main.pref.getInteger("mappaint.node.unselected-size", 3);
100        connectionNodeSize = Main.pref.getInteger("mappaint.node.connection-size", 5);
101        taggedNodeSize = Main.pref.getInteger("mappaint.node.tagged-size", 3);
102        fillSelectedNode = Main.pref.getBoolean("mappaint.node.fill-selected", true);
103        fillUnselectedNode = Main.pref.getBoolean("mappaint.node.fill-unselected", false);
104        fillTaggedNode = Main.pref.getBoolean("mappaint.node.fill-tagged", true);
105        fillConnectionNode = Main.pref.getBoolean("mappaint.node.fill-connection", false);
106
107        outlineOnly = Main.pref.getBoolean("draw.data.area_outline_only", false);
108    }
109
110    @Override
111    public void preferenceChanged(PreferenceChangeEvent e) {
112        load();
113    }
114
115    /**
116     * Determines if the real width of ways should be used
117     * @return {@code true} if the real width of ways should be used
118     */
119    public boolean isUseRealWidth() {
120        return useRealWidth;
121    }
122
123    /**
124     * Determines if directional arrows should be displayed
125     * @return {@code true} if directional arrows should be displayed
126     */
127    public boolean isShowDirectionArrow() {
128        return showDirectionArrow;
129    }
130
131    /**
132     * Determines if arrows for oneways should be displayed
133     * @return {@code true} if arrows for oneways should be displayed
134     */
135    public boolean isShowOnewayArrow() {
136        return showOnewayArrow;
137    }
138
139    /**
140     * Returns color for selected objects (nodes and ways)
141     * @return color for selected objects
142     */
143    public Color getSelectedColor() {
144        return selectedColor;
145    }
146
147    /**
148     * Returns color for selected objects (nodes and ways) with a given alpha
149     * @param alpha alpha component in the range 0-255
150     * @return color for selected objects
151     */
152    public Color getSelectedColor(int alpha) {
153        return new Color(selectedColor.getRGB() & 0x00ffffff | (alpha << 24), true);
154    }
155
156    /**
157     * Returns default width for ways segments
158     * @return default width for ways segments
159     */
160    public int getDefaultSegmentWidth() {
161        return defaultSegmentWidth;
162    }
163
164    /**
165     * Returns color for selected relations
166     * @return color for selected relations
167     */
168    public Color getRelationSelectedColor() {
169        return relationSelectedColor;
170    }
171
172    /**
173     * Returns color for selected relations with a given alpha
174     * @param alpha alpha component in the range 0-255
175     * @return color for selected relations
176     */
177    public Color getRelationSelectedColor(int alpha) {
178        return new Color(relationSelectedColor.getRGB() & 0x00ffffff | (alpha << 24), true);
179    }
180
181    /**
182     * Returns color for hightlighted objects
183     * @return color for hightlighted objects
184     */
185    public Color getHighlightColor() {
186        return highlightColor;
187    }
188
189    /**
190     * Returns color for inactive objects
191     * @return color for inactive objects
192     */
193    public Color getInactiveColor() {
194        return inactiveColor;
195    }
196
197    /**
198     * Returns color for nodes
199     * @return color for nodes
200     */
201    public Color getNodeColor() {
202        return nodeColor;
203    }
204
205    /**
206     * Returns color for tagged nodes
207     * @return color for tagged nodes
208     */
209    public Color getTaggedColor() {
210        return taggedColor;
211    }
212
213    /**
214     * Returns color for multiply connected nodes
215     * @return color for multiply connected nodes
216     */
217    public Color getConnectionColor() {
218        return connectionColor;
219    }
220
221    /**
222     * Returns color for tagged and multiply connected nodes
223     * @return color for tagged and multiply connected nodes
224     */
225    public Color getTaggedConnectionColor() {
226        return taggedConnectionColor;
227    }
228
229    /**
230     * Determines if the segment numbers of ways should be displayed
231     * @return {@code true} if the segment numbers of ways should be displayed
232     */
233    public boolean isShowOrderNumber() {
234        return showOrderNumber;
235    }
236
237    /**
238     * Specifies if only the last arrow of a way should be displayed
239     * @param showHeadArrowOnly {@code true} if only the last arrow of a way should be displayed
240     */
241    public void setShowHeadArrowOnly(boolean showHeadArrowOnly) {
242        this.showHeadArrowOnly = showHeadArrowOnly;
243    }
244
245    /**
246     * Determines if only the last arrow of a way should be displayed
247     * @return {@code true} if only the last arrow of a way should be displayed
248     */
249    public boolean isShowHeadArrowOnly() {
250        return showHeadArrowOnly;
251    }
252
253    /**
254     * Returns the distance at which names should be drawn
255     * @return the distance at which names should be drawn
256     */
257    public int getShowNamesDistance() {
258        return showNamesDistance;
259    }
260
261    /**
262     * Returns the distance at which strokes should be used
263     * @return the distance at which strokes should be used
264     */
265    public int getUseStrokesDistance() {
266        return useStrokesDistance;
267    }
268
269    /**
270     * Returns the distance at which icons should be drawn
271     * @return the distance at which icons should be drawn
272     */
273    public int getShowIconsDistance() {
274        return showIconsDistance;
275    }
276
277    /**
278     * Returns the size of selected nodes
279     * @return the size of selected nodes
280     */
281    public int getSelectedNodeSize() {
282        return selectedNodeSize;
283    }
284
285    /**
286     * Returns the size of multiply connected nodes
287     * @return the size of multiply connected nodes
288     */
289    public int getConnectionNodeSize() {
290        return connectionNodeSize;
291    }
292
293    /**
294     * Returns the size of unselected nodes
295     * @return the size of unselected nodes
296     */
297    public int getUnselectedNodeSize() {
298        return unselectedNodeSize;
299    }
300
301    /**
302     * Returns the size of tagged nodes
303     * @return the size of tagged nodes
304     */
305    public int getTaggedNodeSize() {
306        return taggedNodeSize;
307    }
308
309    /**
310     * Determines if selected nodes should be filled
311     * @return {@code true} if selected nodes should be filled
312     */
313    public boolean isFillSelectedNode() {
314        return fillSelectedNode;
315    }
316
317    /**
318     * Determines if unselected nodes should be filled
319     * @return {@code true} if unselected nodes should be filled
320     */
321    public boolean isFillUnselectedNode() {
322        return fillUnselectedNode;
323    }
324
325    /**
326     * Determines if multiply connected nodes should be filled
327     * @return {@code true} if multiply connected nodes should be filled
328     */
329    public boolean isFillConnectionNode() {
330        return fillConnectionNode;
331    }
332
333    /**
334     * Determines if tagged nodes should be filled
335     * @return {@code true} if tagged nodes should be filled
336     */
337    public boolean isFillTaggedNode() {
338        return fillTaggedNode;
339    }
340
341    /**
342     * Determines if only the data area outline should be drawn
343     * @return {@code true} if only the data area outline should be drawn
344     */
345    public boolean isOutlineOnly() {
346        return outlineOnly;
347    }
348}