Package mars.util
Class HardcopyWriter
java.lang.Object
java.io.Writer
mars.util.HardcopyWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
HardcopyWriter
class from the book "Java Examples in a Nutshell,
3rd Edition" by David Flanagan. Publisher is O'Reilly, ISBN is
0-596-00620-9. Published Jan 2004. Web page for the book is
here.
A character output stream that sends output to a printer. I made only a couple minor changes. -- Pete Sanderson
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This is the exception class that the HardcopyWriter constructor throws when the user clicks "Cancel" in the print dialog box. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected FontMetrics
protected int
protected int
protected int
protected int
protected Font
protected int
protected Font
protected FontMetrics
protected int
protected int
protected PrintJob
protected String
protected int
protected int
protected int
protected int
protected int
protected Graphics
protected int
protected int
protected Dimension
protected static final Object
protected String
protected int
protected int
-
Constructor Summary
ConstructorsConstructorDescriptionHardcopyWriter
(Frame frame, String jobName, int fontSize, double leftMargin, double rightMargin, double topMargin, double bottomMargin) Construct a new HardcopyWriter. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
This internal method begins a new lineprotected void
This internal method begins a new page and prints the header.void
close()
This is the close( ) method that all Writer subclasses must implement.void
flush()
This is the flush( ) method that all Writer subclasses must implement.int
Return the number of columns of characters that fit on the pageint
Return the number of lines that fit on a pagevoid
End the current page.void
setFontStyle
(int style) Set the font style.void
write
(char[] buffer, int index, int len) This is the write() method of the stream.
-
Field Details
-
job
-
page
-
jobName
-
fontSize
protected int fontSize -
time
-
pageSize
-
pageResolutionDPI
protected int pageResolutionDPI -
font
-
headerFont
-
bodyMetrics
-
headerMetrics
-
leftX
protected int leftX -
topY
protected int topY -
width
protected int width -
height
protected int height -
headerY
protected int headerY -
charWidth
protected int charWidth -
lineHeight
protected int lineHeight -
lineAscent
protected int lineAscent -
charsPerLine
protected int charsPerLine -
linesPerPage
protected int linesPerPage -
charsPerTab
protected int charsPerTab -
charNum
protected int charNum -
lineNum
protected int lineNum -
pageNum
protected int pageNum -
PRINT_DIALOG_LOCK
-
-
Constructor Details
-
HardcopyWriter
public HardcopyWriter(Frame frame, String jobName, int fontSize, double leftMargin, double rightMargin, double topMargin, double bottomMargin) throws HardcopyWriter.PrintCanceledException Construct a new HardcopyWriter.- Parameters:
frame
- The parent frame, required for all printing in Java.jobName
- The name of the print job, which appears left justified at the top of each printed page.fontSize
- The font size in points.leftMargin
- The left margin in inches (or fractions of inches).rightMargin
- The right margin in inches (or fractions of inches).topMargin
- The top margin in inches (or fractions of inches).bottomMargin
- The bottom margin in inches (or fractions of inches).- Throws:
HardcopyWriter.PrintCanceledException
-
-
Method Details
-
write
public void write(char[] buffer, int index, int len) This is the write() method of the stream. All Writer subclasses implement this. All other versions of write() are variants of this one -
flush
public void flush()This is the flush( ) method that all Writer subclasses must implement. There is no way to flush a PrintJob without prematurely printing the page, so we don't do anything. -
close
public void close()This is the close( ) method that all Writer subclasses must implement. Print the pending page (if any) and terminate the PrintJob. -
setFontStyle
public void setFontStyle(int style) Set the font style. The argument should be one of the font style constants defined by the java.awt.Font class. All subsequent output will be in that style. This method relies on all styles of the Monospaced font having the same metrics. -
pageBreak
public void pageBreak()End the current page. Subsequent output will be on a new page. -
getCharactersPerLine
public int getCharactersPerLine()Return the number of columns of characters that fit on the page -
getLinesPerPage
public int getLinesPerPage()Return the number of lines that fit on a page -
beginNewLine
protected void beginNewLine()This internal method begins a new line -
beginNewPage
protected void beginNewPage()This internal method begins a new page and prints the header.
-