KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > area > AreaTreeModel


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
18 /* $Id: AreaTreeModel.java 433679 2006-08-22 15:49:26Z cbowditch $ */
19  
20 package org.apache.fop.area;
21
22 // Java
23
import java.util.List JavaDoc;
24
25 // XML
26
import org.xml.sax.SAXException JavaDoc;
27
28 // Apache
29
import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31
32 /**
33  * This is the model for the area tree object.
34  * The model implementation can handle the page sequence,
35  * page and off-document items.
36  * The methods to access the page viewports can only
37  * assume the PageViewport is valid as it remains for
38  * the life of the area tree model.
39  */

40 public class AreaTreeModel {
41     private List JavaDoc pageSequenceList = null;
42     private int currentPageSequenceIndex = -1;
43     /** the current page sequence */
44     protected PageSequence currentPageSequence;
45     private List JavaDoc offDocumentItems = new java.util.ArrayList JavaDoc();
46     /** logger instance */
47     protected static Log log = LogFactory.getLog(AreaTreeModel.class);
48
49     /**
50      * Create a new store pages model
51      */

52     public AreaTreeModel() {
53         pageSequenceList = new java.util.ArrayList JavaDoc();
54     }
55
56     /**
57      * Start a page sequence on this model.
58      * @param title the title of the new page sequence
59      */

60     public void startPageSequence(LineArea title) {
61         currentPageSequence = new PageSequence(title);
62         pageSequenceList.add(currentPageSequence);
63         currentPageSequenceIndex = pageSequenceList.size() - 1;
64     }
65
66     /**
67      * Add a page to this model.
68      * @param page the page to add to the model.
69      */

70     public void addPage(PageViewport page) {
71         currentPageSequence.addPage(page);
72         int pageIndex = 0;
73         for (int i = 0; i < currentPageSequenceIndex; i++) {
74             pageIndex += ((PageSequence)pageSequenceList.get(i)).getPageCount();
75         }
76         pageIndex += currentPageSequence.getPageCount() - 1;
77         page.setPageIndex(pageIndex);
78         page.setPageSequence(currentPageSequence);
79     }
80
81     /**
82      * Handle an OffDocumentItem
83      * @param ext the extension to handle
84      */

85     public void handleOffDocumentItem(OffDocumentItem ext) {};
86
87     /**
88      * Signal the end of the document for any processing.
89      * @throws SAXException if a problem was encountered.
90      */

91     public void endDocument() throws SAXException JavaDoc {};
92
93     /**
94      * Get the page sequence count.
95      * @return the number of page sequences in the document.
96      */

97     public int getPageSequenceCount() {
98         return pageSequenceList.size();
99     }
100
101     /**
102      * Get the page count.
103      * @param seq the page sequence to count.
104      * @return returns the number of pages in a page sequence
105      */

106     public int getPageCount(int seq) {
107         PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
108         return sequence.getPageCount();
109     }
110
111     /**
112      * Get the page for a position in the document.
113      * @param seq the page sequence number
114      * @param count the page count in the sequence
115      * @return the PageViewport for the particular page
116      */

117     public PageViewport getPage(int seq, int count) {
118         PageSequence sequence = (PageSequence)pageSequenceList.get(seq - 1);
119         return sequence.getPage(count);
120     }
121 }
122
Popular Tags