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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 java.util.Locale;
  22. import org.xml.sax.SAXException;
  23. import org.apache.commons.logging.Log;
  24. import org.apache.commons.logging.LogFactory;
  25. /**
  26. * This is the model for the area tree object.
  27. * The model implementation can handle the page sequence,
  28. * page and off-document items.
  29. * The methods to access the page viewports can only
  30. * assume the PageViewport is valid as it remains for
  31. * the life of the area tree model.
  32. */
  33. public class AreaTreeModel {
  34. private List<PageSequence> pageSequenceList;
  35. private int currentPageIndex;
  36. /** the current page sequence */
  37. protected PageSequence currentPageSequence;
  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. if (currentPageSequence != null) {
  55. currentPageIndex += currentPageSequence.getPageCount();
  56. }
  57. this.currentPageSequence = pageSequence;
  58. pageSequenceList.add(currentPageSequence);
  59. }
  60. /**
  61. * Add a page to this model.
  62. * @param page the page to add to the model.
  63. */
  64. public void addPage(PageViewport page) {
  65. currentPageSequence.addPage(page);
  66. page.setPageIndex(currentPageIndex
  67. + currentPageSequence.getPageCount() - 1);
  68. page.setPageSequence(currentPageSequence);
  69. }
  70. /**
  71. * Handle an OffDocumentItem
  72. * @param ext the extension to handle
  73. */
  74. public void handleOffDocumentItem(OffDocumentItem ext) { };
  75. /**
  76. * Signal the end of the document for any processing.
  77. * @throws SAXException if a problem was encountered.
  78. */
  79. public void endDocument() throws SAXException { };
  80. /**
  81. * Returns the currently active page-sequence.
  82. * @return the currently active page-sequence
  83. */
  84. public PageSequence getCurrentPageSequence() {
  85. return this.currentPageSequence;
  86. }
  87. /**
  88. * Get the page sequence count.
  89. * @return the number of page sequences in the document.
  90. */
  91. public int getPageSequenceCount() {
  92. return pageSequenceList.size();
  93. }
  94. /**
  95. * Get the page count.
  96. * @param seq the page sequence to count.
  97. * @return returns the number of pages in a page sequence
  98. */
  99. public int getPageCount(int seq) {
  100. return pageSequenceList.get(seq - 1).getPageCount();
  101. }
  102. /**
  103. * Get the page for a position in the document.
  104. * @param seq the page sequence number
  105. * @param count the page count in the sequence
  106. * @return the PageViewport for the particular page
  107. */
  108. public PageViewport getPage(int seq, int count) {
  109. return pageSequenceList.get(seq - 1).getPage(count);
  110. }
  111. /**
  112. *
  113. * @param locale The locale of the document
  114. */
  115. public void setDocumentLocale(Locale locale) {
  116. }
  117. }