You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MixedLength.java 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.datatypes;
  8. import java.util.Vector;
  9. import java.util.Enumeration;
  10. import org.apache.fop.fo.expr.Numeric;
  11. import org.apache.fop.fo.expr.PropertyException;
  12. /**
  13. * A length quantity in XSL which is specified with a mixture
  14. * of absolute and relative and/or percent components.
  15. * The actual value may not be computable before layout is done.
  16. */
  17. public class MixedLength extends Length {
  18. private Vector lengths ;
  19. public MixedLength(Vector lengths) {
  20. this.lengths = lengths;
  21. }
  22. protected void computeValue() {
  23. int computedValue = 0;
  24. boolean bAllComputed = true;
  25. Enumeration e = lengths.elements();
  26. while (e.hasMoreElements()) {
  27. Length l = (Length) e.nextElement();
  28. computedValue += l.mvalue();
  29. if (! l.isComputed()) {
  30. bAllComputed = false;
  31. }
  32. }
  33. setComputedValue(computedValue, bAllComputed);
  34. }
  35. public double getTableUnits() {
  36. double tableUnits = 0.0;
  37. Enumeration e = lengths.elements();
  38. while (e.hasMoreElements()) {
  39. tableUnits += ((Length) e.nextElement()).getTableUnits();
  40. }
  41. return tableUnits;
  42. }
  43. public void resolveTableUnit(double dTableUnit) {
  44. Enumeration e = lengths.elements();
  45. while (e.hasMoreElements()) {
  46. ((Length) e.nextElement()).resolveTableUnit(dTableUnit);
  47. }
  48. }
  49. public String toString() {
  50. StringBuffer sbuf = new StringBuffer();
  51. Enumeration e = lengths.elements();
  52. while (e.hasMoreElements()) {
  53. if (sbuf.length() > 0) {
  54. sbuf.append('+');
  55. }
  56. sbuf.append(e.nextElement().toString());
  57. }
  58. return sbuf.toString();
  59. }
  60. public Numeric asNumeric() {
  61. Numeric numeric = null;
  62. for (Enumeration e = lengths.elements(); e.hasMoreElements();) {
  63. Length l = (Length) e.nextElement();
  64. if (numeric == null) {
  65. numeric = l.asNumeric();
  66. } else {
  67. try {
  68. Numeric sum = numeric.add(l.asNumeric());
  69. numeric = sum;
  70. } catch (PropertyException pe) {
  71. System.err.println(
  72. "Can't convert MixedLength to Numeric: " + pe);
  73. }
  74. }
  75. }
  76. return numeric;
  77. }
  78. }