Methods Summary |
---|
public int | getCurrentPage() return mCurrentPage;
|
public int | getNumPages() return mPages.size();
|
public java.awt.Dimension | getPreferredSize() return mPreferredSize;
|
public void | nextPage()
if (mCurrentPage < mPages.size() - 1)
mCurrentPage++;
repaint();
|
public void | paginate(java.awt.print.PageFormat pageFormat)
mCurrentPage = 0;
mPages = new Vector();
float y = mFontSize;
Vector page = new Vector();
for (int i = 0; i < mLines.size(); i++) {
String line = (String)mLines.elementAt(i);
page.addElement(line);
y += mFontSize;
if (y + mFontSize * 2 > pageFormat.getImageableHeight()) {
y = 0;
mPages.addElement(page);
page = new Vector();
}
}
// Add the last page.
if (page.size() > 0) mPages.addElement(page);
// Set our preferred size based on the PageFormat.
mPreferredSize = new Dimension((int)pageFormat.getImageableWidth(),
(int)pageFormat.getImageableHeight());
repaint();
|
public void | paintComponent(java.awt.Graphics g)
Graphics2D g2 = (Graphics2D)g;
// Make the background white.
java.awt.geom.Rectangle2D r = new java.awt.geom.Rectangle2D.Float(0, 0,
mPreferredSize.width, mPreferredSize.height);
g2.setPaint(Color.white);
g2.fill(r);
// Get the current page.
Vector page = (Vector)mPages.elementAt(mCurrentPage);
// Draw all the lines for this page.
g2.setFont(mFont);
g2.setPaint(Color.black);
float x = 0;
float y = mFontSize;
for (int i = 0; i < page.size(); i++) {
String line = (String)page.elementAt(i);
if (line.length() > 0) g2.drawString(line, (int)x, (int)y);
y += mFontSize;
}
|
public void | previousPage()
if (mCurrentPage > 0)
mCurrentPage--;
repaint();
|
public int | print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
if (pageIndex >= mPages.size()) return NO_SUCH_PAGE;
int savedPage = mCurrentPage;
mCurrentPage = pageIndex;
Graphics2D g2 = (Graphics2D)g;
g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
paint(g2);
mCurrentPage = savedPage;
return PAGE_EXISTS;
|