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.

AreaTreeModel.java 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. // Java
  20. import java.util.List;
  21. import org.xml.sax.SAXException;
  22. import org.apache.commons.logging.Log;
  23. import org.apache.commons.logging.LogFactory;
  24. /**
  25. * This is the model for the area tree object.
  26. * The model implementation can handle the page sequence,
  27. * page and off-document items.
  28. * The methods to access the page viewports can only
  29. * assume the PageViewport is valid as it remains for
  30. * the life of the area tree model.
  31. */
  32. public class AreaTreeModel {
  33. private List/*<PageSequence>*/ pageSequenceList = null;
  34. private int currentPageSequenceIndex = -1;
  35. /** the current page sequence */
  36. protected PageSequence currentPageSequence;
  37. // private List offDocumentItems = new java.util.ArrayList();
  38. /** logger instance */
  39. protected static final Log log = LogFactory.getLog(AreaTreeModel.class);
  40. /**
  41. * Create a new store pages model
  42. */
  43. public AreaTreeModel() {
  44. pageSequenceList = new java.util.ArrayList/*<PageSequence>*/();
  45. }
  46. /**
  47. * Start a page sequence on this model.
  48. * @param pageSequence the page sequence about to start
  49. */
  50. public void startPageSequence(PageSequence pageSequence) {
  51. if (pageSequence == null) {
  52. throw new NullPointerException("pageSequence must not be null");
  53. }
  54. this.currentPageSequence = pageSequence;
  55. pageSequenceList.add(currentPageSequence);
  56. currentPageSequenceIndex = pageSequenceList.size() - 1;
  57. }
  58. /**
  59. * Add a page to this model.
  60. * @param page the page to add to the model.
  61. */
  62. public void addPage(PageViewport page) {
  63. currentPageSequence.addPage(page);
  64. int pageIndex = 0;
  65. for (int i = 0; i < currentPageSequenceIndex; i++) {
  66. pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount();
  67. }
  68. pageIndex += currentPageSequence.getPageCount() - 1;
  69. page.setPageIndex(pageIndex);
  70. page.setPageSequence(currentPageSequence);
  71. }
  72. /**
  73. * Handle an OffDocumentItem
  74. * @param ext the extension to handle
  75. */
  76. public void handleOffDocumentItem(OffDocumentItem ext) { };
  77. /**
  78. * Signal the end of the document for any processing.
  79. * @throws SAXException if a problem was encountered.
  80. */
  81. public void endDocument() throws SAXException { };
  82. /**
  83. * Returns the currently active page-sequence.
  84. * @return the currently active page-sequence
  85. */
  86. public PageSequence getCurrentPageSequence() {
  87. return this.currentPageSequence;
  88. }
  89. /**
  90. * Get the page sequence count.
  91. * @return the number of page sequences in the document.
  92. */
  93. public int getPageSequenceCount() {
  94. return pageSequenceList.size();
  95. }
  96. /**
  97. * Get the page count.
  98. * @param seq the page sequence to count.
  99. * @return returns the number of pages in a page sequence
  100. */
  101. public int getPageCount(int seq) {
  102. PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
  103. return sequence.getPageCount();
  104. }
  105. /**
  106. * Get the page for a position in the document.
  107. * @param seq the page sequence number
  108. * @param count the page count in the sequence
  109. * @return the PageViewport for the particular page
  110. */
  111. public PageViewport getPage(int seq, int count) {
  112. PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
  113. return sequence.getPage(count);
  114. }
  115. }