Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Page.java 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.area;
  8. import java.io.Serializable;
  9. import java.util.HashMap;
  10. /**
  11. * The page.
  12. * This holds the contents of the page. Each region is added.
  13. * The unresolved references area added so that if the page is
  14. * serialized then it will handle the resolving properly after
  15. * being reloaded.
  16. * This is serializable so it can be saved to cache to save
  17. * memory if there are forward references.
  18. * The page is cloneable so the page master can make copies of
  19. * the top level page and regions.
  20. */
  21. public class Page implements Serializable, Cloneable {
  22. // contains before, start, body, end and after regions
  23. private RegionViewport regionBefore = null;
  24. private RegionViewport regionStart = null;
  25. private RegionViewport regionBody = null;
  26. private RegionViewport regionEnd = null;
  27. private RegionViewport regionAfter = null;
  28. // hashmap of markers for this page
  29. // start and end are added by the fo that contains the markers
  30. private HashMap markerStart = null;
  31. private HashMap markerEnd = null;
  32. // temporary map of unresolved objects used when serializing the page
  33. private HashMap unresolved = null;
  34. /**
  35. * Set the region on this page.
  36. *
  37. * @param areaclass the area class of the region to set
  38. * @param port the region viewport to set
  39. */
  40. public void setRegion(int areaclass, RegionViewport port) {
  41. if (areaclass == RegionReference.BEFORE) {
  42. regionBefore = port;
  43. } else if (areaclass == RegionReference.START) {
  44. regionStart = port;
  45. } else if (areaclass == RegionReference.BODY) {
  46. regionBody = port;
  47. } else if (areaclass == RegionReference.END) {
  48. regionEnd = port;
  49. } else if (areaclass == RegionReference.AFTER) {
  50. regionAfter = port;
  51. }
  52. }
  53. /**
  54. * Get the region from this page.
  55. *
  56. * @param areaclass the region area class
  57. * @return the region viewport or null if none
  58. */
  59. public RegionViewport getRegion(int areaclass) {
  60. if (areaclass == RegionReference.BEFORE) {
  61. return regionBefore;
  62. } else if (areaclass == RegionReference.START) {
  63. return regionStart;
  64. } else if (areaclass == RegionReference.BODY) {
  65. return regionBody;
  66. } else if (areaclass == RegionReference.END) {
  67. return regionEnd;
  68. } else if (areaclass == RegionReference.AFTER) {
  69. return regionAfter;
  70. }
  71. return null;
  72. }
  73. /**
  74. * Clone this page.
  75. * This returns a new page with a clone of all the regions.
  76. *
  77. * @return a new clone of this page
  78. */
  79. public Object clone() {
  80. Page p = new Page();
  81. if (regionBefore != null) {
  82. p.regionBefore = (RegionViewport)regionBefore.clone();
  83. }
  84. if (regionStart != null) {
  85. p.regionStart = (RegionViewport)regionStart.clone();
  86. }
  87. if (regionBody != null) {
  88. p.regionBody = (RegionViewport)regionBody.clone();
  89. }
  90. if (regionEnd != null) {
  91. p.regionEnd = (RegionViewport)regionEnd.clone();
  92. }
  93. if (regionAfter != null) {
  94. p.regionAfter = (RegionViewport)regionAfter.clone();
  95. }
  96. return p;
  97. }
  98. /**
  99. * Set the unresolved references on this page for serializing.
  100. *
  101. * @param unres the map of unresolved objects
  102. */
  103. public void setUnresolvedReferences(HashMap unres) {
  104. unresolved = unres;
  105. }
  106. /**
  107. * Get the map unresolved references from this page.
  108. * This should be called after deserializing to retrieve
  109. * the map of unresolved references that were serialized.
  110. *
  111. * @return the de-serialized map of unresolved objects
  112. */
  113. public HashMap getUnresolvedReferences() {
  114. return unresolved;
  115. }
  116. }