001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.mappaint.xml;
003
004import org.openstreetmap.josm.gui.mappaint.Range;
005
006public class LinemodPrototype extends LinePrototype implements Comparable<LinemodPrototype> {
007
008    public enum WidthMode { ABSOLUTE, PERCENT, OFFSET }
009
010    public WidthMode widthMode;
011    public boolean over;
012
013    public LinemodPrototype(LinemodPrototype s, Range range) {
014        super(s, range);
015        this.over = s.over;
016        this.widthMode = s.widthMode;
017    }
018
019    /**
020     * Constructs a new {@code LinemodPrototype}.
021     */
022    public LinemodPrototype() {
023        init();
024    }
025
026    @Override
027    public final void init() {
028        super.init();
029        over = true;
030        widthMode = WidthMode.ABSOLUTE;
031    }
032
033    /** get width for overlays */
034    public float getWidth(float ref) {
035        float res;
036        if (widthMode == WidthMode.ABSOLUTE) {
037            res = width;
038        } else if (widthMode == WidthMode.OFFSET) {
039            res = ref + width;
040        } else {
041            if (width < 0) {
042                res = 0;
043            } else {
044                res = ref*width/100;
045            }
046        }
047        return res <= 0 ? 1 : res;
048    }
049
050    @Override
051    public int getWidth() {
052        throw new UnsupportedOperationException();
053    }
054
055    @Override
056    public int compareTo(LinemodPrototype s) {
057        if (s.priority != priority)
058            return s.priority > priority ? 1 : -1;
059            if (!over && s.over)
060                return -1;
061            // we have no idea how to order other objects :-)
062            return 0;
063    }
064}