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.

ChangeBar.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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.flow;
  19. import java.awt.Color;
  20. import org.xml.sax.Attributes;
  21. import org.xml.sax.Locator;
  22. import org.apache.fop.apps.FOPException;
  23. import org.apache.fop.datatypes.Length;
  24. import org.apache.fop.fo.FONode;
  25. import org.apache.fop.fo.FObj;
  26. import org.apache.fop.fo.PropertyList;
  27. import org.apache.fop.fo.StaticPropertyList;
  28. import org.apache.fop.fo.ValidationException;
  29. import org.apache.fop.fo.properties.SpaceProperty;
  30. /**
  31. * Common change bar base class. Handles change bar properties and validates child nodes.
  32. */
  33. public abstract class ChangeBar extends FObj {
  34. /**
  35. * Constructs a ChangeBar element with common parts for both begin and end change bars.
  36. *
  37. * @param parent The parent node
  38. */
  39. public ChangeBar(FONode parent) {
  40. super(parent);
  41. }
  42. /**
  43. * The change bar class (required).
  44. */
  45. protected String changeBarClass;
  46. /**
  47. * The change bar color.
  48. */
  49. protected Color color;
  50. /**
  51. * The change bar offset.
  52. */
  53. protected Length offset;
  54. /**
  55. * The change bar placement.
  56. */
  57. protected int placement = -1;
  58. /**
  59. * The change bar style.
  60. */
  61. protected int style = -1;
  62. /**
  63. * The change bar width.
  64. */
  65. protected Length width;
  66. /**
  67. * The actual line height.
  68. */
  69. protected SpaceProperty lineHeight;
  70. /** {@inheritDoc} */
  71. public void bind(PropertyList pList) throws FOPException {
  72. super.bind(pList);
  73. changeBarClass = pList.get(PR_CHANGE_BAR_CLASS).getString();
  74. color = pList.get(PR_CHANGE_BAR_COLOR).getColor(getUserAgent());
  75. offset = pList.get(PR_CHANGE_BAR_OFFSET).getLength();
  76. placement = pList.get(PR_CHANGE_BAR_PLACEMENT).getEnum();
  77. style = pList.get(PR_CHANGE_BAR_STYLE).getEnum();
  78. width = pList.get(PR_CHANGE_BAR_WIDTH).getLength();
  79. lineHeight = pList.get(PR_LINE_HEIGHT).getSpace();
  80. }
  81. /** {@inheritDoc} */
  82. protected void validateChildNode(
  83. Locator loc,
  84. String namespaceURI,
  85. String localName) throws ValidationException {
  86. // no children allowed
  87. invalidChildError(loc, namespaceURI, localName);
  88. }
  89. /** {@inheritDoc} */
  90. public void processNode(String elementName, Locator locator,
  91. Attributes attlist, PropertyList pList) throws FOPException {
  92. super.processNode(elementName, locator, attlist, pList);
  93. if (inMarker()) {
  94. PropertyList newPList = new StaticPropertyList(this, null);
  95. newPList.addAttributesToList(attlist);
  96. bind(newPList);
  97. }
  98. if (changeBarClass == null || changeBarClass.isEmpty()) {
  99. missingPropertyError("change-bar-class");
  100. }
  101. if (findAncestor(FO_FLOW) == -1
  102. && findAncestor(FO_STATIC_CONTENT) == -1) {
  103. getFOValidationEventProducer().changeBarWrongAncestor(this, getName(), locator);
  104. }
  105. }
  106. /**
  107. * Adds the current change bar to the active change bar list.
  108. */
  109. protected void push() {
  110. getRoot().getLastPageSequence().pushChangeBar(this);
  111. }
  112. /**
  113. * Removes the starting counterpart of the current change bar from the active change bar list.
  114. */
  115. protected void pop() {
  116. getRoot().getLastPageSequence().popChangeBar(this);
  117. }
  118. /**
  119. * Returns the starting counterpart of the current (ending) change bar.
  120. *
  121. * @return The starting counterpart of the current (ending) change bar
  122. */
  123. protected ChangeBar getChangeBarBegin() {
  124. return getRoot().getLastPageSequence().getChangeBarBegin(this);
  125. }
  126. /**
  127. * Returns the change bar class.
  128. *
  129. * @return The change bar class
  130. */
  131. public String getChangeBarClass() {
  132. return changeBarClass;
  133. }
  134. /**
  135. * Returns the change bar color.
  136. *
  137. * @return The change bar color
  138. */
  139. public Color getColor() {
  140. return color;
  141. }
  142. /**
  143. * Returns the change bar offset.
  144. *
  145. * @return The change bar offset
  146. */
  147. public Length getOffset() {
  148. return offset;
  149. }
  150. /**
  151. * Returns the change bar placement.
  152. *
  153. * @return The change bar placement
  154. */
  155. public int getPlacement() {
  156. return placement;
  157. }
  158. /**
  159. * Returns the change bar style.
  160. *
  161. * @return The change bar style
  162. */
  163. public int getStyle() {
  164. return style;
  165. }
  166. /**
  167. * Returns the change bar width.
  168. *
  169. * @return The change bar width
  170. */
  171. public Length getWidth() {
  172. return width;
  173. }
  174. /**
  175. * Returns the line height.
  176. *
  177. * @return The line height
  178. */
  179. public SpaceProperty getLineHeight() {
  180. return lineHeight;
  181. }
  182. }