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 /** 034 * get width for overlays 035 * @param ref reference width 036 * @return width according to {@link #widthMode} with a minimal value of 1 037 */ 038 public float getWidth(float ref) { 039 float res; 040 if (widthMode == WidthMode.ABSOLUTE) { 041 res = width; 042 } else if (widthMode == WidthMode.OFFSET) { 043 res = ref + width; 044 } else { 045 if (width < 0) { 046 res = 0; 047 } else { 048 res = ref*width/100; 049 } 050 } 051 return res <= 0 ? 1 : res; 052 } 053 054 @Override 055 public int getWidth() { 056 throw new UnsupportedOperationException(); 057 } 058 059 @Override 060 public int compareTo(LinemodPrototype s) { 061 if (s.priority != priority) 062 return s.priority > priority ? 1 : -1; 063 if (!over && s.over) 064 return -1; 065 // we have no idea how to order other objects :-) 066 return 0; 067 } 068}