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.

AbstractGraphicsDrawingOrderContainer.java 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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.afp.goca;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. import java.util.Collection;
  22. import java.util.Iterator;
  23. import java.util.List;
  24. import org.apache.fop.afp.Completable;
  25. import org.apache.fop.afp.Startable;
  26. import org.apache.fop.afp.StructuredData;
  27. import org.apache.fop.afp.modca.AbstractNamedAFPObject;
  28. /**
  29. * A base container of prepared structured AFP objects
  30. */
  31. public abstract class AbstractGraphicsDrawingOrderContainer extends AbstractNamedAFPObject
  32. implements StructuredData, Completable, Startable {
  33. /** list of objects contained within this container */
  34. protected List/*<StructuredDataObject>*/ objects
  35. = new java.util.ArrayList/*<StructuredDataObject>*/();
  36. /** object is complete */
  37. private boolean complete = false;
  38. /** object has started */
  39. private boolean started = false;
  40. private int dataLength = 0;
  41. /**
  42. * Default constructor
  43. */
  44. protected AbstractGraphicsDrawingOrderContainer() {
  45. }
  46. /**
  47. * Named constructor
  48. *
  49. * @param name the name of the container
  50. */
  51. protected AbstractGraphicsDrawingOrderContainer(String name) {
  52. super(name);
  53. }
  54. /** {@inheritDoc} */
  55. protected void writeStart(OutputStream os) throws IOException {
  56. setStarted(true);
  57. }
  58. /** {@inheritDoc} */
  59. protected void writeContent(OutputStream os) throws IOException {
  60. writeObjects(objects, os);
  61. }
  62. /**
  63. * Adds a given graphics object to this container
  64. *
  65. * @param object the structured data object
  66. */
  67. public void addObject(StructuredData object) {
  68. objects.add(object);
  69. dataLength += object.getDataLength();
  70. }
  71. /**
  72. * Adds all the contents of a given graphics container to this container
  73. *
  74. * @param graphicsContainer a graphics container
  75. */
  76. public void addAll(AbstractGraphicsDrawingOrderContainer graphicsContainer) {
  77. Collection/*<StructuredDataObject>*/ objects = graphicsContainer.getObjects();
  78. objects.addAll(objects);
  79. dataLength += graphicsContainer.getDataLength();
  80. }
  81. /**
  82. * Returns all the objects in this container
  83. *
  84. * @return all the objects in this container
  85. */
  86. private Collection getObjects() {
  87. return this.objects;
  88. }
  89. /**
  90. * Removes the last drawing order from this container and returns it
  91. *
  92. * @return the last drawing order from this container or null if empty
  93. */
  94. public StructuredData removeLast() {
  95. int lastIndex = objects.size() - 1;
  96. StructuredData object = null;
  97. if (lastIndex >= 0) {
  98. object = (StructuredData)objects.remove(lastIndex);
  99. }
  100. if (object != null) {
  101. dataLength -= object.getDataLength();
  102. }
  103. return object;
  104. }
  105. /**
  106. * Returns the current data length
  107. *
  108. * @return the current data length of this container including
  109. * all enclosed objects (and their containers)
  110. */
  111. public int getDataLength() {
  112. return this.dataLength;
  113. }
  114. /** {@inheritDoc} */
  115. public void setComplete(boolean complete) {
  116. Iterator it = objects.iterator();
  117. while (it.hasNext()) {
  118. Object object = it.next();
  119. if (object instanceof Completable) {
  120. ((Completable)object).setComplete(true);
  121. }
  122. }
  123. this.complete = true;
  124. }
  125. /** {@inheritDoc} */
  126. public boolean isComplete() {
  127. return this.complete;
  128. }
  129. /** {@inheritDoc} */
  130. public boolean isStarted() {
  131. return this.started;
  132. }
  133. /** {@inheritDoc} */
  134. public void setStarted(boolean started) {
  135. this.started = started;
  136. }
  137. }