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

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