1 51 package org.apache.fop.datatypes; 52 53 import java.util.ArrayList ; 54 55 import org.apache.fop.fo.expr.Numeric; 56 import org.apache.fop.fo.expr.PropertyException; 57 58 63 public class MixedLength extends Length { 64 65 private ArrayList lengths ; 66 67 public MixedLength(ArrayList lengths) { 68 this.lengths = lengths; 69 } 70 71 protected void computeValue() { 72 int computedValue =0; 73 boolean bAllComputed = true; 74 for (int i = 0; i < lengths.size(); i++) { 75 Length l = (Length)lengths.get(i); 76 computedValue += l.mvalue(); 77 if (! l.isComputed()) { 78 bAllComputed = false; 79 } 80 } 81 setComputedValue(computedValue, bAllComputed); 82 } 83 84 public double getTableUnits() { 85 double tableUnits = 0.0; 86 for (int i = 0; i < lengths.size(); i++) { 87 tableUnits += ((Length)lengths.get(i)).getTableUnits(); 88 } 89 return tableUnits; 90 } 91 92 public void resolveTableUnit(double dTableUnit) { 93 for (int i = 0; i < lengths.size(); i++) { 94 ((Length)lengths.get(i)).resolveTableUnit(dTableUnit); 95 } 96 } 97 98 public String toString() { 99 StringBuffer sbuf = new StringBuffer (); 100 for (int i = 0; i < lengths.size(); i++) { 101 if (sbuf.length()>0) { 102 sbuf.append('+'); 103 } 104 sbuf.append(lengths.get(i).toString()); 105 } 106 return sbuf.toString(); 107 } 108 109 public Numeric asNumeric() { 110 Numeric numeric = null; 111 for (int i = 0; i < lengths.size(); i++) { 112 Length l = (Length)lengths.get(i); 113 if (numeric == null) { 114 numeric = l.asNumeric(); 115 } else { 116 try { 117 Numeric sum = numeric.add(l.asNumeric()); 118 numeric = sum; 119 } catch (PropertyException pe) { 120 System.err.println("Can't convert MixedLength to Numeric: " + 121 pe); 122 } 123 } 124 } 125 return numeric; 126 } 127 128 } 129 | Popular Tags |