Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

LengthRange.java 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * $Id: LengthRange.java,v 1.10 2003/03/05 20:38:23 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.datatypes;
  52. import org.apache.fop.fo.Property;
  53. /**
  54. * a "progression-dimension" quantity
  55. * ex. block-progression-dimension, inline-progression-dimension
  56. * corresponds to the triplet min-height, height, max-height (or width)
  57. */
  58. public class LengthRange implements CompoundDatatype {
  59. private Property minimum;
  60. private Property optimum;
  61. private Property maximum;
  62. private static final int MINSET = 1;
  63. private static final int OPTSET = 2;
  64. private static final int MAXSET = 4;
  65. private int bfSet = 0; // bit field
  66. private boolean bChecked = false;
  67. // From CompoundDatatype
  68. public void setComponent(String sCmpnName, Property cmpnValue,
  69. boolean bIsDefault) {
  70. if (sCmpnName.equals("minimum")) {
  71. setMinimum(cmpnValue, bIsDefault);
  72. } else if (sCmpnName.equals("optimum")) {
  73. setOptimum(cmpnValue, bIsDefault);
  74. } else if (sCmpnName.equals("maximum")) {
  75. setMaximum(cmpnValue, bIsDefault);
  76. }
  77. }
  78. // From CompoundDatatype
  79. public Property getComponent(String sCmpnName) {
  80. if (sCmpnName.equals("minimum")) {
  81. return getMinimum();
  82. } else if (sCmpnName.equals("optimum")) {
  83. return getOptimum();
  84. } else if (sCmpnName.equals("maximum")) {
  85. return getMaximum();
  86. } else {
  87. return null; // SHOULDN'T HAPPEN
  88. }
  89. }
  90. /**
  91. * Set minimum value to min.
  92. * @param minimum A Length value specifying the minimum value for this
  93. * LengthRange.
  94. * @param bIsDefault If true, this is set as a "default" value
  95. * and not a user-specified explicit value.
  96. */
  97. protected void setMinimum(Property minimum, boolean bIsDefault) {
  98. this.minimum = minimum;
  99. if (!bIsDefault) {
  100. bfSet |= MINSET;
  101. }
  102. }
  103. /**
  104. * Set maximum value to max if it is >= optimum or optimum isn't set.
  105. * @param max A Length value specifying the maximum value for this
  106. * @param bIsDefault If true, this is set as a "default" value
  107. * and not a user-specified explicit value.
  108. */
  109. protected void setMaximum(Property max, boolean bIsDefault) {
  110. maximum = max;
  111. if (!bIsDefault) {
  112. bfSet |= MAXSET;
  113. }
  114. }
  115. /**
  116. * Set the optimum value.
  117. * @param opt A Length value specifying the optimum value for this
  118. * @param bIsDefault If true, this is set as a "default" value
  119. * and not a user-specified explicit value.
  120. */
  121. protected void setOptimum(Property opt, boolean bIsDefault) {
  122. optimum = opt;
  123. if (!bIsDefault) {
  124. bfSet |= OPTSET;
  125. }
  126. }
  127. // Minimum is prioritaire, if explicit
  128. private void checkConsistency() {
  129. if (bChecked) {
  130. return;
  131. }
  132. // Make sure max >= min
  133. // Must also control if have any allowed enum values!
  134. /**
  135. * *******************
  136. * if (minimum.mvalue() > maximum.mvalue()) {
  137. * if ((bfSet&MINSET)!=0) {
  138. * // if minimum is explicit, force max to min
  139. * if ((bfSet&MAXSET)!=0) {
  140. * // Warning: min>max, resetting max to min
  141. * log.error("forcing max to min in LengthRange");
  142. * }
  143. * maximum = minimum ;
  144. * }
  145. * else {
  146. * minimum = maximum; // minimum was default value
  147. * }
  148. * }
  149. * // Now make sure opt <= max and opt >= min
  150. * if (optimum.mvalue() > maximum.mvalue()) {
  151. * if ((bfSet&OPTSET)!=0) {
  152. * if ((bfSet&MAXSET)!=0) {
  153. * // Warning: opt > max, resetting opt to max
  154. * log.error("forcing opt to max in LengthRange");
  155. * optimum = maximum ;
  156. * }
  157. * else {
  158. * maximum = optimum; // maximum was default value
  159. * }
  160. * }
  161. * else {
  162. * // opt is default and max is explicit or default
  163. * optimum = maximum ;
  164. * }
  165. * }
  166. * else if (optimum.mvalue() < minimum.mvalue()) {
  167. * if ((bfSet&MINSET)!=0) {
  168. * // if minimum is explicit, force opt to min
  169. * if ((bfSet&OPTSET)!=0) {
  170. * log.error("forcing opt to min in LengthRange");
  171. * }
  172. * optimum = minimum ;
  173. * }
  174. * else {
  175. * minimum = optimum; // minimum was default value
  176. * }
  177. * }
  178. * *******$*******
  179. */
  180. bChecked = true;
  181. }
  182. public Property getMinimum() {
  183. checkConsistency();
  184. return this.minimum;
  185. }
  186. public Property getMaximum() {
  187. checkConsistency();
  188. return this.maximum;
  189. }
  190. public Property getOptimum() {
  191. checkConsistency();
  192. return this.optimum;
  193. }
  194. }