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 boolean over; 009 010 public enum WidthMode { ABSOLUTE, PERCENT, OFFSET } 011 public WidthMode widthMode; 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 public LinemodPrototype() { init(); } 020 021 @Override 022 public final void init() { 023 super.init(); 024 over = true; 025 widthMode = WidthMode.ABSOLUTE; 026 } 027 028 /** get width for overlays */ 029 public float getWidth(float ref) { 030 float res; 031 if(widthMode == WidthMode.ABSOLUTE) { 032 res = width; 033 } else if(widthMode == WidthMode.OFFSET) { 034 res = ref + width; 035 } else 036 { 037 if(width < 0) { 038 res = 0; 039 } else { 040 res = ref*width/100; 041 } 042 } 043 return res <= 0 ? 1 : res; 044 } 045 046 @Override 047 public int getWidth() { 048 throw new UnsupportedOperationException(); 049 } 050 051 @Override 052 public int compareTo(LinemodPrototype s) { 053 if(s.priority != priority) 054 return s.priority > priority ? 1 : -1; 055 if(!over && s.over) 056 return -1; 057 // we have no idea how to order other objects :-) 058 return 0; 059 } 060}