1 19 20 package com.sshtools.ui.swing; 21 22 import java.awt.Graphics ; 23 import java.awt.Rectangle ; 24 import javax.swing.text.BoxView ; 25 import javax.swing.text.Element ; 26 import javax.swing.text.View ; 27 28 public class PrintView extends BoxView { 29 protected int m_firstOnPage = 0; 30 protected int m_lastOnPage = 0; 31 protected int m_pageIndex = 0; 32 33 public PrintView(Element elem, View 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 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 rc = new Rectangle (); 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 |