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.

RegionReference.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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.area;
  19. import java.util.ArrayList;
  20. import java.util.List;
  21. import org.apache.fop.fo.pagination.Region;
  22. /**
  23. * This is a region reference area for a page regions.
  24. * This area is the direct child of a region-viewport-area. It is cloneable
  25. * so the page master can make copies from the original page and regions.
  26. */
  27. public class RegionReference extends Area {
  28. private static final long serialVersionUID = -298980963268244238L;
  29. private int regionClass;
  30. private String regionName;
  31. private CTM ctm;
  32. // the list of block areas from the static flow
  33. private ArrayList<Area> blocks = new ArrayList<Area>();
  34. /** the parent {@link RegionViewport} for this object */
  35. protected RegionViewport regionViewport;
  36. /**
  37. * Create a new region reference area.
  38. *
  39. * @param regionFO the region.
  40. * @param parent the viewport for this region.
  41. */
  42. public RegionReference(Region regionFO, RegionViewport parent) {
  43. this(regionFO.getNameId(), regionFO.getRegionName(), parent);
  44. }
  45. /**
  46. * Create a new region reference area.
  47. *
  48. * @param regionClass the region class (as returned by Region.getNameId())
  49. * @param regionName the name of the region (as returned by Region.getRegionName())
  50. * @param parent the viewport for this region.
  51. */
  52. public RegionReference(int regionClass, String regionName, RegionViewport parent) {
  53. this.regionClass = regionClass;
  54. this.regionName = regionName;
  55. addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  56. regionViewport = parent;
  57. }
  58. /** {@inheritDoc} */
  59. @Override
  60. public void addChildArea(Area child) {
  61. blocks.add(child);
  62. }
  63. /**
  64. * Set the Coordinate Transformation Matrix which transforms content
  65. * coordinates in this region reference area which are specified in
  66. * terms of "start" and "before" into coordinates in a system which
  67. * is positioned in "absolute" directions (with origin at lower left of
  68. * the region reference area.
  69. *
  70. * @param ctm the current transform to position this region
  71. */
  72. public void setCTM(CTM ctm) {
  73. this.ctm = ctm;
  74. }
  75. /**
  76. * @return Returns the parent RegionViewport.
  77. */
  78. public RegionViewport getRegionViewport() {
  79. return regionViewport;
  80. }
  81. /**
  82. * Get the current transform of this region.
  83. *
  84. * @return ctm the current transform to position this region
  85. */
  86. public CTM getCTM() {
  87. return this.ctm;
  88. }
  89. /**
  90. * Get the block in this region.
  91. *
  92. * @return the list of blocks in this region
  93. */
  94. public List<Area> getBlocks() {
  95. return blocks;
  96. }
  97. /**
  98. * Get the region class of this region.
  99. *
  100. * @return the region class
  101. */
  102. public int getRegionClass() {
  103. return this.regionClass;
  104. }
  105. /** @return the region name */
  106. public String getRegionName() {
  107. return this.regionName;
  108. }
  109. /**
  110. * Add a block area to this region reference area.
  111. *
  112. * @param block the block area to add
  113. */
  114. public void addBlock(Block block) {
  115. addChildArea(block);
  116. }
  117. /**
  118. * indicates whether the main reference area has any child areas added to it
  119. *
  120. * @return whether the main reference area has any child areas added to it
  121. */
  122. public boolean isEmpty() {
  123. return true;
  124. }
  125. /** {@inheritDoc} */
  126. public Object clone() throws CloneNotSupportedException {
  127. RegionReference rr = (RegionReference) super.clone();
  128. rr.blocks = (ArrayList) blocks.clone();
  129. return rr;
  130. }
  131. /** {@inheritDoc} */
  132. @Override
  133. public String toString() {
  134. StringBuffer sb = new StringBuffer(super.toString());
  135. sb.append(" {regionName=").append(regionName);
  136. sb.append(", regionClass=").append(regionClass);
  137. sb.append(", ctm=").append(ctm);
  138. sb.append("}");
  139. return sb.toString();
  140. }
  141. }