|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.lang.Thread
util.StringPrinter
public class StringPrinter
Implements a simple printing class for a text string in a Thread. Based on a JavaWorld article by Michael Shoffner. Rather inefficient, since it repaginates far more often than it needs to, but would be appropriate for the kind of toy compiler I am writing.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.lang.Thread |
---|
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler |
Field Summary |
---|
Fields inherited from class java.lang.Thread |
---|
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Fields inherited from interface java.awt.print.Pageable |
---|
UNKNOWN_NUMBER_OF_PAGES |
Fields inherited from interface java.awt.print.Printable |
---|
NO_SUCH_PAGE, PAGE_EXISTS |
Constructor Summary | |
---|---|
StringPrinter(java.lang.String text)
Creates a new instance of StringPrinter with default Font and PageFormat |
|
StringPrinter(java.lang.String text,
java.awt.Font font)
Creates a new instance of StringPrinter with default PageFormat |
|
StringPrinter(java.lang.String text,
java.awt.Font font,
java.awt.print.PageFormat format)
Creates a new instance of StringPrinter. |
|
StringPrinter(java.lang.String text,
java.awt.print.PageFormat format)
Creates a new instance of StringPrinter with default Font |
Method Summary | |
---|---|
int |
getNumberOfPages()
calculates the total number of printable pages |
java.awt.print.PageFormat |
getPageFormat(int pageIndex)
returns the PageFormat for a given page |
java.awt.print.Printable |
getPrintable(int pageIndex)
returns the Printable for a given page |
java.lang.String |
getTitle()
returns the title string |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat format,
int pageIndex)
renders a page |
void |
run()
prints the string |
void |
setTitle(java.lang.String title)
sets the title string |
static java.lang.StringBuffer |
untabify(java.lang.String s,
int tabSize,
boolean truncate)
changes tabs to spaces. |
Methods inherited from class java.lang.Thread |
---|
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public StringPrinter(java.lang.String text)
public StringPrinter(java.lang.String text, java.awt.Font font)
public StringPrinter(java.lang.String text, java.awt.print.PageFormat format)
public StringPrinter(java.lang.String text, java.awt.Font font, java.awt.print.PageFormat format)
text
- the text to printfont
- the font; uses monospaced 12-point if nullformat
- the PageFormat to use; uses PrinterJob.getPrinterJob().defaultPage()
if nullMethod Detail |
---|
public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public void setTitle(java.lang.String title)
title
- the String to use for the header, along with the page numberpublic java.lang.String getTitle()
public int getNumberOfPages()
getNumberOfPages
in interface java.awt.print.Pageable
public java.awt.print.PageFormat getPageFormat(int pageIndex) throws java.lang.IndexOutOfBoundsException
getPageFormat
in interface java.awt.print.Pageable
pageIndex
- the page to format
java.lang.IndexOutOfBoundsException
- if pageIndex is not a valid pagepublic java.awt.print.Printable getPrintable(int pageIndex) throws java.lang.IndexOutOfBoundsException
getPrintable
in interface java.awt.print.Pageable
pageIndex
- the page that will be printed
java.lang.IndexOutOfBoundsException
- if pageIndex is not a valid pagepublic int print(java.awt.Graphics g, java.awt.print.PageFormat format, int pageIndex) throws java.awt.print.PrinterException
print
in interface java.awt.print.Printable
g
- the Graphics to render onformat
- the PageFormat to use for renderingpageIndex
- the page to print
java.lang.IndexOutOfBoundsException
- if pageIndex is not a valid page
java.awt.print.PrinterException
public static java.lang.StringBuffer untabify(java.lang.String s, int tabSize, boolean truncate)
s
- the string to detabify. Splits lines on '\n' only,
not '\r'.tabSize
- the number of spaces to use for each tabtruncate
- true if each tab field should be truncated
to fit in tabSize-1 columns (the -1 ensures a space between
tabs; false to keep the text intact and move to the next
available tab stop. Strings get truncated from the end; numbers
are rounded with Num2Str
if possible, and replaced
with '*'s (a la FORTRAN) if not.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |