KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > PrintView


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sshtools.ui.swing;
21
22 import java.awt.Graphics JavaDoc;
23 import java.awt.Rectangle JavaDoc;
24 import javax.swing.text.BoxView JavaDoc;
25 import javax.swing.text.Element JavaDoc;
26 import javax.swing.text.View JavaDoc;
27
28 public class PrintView extends BoxView JavaDoc {
29     protected int m_firstOnPage = 0;
30     protected int m_lastOnPage = 0;
31     protected int m_pageIndex = 0;
32
33     public PrintView(Element JavaDoc elem, View JavaDoc root, int w, int h) {
34         super(elem, Y_AXIS);
35         setParent(root);
36         setSize(w, h);
37         layout(w, h);
38     }
39
40     public boolean paintPage(Graphics JavaDoc g, int hPage, int pageIndex) {
41         if (pageIndex > m_pageIndex) {
42             m_firstOnPage = m_lastOnPage + 1;
43             if (m_firstOnPage >= getViewCount()) {
44                 return false;
45             }
46             m_pageIndex = pageIndex;
47         }
48         int yMin = getOffset(Y_AXIS, m_firstOnPage);
49         int yMax = yMin + hPage;
50         Rectangle JavaDoc rc = new Rectangle JavaDoc();
51         for (int k = m_firstOnPage; k < getViewCount(); k++) {
52             rc.x = getOffset(X_AXIS, k);
53             rc.y = getOffset(Y_AXIS, k);
54             rc.width = getSpan(X_AXIS, k);
55             rc.height = getSpan(Y_AXIS, k);
56             if ((rc.y + rc.height) > yMax) {
57                 break;
58             }
59             m_lastOnPage = k;
60             rc.y -= yMin;
61             paintChild(g, rc, k);
62         }
63         return true;
64     }
65 }
Popular Tags