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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /** Reference to the region FO. */
  29. //protected Region regionFO;
  30. private int regionClass;
  31. private String regionName;
  32. private CTM ctm;
  33. // the list of block areas from the static flow
  34. private ArrayList blocks = new ArrayList();
  35. /** the parent RegionViewport for this object */
  36. protected RegionViewport regionViewport;
  37. /**
  38. * Create a new region reference area.
  39. *
  40. * @param regionFO the region.
  41. * @param parent the viewport for this region.
  42. */
  43. public RegionReference(Region regionFO, RegionViewport parent) {
  44. this(regionFO.getNameId(), regionFO.getRegionName(), parent);
  45. }
  46. /**
  47. * Create a new region reference area.
  48. *
  49. * @param regionClass the region class (as returned by Region.getNameId())
  50. * @param regionName the name of the region (as returned by Region.getRegionName())
  51. * @param parent the viewport for this region.
  52. */
  53. public RegionReference(int regionClass, String regionName, RegionViewport parent) {
  54. this.regionClass = regionClass;
  55. this.regionName = regionName;
  56. addTrait(Trait.IS_REFERENCE_AREA, Boolean.TRUE);
  57. regionViewport = parent;
  58. }
  59. /** {@inheritDoc} */
  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 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. * Clone this region.
  119. * This is used when cloning the page by the page master.
  120. *
  121. * @return a copy of this region reference area
  122. */
  123. public Object clone() {
  124. RegionReference rr = new RegionReference(regionClass, regionName, regionViewport);
  125. rr.ctm = ctm;
  126. rr.setIPD(getIPD());
  127. rr.blocks = (ArrayList)blocks.clone();
  128. return rr;
  129. }
  130. /** {@inheritDoc} */
  131. public String toString() {
  132. StringBuffer sb = new StringBuffer(super.toString());
  133. sb.append(" {regionName=").append(regionName);
  134. sb.append(", regionClass=").append(regionClass);
  135. sb.append(", ctm=").append(ctm);
  136. sb.append("}");
  137. return sb.toString();
  138. }
  139. }