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 floatprotected intprotected floatprotected 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 Dimensionprotected 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.floatintGet 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.Write the decoder pro icon to the output.writeDecoderProIcon(boolean no_advance) Write the decoder pro icon to the output.writeSpecificSize(Image c, Dimension requiredSize) Write a graphic to the printout at a specific size (in points)
-
Field Details
-
job
-
page
-
jobname
-
line
-
fontsize
-
time
-
pagesizePixels
-
pagesizePoints
-
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. Modified by P Gladstone. The image well be rendered at 1.5 pixels per point.
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
-
writeDecoderProIcon
Write the decoder pro icon to the output. Method added by P Gladstone. This actually uses the high resolution image. It also advances the linenum appropriately (unless no_advance is True)The image is positioned on the right side of the paper, at the current height.
- Parameters:
no_advance- if true, do not advance the linenum- Returns:
- The actual size in points of the icon that was rendered.
-
writeDecoderProIcon
Write the decoder pro icon to the output. Method added by P Gladstone. This actually uses the high resolution image. It also advances the linenum appropriately.The image is positioned on the right side of the paper, at the current height.
- Returns:
- The actual size in points of the icon that was rendered.
-
writeSpecificSize
Write a graphic to the printout at a specific size (in points)This was not in the original class, but was added afterwards by Kevin Dickerson. Heavily modified by P Gladstone.
The image is positioned on the right side of the paper, at the current height. The image aspect ratio is maintained.
- Parameters:
c- the image to printrequiredSize- the dimensions to scale the image to. The image will fit inside the bounding box.- Returns:
- the dimensions of the image in points
-
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
-