1 18 19 package org.objectweb.jac.aspects.gui; 20 21 public class Length { 22 public float value; 23 public Unit unit; 24 25 public Length(float value, Unit unit) { 26 this.value = value; 27 this.unit = unit; 28 } 29 30 public Length(String str) { 31 str = str.toLowerCase(); 32 if (str.endsWith("em")) { 33 unit = Unit.EM; 34 } else if (str.endsWith("ex")) { 35 unit = Unit.EX; 36 } else if (str.endsWith("px")) { 37 unit = Unit.PX; 38 } else { 39 throw new RuntimeException ("Unrecognized length unit for "+str); 40 } 41 value = Float.parseFloat(str.substring(0, str.length()-2)); 42 } 43 44 public String toString() { 45 return value+unit.toString(); 46 } 47 } 48 | Popular Tags |