001 // License: GPL. For details, see LICENSE file. 002 package org.openstreetmap.josm.gui.mappaint.xml; 003 004 import org.openstreetmap.josm.gui.mappaint.Range; 005 006 public 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 void init() 023 { 024 super.init(); 025 over = true; 026 widthMode = WidthMode.ABSOLUTE; 027 } 028 029 // get width for overlays 030 public float getWidth(float ref) 031 { 032 float res; 033 if(widthMode == WidthMode.ABSOLUTE) { 034 res = width; 035 } else if(widthMode == WidthMode.OFFSET) { 036 res = ref + width; 037 } else 038 { 039 if(width < 0) { 040 res = 0; 041 } else { 042 res = ref*width/100; 043 } 044 } 045 return res <= 0 ? 1 : res; 046 } 047 048 @Override 049 public int getWidth() { 050 throw new UnsupportedOperationException(); 051 } 052 053 @Override 054 public int compareTo(LinemodPrototype s) { 055 if(s.priority != priority) 056 return s.priority > priority ? 1 : -1; 057 if(!over && s.over) 058 return -1; 059 // we have no idea how to order other objects :-) 060 return 0; 061 } 062 }