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 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. /** {@inheritDoc} */
  64. public int getBPD() {
  65. // subtract bpd of borders and padding before / after
  66. return super.getBPD() - getBorderAndPaddingWidthBefore() - getBorderAndPaddingWidthAfter();
  67. }
  68. /** {@inheritDoc} */
  69. public int getIPD() {
  70. // subtract ipd of borders and padding start / end
  71. return super.getIPD() - getBorderAndPaddingWidthStart() - getBorderAndPaddingWidthEnd();
  72. }
  73. /**
  74. * Set the Coordinate Transformation Matrix which transforms content
  75. * coordinates in this region reference area which are specified in
  76. * terms of "start" and "before" into coordinates in a system which
  77. * is positioned in "absolute" directions (with origin at lower left of
  78. * the region reference area.
  79. *
  80. * @param ctm the current transform to position this region
  81. */
  82. public void setCTM(CTM ctm) {
  83. this.ctm = ctm;
  84. }
  85. /**
  86. * @return Returns the parent RegionViewport.
  87. */
  88. public RegionViewport getRegionViewport() {
  89. return regionViewport;
  90. }
  91. /**
  92. * Get the current transform of this region.
  93. *
  94. * @return ctm the current transform to position this region
  95. */
  96. public CTM getCTM() {
  97. return this.ctm;
  98. }
  99. /**
  100. * Get the block in this region.
  101. *
  102. * @return the list of blocks in this region
  103. */
  104. public List getBlocks() {
  105. return blocks;
  106. }
  107. /**
  108. * Get the region class of this region.
  109. *
  110. * @return the region class
  111. */
  112. public int getRegionClass() {
  113. return this.regionClass;
  114. }
  115. /** @return the region name */
  116. public String getRegionName() {
  117. return this.regionName;
  118. }
  119. /**
  120. * Add a block area to this region reference area.
  121. *
  122. * @param block the block area to add
  123. */
  124. public void addBlock(Block block) {
  125. addChildArea(block);
  126. }
  127. /**
  128. * Clone this region.
  129. * This is used when cloning the page by the page master.
  130. *
  131. * @return a copy of this region reference area
  132. */
  133. public Object clone() {
  134. RegionReference rr = new RegionReference(regionClass, regionName, regionViewport);
  135. rr.ctm = ctm;
  136. rr.setIPD(getIPD());
  137. rr.blocks = (ArrayList)blocks.clone();
  138. return rr;
  139. }
  140. }