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.

Page.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.area;
  18. import java.io.Serializable;
  19. import java.util.Map;
  20. import org.apache.fop.fo.pagination.Region;
  21. /**
  22. * The page.
  23. * This holds the contents of the page. Each region is added.
  24. * The unresolved references area added so that if the page is
  25. * serialized then it will handle the resolving properly after
  26. * being reloaded.
  27. * This is serializable so it can be saved to cache to save
  28. * memory if there are forward references.
  29. * The page is cloneable so the page master can make copies of
  30. * the top level page and regions.
  31. */
  32. public class Page implements Serializable, Cloneable {
  33. // contains before, start, body, end and after regions
  34. private RegionViewport regionBefore = null;
  35. private RegionViewport regionStart = null;
  36. private RegionViewport regionBody = null;
  37. private RegionViewport regionEnd = null;
  38. private RegionViewport regionAfter = null;
  39. // temporary map of unresolved objects used when serializing the page
  40. private Map unresolved = null;
  41. /**
  42. * Set the region on this page.
  43. *
  44. * @param areaclass the area class of the region to set
  45. * @param port the region viewport to set
  46. */
  47. public void setRegionViewport(int areaclass, RegionViewport port) {
  48. if (areaclass == Region.BEFORE_CODE) {
  49. regionBefore = port;
  50. } else if (areaclass == Region.START_CODE) {
  51. regionStart = port;
  52. } else if (areaclass == Region.BODY_CODE) {
  53. regionBody = port;
  54. } else if (areaclass == Region.END_CODE) {
  55. regionEnd = port;
  56. } else if (areaclass == Region.AFTER_CODE) {
  57. regionAfter = port;
  58. }
  59. }
  60. /**
  61. * Get the region from this page.
  62. *
  63. * @param areaclass the region area class
  64. * @return the region viewport or null if none
  65. */
  66. public RegionViewport getRegionViewport(int areaclass) {
  67. if (areaclass == Region.BEFORE_CODE) {
  68. return regionBefore;
  69. } else if (areaclass == Region.START_CODE) {
  70. return regionStart;
  71. } else if (areaclass == Region.BODY_CODE) {
  72. return regionBody;
  73. } else if (areaclass == Region.END_CODE) {
  74. return regionEnd;
  75. } else if (areaclass == Region.AFTER_CODE) {
  76. return regionAfter;
  77. }
  78. return null;
  79. }
  80. /**
  81. * Clone this page.
  82. * This returns a new page with a clone of all the regions.
  83. *
  84. * @return a new clone of this page
  85. */
  86. public Object clone() {
  87. Page p = new Page();
  88. if (regionBefore != null) {
  89. p.regionBefore = (RegionViewport)regionBefore.clone();
  90. }
  91. if (regionStart != null) {
  92. p.regionStart = (RegionViewport)regionStart.clone();
  93. }
  94. if (regionBody != null) {
  95. p.regionBody = (RegionViewport)regionBody.clone();
  96. }
  97. if (regionEnd != null) {
  98. p.regionEnd = (RegionViewport)regionEnd.clone();
  99. }
  100. if (regionAfter != null) {
  101. p.regionAfter = (RegionViewport)regionAfter.clone();
  102. }
  103. return p;
  104. }
  105. /**
  106. * Set the unresolved references on this page for serializing.
  107. *
  108. * @param unres the map of unresolved objects
  109. */
  110. public void setUnresolvedReferences(Map unres) {
  111. unresolved = unres;
  112. }
  113. /**
  114. * Get the map unresolved references from this page.
  115. * This should be called after deserializing to retrieve
  116. * the map of unresolved references that were serialized.
  117. *
  118. * @return the de-serialized map of unresolved objects
  119. */
  120. public Map getUnresolvedReferences() {
  121. return unresolved;
  122. }
  123. }