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.

LengthRange.java 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 org.apache.fop.fo.Property;
  9. /**
  10. * a "progression-dimension" quantity
  11. * ex. block-progression-dimension, inline-progression-dimension
  12. * corresponds to the triplet min-height, height, max-height (or width)
  13. */
  14. public class LengthRange implements CompoundDatatype {
  15. private Property minimum;
  16. private Property optimum;
  17. private Property maximum;
  18. private static final int MINSET = 1;
  19. private static final int OPTSET = 2;
  20. private static final int MAXSET = 4;
  21. private int bfSet = 0; // bit field
  22. private boolean bChecked = false;
  23. // From CompoundDatatype
  24. public void setComponent(String sCmpnName, Property cmpnValue,
  25. boolean bIsDefault) {
  26. if (sCmpnName.equals("minimum")) {
  27. setMinimum(cmpnValue, bIsDefault);
  28. } else if (sCmpnName.equals("optimum")) {
  29. setOptimum(cmpnValue, bIsDefault);
  30. } else if (sCmpnName.equals("maximum")) {
  31. setMaximum(cmpnValue, bIsDefault);
  32. }
  33. }
  34. // From CompoundDatatype
  35. public Property getComponent(String sCmpnName) {
  36. if (sCmpnName.equals("minimum")) {
  37. return getMinimum();
  38. } else if (sCmpnName.equals("optimum")) {
  39. return getOptimum();
  40. } else if (sCmpnName.equals("maximum")) {
  41. return getMaximum();
  42. } else {
  43. return null; // SHOULDN'T HAPPEN
  44. }
  45. }
  46. /**
  47. * Set minimum value to min.
  48. * @param min A Length value specifying the minimum value for this
  49. * LengthRange.
  50. * @param bIsDefault If true, this is set as a "default" value
  51. * and not a user-specified explicit value.
  52. */
  53. protected void setMinimum(Property minimum, boolean bIsDefault) {
  54. this.minimum = minimum;
  55. if (!bIsDefault) {
  56. bfSet |= MINSET;
  57. }
  58. }
  59. /**
  60. * Set maximum value to max if it is >= optimum or optimum isn't set.
  61. * @param max A Length value specifying the maximum value for this
  62. * @param bIsDefault If true, this is set as a "default" value
  63. * and not a user-specified explicit value.
  64. */
  65. protected void setMaximum(Property max, boolean bIsDefault) {
  66. maximum = max;
  67. if (!bIsDefault) {
  68. bfSet |= MAXSET;
  69. }
  70. }
  71. /**
  72. * Set the optimum value.
  73. * @param opt A Length value specifying the optimum value for this
  74. * @param bIsDefault If true, this is set as a "default" value
  75. * and not a user-specified explicit value.
  76. */
  77. protected void setOptimum(Property opt, boolean bIsDefault) {
  78. optimum = opt;
  79. if (!bIsDefault) {
  80. bfSet |= OPTSET;
  81. }
  82. }
  83. // Minimum is prioritaire, if explicit
  84. private void checkConsistency() {
  85. if (bChecked) {
  86. return;
  87. }
  88. // Make sure max >= min
  89. // Must also control if have any allowed enum values!
  90. /**
  91. * *******************
  92. * if (minimum.mvalue() > maximum.mvalue()) {
  93. * if ((bfSet&MINSET)!=0) {
  94. * // if minimum is explicit, force max to min
  95. * if ((bfSet&MAXSET)!=0) {
  96. * // Warning: min>max, resetting max to min
  97. * log.error("forcing max to min in LengthRange");
  98. * }
  99. * maximum = minimum ;
  100. * }
  101. * else {
  102. * minimum = maximum; // minimum was default value
  103. * }
  104. * }
  105. * // Now make sure opt <= max and opt >= min
  106. * if (optimum.mvalue() > maximum.mvalue()) {
  107. * if ((bfSet&OPTSET)!=0) {
  108. * if ((bfSet&MAXSET)!=0) {
  109. * // Warning: opt > max, resetting opt to max
  110. * log.error("forcing opt to max in LengthRange");
  111. * optimum = maximum ;
  112. * }
  113. * else {
  114. * maximum = optimum; // maximum was default value
  115. * }
  116. * }
  117. * else {
  118. * // opt is default and max is explicit or default
  119. * optimum = maximum ;
  120. * }
  121. * }
  122. * else if (optimum.mvalue() < minimum.mvalue()) {
  123. * if ((bfSet&MINSET)!=0) {
  124. * // if minimum is explicit, force opt to min
  125. * if ((bfSet&OPTSET)!=0) {
  126. * log.error("forcing opt to min in LengthRange");
  127. * }
  128. * optimum = minimum ;
  129. * }
  130. * else {
  131. * minimum = optimum; // minimum was default value
  132. * }
  133. * }
  134. * *******$*******
  135. */
  136. bChecked = true;
  137. }
  138. public Property getMinimum() {
  139. checkConsistency();
  140. return this.minimum;
  141. }
  142. public Property getMaximum() {
  143. checkConsistency();
  144. return this.maximum;
  145. }
  146. public Property getOptimum() {
  147. checkConsistency();
  148. return this.optimum;
  149. }
  150. }