1 17 18 19 20 package org.apache.fop.fo.properties; 21 22 import java.awt.Color ; 23 24 import org.apache.fop.apps.FOUserAgent; 25 import org.apache.fop.datatypes.Length; 26 import org.apache.fop.datatypes.Numeric; 27 import org.apache.fop.datatypes.PercentBaseContext; 28 import org.apache.fop.fo.FObj; 29 import org.apache.fop.fo.PropertyList; 30 import org.apache.fop.fo.expr.PropertyException; 31 32 35 public class NumberProperty extends Property implements Numeric { 36 37 40 public static class Maker extends PropertyMaker { 41 42 46 public Maker(int propId) { 47 super(propId); 48 } 49 50 54 public Property convertProperty(Property p, 55 PropertyList propertyList, FObj fo) 56 throws PropertyException { 57 if (p instanceof NumberProperty) { 58 return p; 59 } 60 if (p instanceof EnumProperty) { 61 return EnumNumber.getInstance(p); 62 } 63 Number val = p.getNumber(); 64 if (val != null) { 65 return new NumberProperty(val); 66 } 67 return convertPropertyDatatype(p, propertyList, fo); 68 } 69 70 } 71 72 private Number number; 73 74 78 public NumberProperty(Number num) { 79 this.number = num; 80 } 81 82 86 public NumberProperty(double num) { 87 this.number = new Double (num); 88 } 89 90 94 public NumberProperty(int num) { 95 this.number = new Integer (num); 96 } 97 98 103 public int getDimension() { 104 return 0; 105 } 106 107 112 public double getNumericValue() { 113 return number.doubleValue(); 114 } 115 116 122 public double getNumericValue(PercentBaseContext context) { 123 return getNumericValue(); 124 } 125 126 127 public int getValue() { 128 return number.intValue(); 129 } 130 131 137 public int getValue(PercentBaseContext context) { 138 return getValue(); 139 } 140 141 146 public boolean isAbsolute() { 147 return true; 148 } 149 150 153 public Number getNumber() { 154 return this.number; 155 } 156 157 160 public Object getObject() { 161 return this.number; 162 } 163 164 168 public Numeric getNumeric() { 169 return this; 170 } 171 172 173 public Length getLength() { 174 return new FixedLength(getNumericValue(), "px"); 176 } 177 178 183 public Color getColor(FOUserAgent foUserAgent) { 184 return Color.black; 188 } 189 190 } 191 | Popular Tags |