1 18 package org.apache.batik.css.engine.value; 19 20 import org.w3c.dom.DOMException ; 21 import org.w3c.dom.css.CSSPrimitiveValue; 22 23 29 public class FloatValue extends AbstractValue { 30 31 34 public static String getCssText(short unit, float value) { 35 if (unit < 0 || unit >= UNITS.length) { 36 throw new DOMException (DOMException.SYNTAX_ERR, ""); 37 } 38 String s = String.valueOf(value); 39 if (s.endsWith(".0")) { 40 s = s.substring(0, s.length() - 2); 41 } 42 return s + UNITS[unit - CSSPrimitiveValue.CSS_NUMBER]; 43 } 44 45 48 protected final static String [] UNITS = { 49 "", "%", "em", "ex", "px", "cm", "mm", "in", "pt", 50 "pc", "deg", "rad", "grad", "ms", "s", "Hz", "kHz", "" 51 }; 52 53 56 protected float floatValue; 57 58 61 protected short unitType; 62 63 66 public FloatValue(short unitType, float floatValue) { 67 this.unitType = unitType; 68 this.floatValue = floatValue; 69 } 70 71 74 public short getPrimitiveType() { 75 return unitType; 76 } 77 78 81 public float getFloatValue() { 82 return floatValue; 83 } 84 85 88 public String getCssText() { 89 return getCssText(unitType, floatValue); 90 } 91 92 95 public String toString() { 96 return getCssText(); 97 } 98 } 99 | Popular Tags |