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.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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;
  38. /** object has started */
  39. private boolean started;
  40. /**
  41. * Default constructor
  42. */
  43. protected AbstractGraphicsDrawingOrderContainer() {
  44. }
  45. /**
  46. * Named constructor
  47. *
  48. * @param name the name of the container
  49. */
  50. protected AbstractGraphicsDrawingOrderContainer(String name) {
  51. super(name);
  52. }
  53. /** {@inheritDoc} */
  54. protected void writeStart(OutputStream os) throws IOException {
  55. setStarted(true);
  56. }
  57. /** {@inheritDoc} */
  58. protected void writeContent(OutputStream os) throws IOException {
  59. writeObjects(objects, os);
  60. }
  61. /**
  62. * Adds a given graphics object to this container
  63. *
  64. * @param object the structured data object
  65. */
  66. public void addObject(StructuredData object) {
  67. objects.add(object);
  68. }
  69. /**
  70. * Adds all the contents of a given graphics container to this container
  71. *
  72. * @param graphicsContainer a graphics container
  73. */
  74. public void addAll(AbstractGraphicsDrawingOrderContainer graphicsContainer) {
  75. Collection/*<StructuredDataObject>*/ objects = graphicsContainer.getObjects();
  76. objects.addAll(objects);
  77. }
  78. /**
  79. * Returns all the objects in this container
  80. *
  81. * @return all the objects in this container
  82. */
  83. private Collection getObjects() {
  84. return this.objects;
  85. }
  86. /**
  87. * Removes the last drawing order from this container and returns it
  88. *
  89. * @return the last drawing order from this container or null if empty
  90. */
  91. public StructuredData removeLast() {
  92. int lastIndex = objects.size() - 1;
  93. StructuredData object = null;
  94. if (lastIndex > -1) {
  95. object = (StructuredData)objects.get(lastIndex);
  96. objects.remove(lastIndex);
  97. }
  98. return object;
  99. }
  100. /**
  101. * Returns the current data length
  102. *
  103. * @return the current data length of this container including
  104. * all enclosed objects (and their containers)
  105. */
  106. public int getDataLength() {
  107. int dataLen = 0;
  108. Iterator it = objects.iterator();
  109. while (it.hasNext()) {
  110. dataLen += ((StructuredData)it.next()).getDataLength();
  111. }
  112. return dataLen;
  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. }