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.

SpaceProperty.java 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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.fo.properties;
  19. import org.apache.fop.fo.Constants;
  20. import org.apache.fop.fo.FObj;
  21. import org.apache.fop.fo.PropertyList;
  22. import org.apache.fop.fo.expr.PropertyException;
  23. import org.apache.fop.util.CompareUtil;
  24. /**
  25. * Base class used for handling properties of the fo:space-before and
  26. * fo:space-after variety. It is extended by org.apache.fop.fo.properties.GenericSpace,
  27. * which is extended by many other properties.
  28. */
  29. public class SpaceProperty extends LengthRangeProperty {
  30. private Property precedence;
  31. private Property conditionality;
  32. /**
  33. * Inner class used to create new instances of SpaceProperty
  34. */
  35. public static class Maker extends CompoundPropertyMaker {
  36. /**
  37. * @param propId the id of the property for which a Maker should be created
  38. */
  39. public Maker(int propId) {
  40. super(propId);
  41. }
  42. /**
  43. * Create a new empty instance of SpaceProperty.
  44. * @return the new instance.
  45. */
  46. public Property makeNewProperty() {
  47. return new SpaceProperty();
  48. }
  49. /**
  50. * {@inheritDoc}
  51. */
  52. public Property convertProperty(Property p,
  53. PropertyList propertyList,
  54. FObj fo) throws PropertyException {
  55. if (p instanceof SpaceProperty) {
  56. return p;
  57. }
  58. return super.convertProperty(p, propertyList, fo);
  59. }
  60. }
  61. /**
  62. * {@inheritDoc}
  63. */
  64. public void setComponent(int cmpId, Property cmpnValue,
  65. boolean bIsDefault) {
  66. if (cmpId == CP_PRECEDENCE) {
  67. setPrecedence(cmpnValue, bIsDefault);
  68. } else if (cmpId == CP_CONDITIONALITY) {
  69. setConditionality(cmpnValue, bIsDefault);
  70. } else {
  71. super.setComponent(cmpId, cmpnValue, bIsDefault);
  72. }
  73. }
  74. /**
  75. * {@inheritDoc}
  76. */
  77. public Property getComponent(int cmpId) {
  78. if (cmpId == CP_PRECEDENCE) {
  79. return getPrecedence();
  80. } else if (cmpId == CP_CONDITIONALITY) {
  81. return getConditionality();
  82. } else {
  83. return super.getComponent(cmpId);
  84. }
  85. }
  86. /**
  87. *
  88. * @param precedence precedence Property to set
  89. * @param bIsDefault (is not used anywhere)
  90. */
  91. protected void setPrecedence(Property precedence, boolean bIsDefault) {
  92. this.precedence = precedence;
  93. }
  94. /**
  95. *
  96. * @param conditionality conditionality Property to set
  97. * @param bIsDefault (is not used anywhere)
  98. */
  99. protected void setConditionality(Property conditionality,
  100. boolean bIsDefault) {
  101. this.conditionality = conditionality;
  102. }
  103. /**
  104. * @return precedence Property
  105. */
  106. public Property getPrecedence() {
  107. return this.precedence;
  108. }
  109. /**
  110. * @return conditionality Property
  111. */
  112. public Property getConditionality() {
  113. return this.conditionality;
  114. }
  115. /**
  116. * Indicates if the length can be discarded on certain conditions.
  117. * @return true if the length can be discarded.
  118. */
  119. public boolean isDiscard() {
  120. return this.conditionality.getEnum() == Constants.EN_DISCARD;
  121. }
  122. /** {@inheritDoc} */
  123. public String toString() {
  124. return "Space["
  125. + "min:" + getMinimum(null).getObject()
  126. + ", max:" + getMaximum(null).getObject()
  127. + ", opt:" + getOptimum(null).getObject()
  128. + ", precedence:" + precedence.getObject()
  129. + ", conditionality:" + conditionality.getObject() + "]";
  130. }
  131. /**
  132. * @return the Space (datatype) object contained here
  133. */
  134. public SpaceProperty getSpace() {
  135. return this;
  136. }
  137. /**
  138. * Space extends LengthRange.
  139. * @return the Space (datatype) object contained here
  140. */
  141. public LengthRangeProperty getLengthRange() {
  142. return this;
  143. }
  144. /**
  145. * @return the Space (datatype) object contained here
  146. */
  147. public Object getObject() {
  148. return this;
  149. }
  150. @Override
  151. public int hashCode() {
  152. final int prime = 31;
  153. int result = super.hashCode();
  154. result = prime * result + CompareUtil.getHashCode(precedence);
  155. result = prime * result + CompareUtil.getHashCode(conditionality);
  156. return result;
  157. }
  158. @Override
  159. public boolean equals(Object obj) {
  160. if (this == obj) {
  161. return true;
  162. }
  163. if (!(obj instanceof SpaceProperty)) {
  164. return false;
  165. }
  166. SpaceProperty other = (SpaceProperty) obj;
  167. return super.equals(obj)
  168. && CompareUtil.equal(precedence, other.precedence)
  169. && CompareUtil.equal(conditionality, other.conditionality);
  170. }
  171. }