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.

SpaceElement.java 3.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.layoutmgr;
  19. import org.apache.fop.datatypes.PercentBaseContext;
  20. import org.apache.fop.fo.Constants;
  21. import org.apache.fop.fo.properties.SpaceProperty;
  22. import org.apache.fop.traits.MinOptMax;
  23. /**
  24. * This class represents an unresolved space element.
  25. */
  26. public class SpaceElement extends UnresolvedListElementWithLength {
  27. private int precedence;
  28. /**
  29. * Main constructor
  30. * @param position the Position instance needed by the addAreas stage of the LMs.
  31. * @param space the space property
  32. * @param side the side to which this space element applies.
  33. * @param isFirst true if this is a space-before of the first area generated.
  34. * @param isLast true if this is a space-after of the last area generated.
  35. * @param context the property evaluation context
  36. */
  37. public SpaceElement(Position position, SpaceProperty space, RelSide side, boolean isFirst,
  38. boolean isLast, PercentBaseContext context) {
  39. super(position, space.getSpace().getLengthRange().toMinOptMax(context), side,
  40. space.isDiscard(), isFirst, isLast);
  41. int en = space.getSpace().getPrecedence().getEnum();
  42. if (en == Constants.EN_FORCE) {
  43. this.precedence = Integer.MAX_VALUE;
  44. } else {
  45. this.precedence = space.getSpace().getPrecedence().getNumber().intValue();
  46. }
  47. }
  48. /** @return true if the space is forcing. */
  49. public boolean isForcing() {
  50. return this.precedence == Integer.MAX_VALUE;
  51. }
  52. /** @return the precedence of the space */
  53. public int getPrecedence() {
  54. return this.precedence;
  55. }
  56. /** {@inheritDoc} */
  57. public void notifyLayoutManager(MinOptMax effectiveLength) {
  58. LayoutManager lm = getOriginatingLayoutManager();
  59. if (lm instanceof ConditionalElementListener) {
  60. ((ConditionalElementListener)lm).notifySpace(
  61. getSide(), effectiveLength);
  62. } else {
  63. log.warn("Cannot notify LM. It does not implement ConditionalElementListener:"
  64. + lm.getClass().getName());
  65. }
  66. }
  67. /** {@inheritDoc} */
  68. public String toString() {
  69. StringBuffer sb = new StringBuffer("Space[");
  70. sb.append(super.toString());
  71. sb.append(", precedence=");
  72. if (isForcing()) {
  73. sb.append("forcing");
  74. } else {
  75. sb.append(getPrecedence());
  76. }
  77. sb.append("]");
  78. return sb.toString();
  79. }
  80. }