Class HardcopyWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
This is from Chapter 12 of the O'Reilly Java book by David Flanagan with the alligator on the front.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected intprotected JButtonprotected Colorprotected Fontprotected Stringprotected intprotected intprotected Frameprotected Fontprotected FontMetricsprotected intprotected intprotected booleanprotected PrintJob(package private) JobAttributesprotected Stringprotected Stringprotected intprotected intprotected intprotected intprotected FontMetricsprotected JButtonprotected Graphics(package private) PageAttributesprotected JLabelprotected intprotected intprotected Dimensionprotected JmriJFrameprotected ImageIconprotected Imageprotected JLabelprotected JPanelprotected JToolBarprotected JButtonprotected intprotected booleanprotected Stringprotected intprotected intprotected int -
Constructor Summary
ConstructorsConstructorDescriptionHardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean isPreview) HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean isPreview, String printerName, boolean isLandscape, boolean isPrintHeader, JobAttributes.SidesType sidesType, Dimension pagesize) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Handle close event of pane.protected voidDisplay a page image in the preview pane.voiddispose()Free up resources .voidflush()intReturn the number of columns of characters that fit on a page.intintGet the current linenumber.intintintintReturn the number of lines that fit on a page.voidincreaseLineSpacing(int percent) Increase line spacing by a percentageprotected voidnewline()Internal method begins a new line method modified by Dennis Miller to add preview capabilityprotected voidnewpage()Internal method beings a new page and prints the header method modified by Dennis Miller to add preview capabilityvoidEnd the current page.voidsetFontName(String name) voidsetFontStyle(int style) voidsets the default text colorprotected voidCreate a print preview toolbar.voidwrite(char[] buffer, int index, int len) Send text to Writer output.voidwrite(int rowStart, int colStart, int rowEnd, int colEnd) Draw a line on the printout.voidWrite a given String with the desired color.voidWrite a graphic to the printout.voidA Method to allow a JWindow to print itself at the current line positionvoidPrint vertical borders on the current line at the left and right sides of the page at character positions 0 and chars_per_line + 1.voidwriteNoScale(Image c, Component i) Write a graphic to the printout.
-
Field Details
-
job
-
page
-
jobname
-
line
-
fontsize
-
time
-
pagesize
-
pagedpi
-
font
-
headerfont
-
fontName
-
fontStyle
-
metrics
-
headermetrics
-
x0
-
y0
-
height
-
width
-
headery
-
charwidth
-
lineheight
-
lineascent
-
chars_per_line
-
lines_per_page
-
charnum
-
linenum
-
charoffset
-
pagenum
-
prFirst
-
color
-
printHeader
-
isPreview
-
previewImage
-
pageImages
-
previewFrame
-
previewPanel
-
previewIcon
-
previewLabel
-
previewToolBar
-
frame
-
nextButton
-
previousButton
-
closeButton
-
pageCount
-
jobAttributes
-
pageAttributes
-
-
Constructor Details
-
HardcopyWriter
public HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean isPreview) throws HardcopyWriter.PrintCanceledException -
HardcopyWriter
public HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean isPreview, String printerName, boolean isLandscape, boolean isPrintHeader, JobAttributes.SidesType sidesType, Dimension pagesize) throws HardcopyWriter.PrintCanceledException
-
-
Method Details
-
toolBarInit
Create a print preview toolbar. -
displayPage
Display a page image in the preview pane.Not part of the original HardcopyWriter class.
-
write
Send text to Writer output. -
write
Write a given String with the desired color.Reset the text color back to the default after the string is written.
- Parameters:
c- the color desired for this Strings- the String- Throws:
IOException- if unable to write to printer
-
flush
-
close
Handle close event of pane. Modified to clean up the added preview capability. -
dispose
Free up resources .Added so that a preview can be canceled.
-
setFontStyle
-
getLineHeight
-
getFontSize
-
getCharWidth
-
getLineAscent
-
setFontName
-
setTextColor
sets the default text color- Parameters:
c- the new default text color
-
pageBreak
End the current page. Subsequent output will be on a new page -
getCharactersPerLine
Return the number of columns of characters that fit on a page.- Returns:
- the number of characters in a line
-
getLinesPerPage
Return the number of lines that fit on a page.- Returns:
- the number of lines in a page
-
newline
Internal method begins a new line method modified by Dennis Miller to add preview capability -
newpage
Internal method beings a new page and prints the header method modified by Dennis Miller to add preview capability -
write
Write a graphic to the printout.This was not in the original class, but was added afterwards by Bob Jacobsen. Modified by D Miller.
The image is positioned on the right side of the paper, at the current height.
- Parameters:
c- image to writei- ignored, but maintained for API compatibility
-
writeNoScale
Write a graphic to the printout.This was not in the original class, but was added afterwards by Kevin Dickerson. it is a copy of the write, but without the scaling.
The image is positioned on the right side of the paper, at the current height.
- Parameters:
c- the image to printi- ignored but maintained for API compatibility
-
write
A Method to allow a JWindow to print itself at the current line positionThis was not in the original class, but was added afterwards by Dennis Miller.
Intended to allow for a graphic printout of the speed table, but can be used to print any window. The JWindow is passed to the method and prints itself at the current line and aligned at the left margin. The calling method should check for sufficient space left on the page and move it to the top of the next page if there isn't enough space.
- Parameters:
jW- the window to print
-
write
Draw a line on the printout.This was not in the original class, but was added afterwards by Dennis Miller.
colStart and colEnd represent the horizontal character positions. The lines actually start in the middle of the character position to make it easy to draw vertical lines and space them between printed characters.
rowStart and rowEnd represent the vertical character positions. Horizontal lines are drawn underneath the row (line) number. They are offset so they appear evenly spaced, although they don't take into account any space needed for descenders, so they look best with all caps text
- Parameters:
rowStart- vertical starting positioncolStart- horizontal starting positionrowEnd- vertical ending positioncolEnd- horizontal ending position
-
getCurrentLineNumber
Get the current linenumber.This was not in the original class, but was added afterwards by Dennis Miller.
- Returns:
- the line number within the page
-
writeBorders
Print vertical borders on the current line at the left and right sides of the page at character positions 0 and chars_per_line + 1. Border lines are one text line in heightThis was not in the original class, but was added afterwards by Dennis Miller.
-
increaseLineSpacing
Increase line spacing by a percentageThis method should be invoked immediately after a new HardcopyWriter is created.
This method was added to improve appearance when printing tables
This was not in the original class, added afterwards by DaveDuchamp.
- Parameters:
percent- percentage by which to increase line spacing
-