Class HardcopyWriter
- java.lang.Object
-
- java.io.Writer
-
- jmri.util.davidflanagan.HardcopyWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class HardcopyWriter extends java.io.Writer
Provide graphic output to a screen/printer.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 Modifier and Type Class Description static class
HardcopyWriter.PrintCanceledException
-
Field Summary
Fields Modifier and Type Field Description protected int
charnum
protected int
charoffset
protected int
chars_per_line
protected int
charwidth
protected javax.swing.JButton
closeButton
protected java.awt.Color
color
protected java.awt.Font
font
protected java.lang.String
fontName
protected int
fontsize
protected int
fontStyle
protected java.awt.Frame
frame
protected java.awt.Font
headerfont
protected java.awt.FontMetrics
headermetrics
protected int
headery
protected int
height
protected boolean
isPreview
protected java.awt.PrintJob
job
(package private) java.awt.JobAttributes
jobAttributes
protected java.lang.String
jobname
protected java.lang.String
line
protected int
lineascent
protected int
lineheight
protected int
linenum
protected int
lines_per_page
protected java.awt.FontMetrics
metrics
protected javax.swing.JButton
nextButton
protected java.awt.Graphics
page
(package private) java.awt.PageAttributes
pageAttributes
protected javax.swing.JLabel
pageCount
protected int
pagedpi
protected java.util.Vector<java.awt.Image>
pageImages
protected int
pagenum
protected java.awt.Dimension
pagesize
protected JmriJFrame
previewFrame
protected javax.swing.ImageIcon
previewIcon
protected java.awt.Image
previewImage
protected javax.swing.JLabel
previewLabel
protected javax.swing.JPanel
previewPanel
protected javax.swing.JToolBar
previewToolBar
protected javax.swing.JButton
previousButton
protected int
prFirst
protected boolean
printHeader
protected java.lang.String
time
protected int
width
protected int
x0
protected int
y0
-
Constructor Summary
Constructors Constructor Description HardcopyWriter(java.awt.Frame frame, java.lang.String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview)
HardcopyWriter(java.awt.Frame frame, java.lang.String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview, java.lang.String printerName, boolean landscape, boolean printHeader, java.awt.Dimension pagesize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Handle close event of pane.protected void
displayPage()
Display a page image in the preview pane.void
dispose()
Free up resources .void
flush()
int
getCharactersPerLine()
Return the number of columns of characters that fit on a page.int
getCharWidth()
int
getCurrentLineNumber()
Get the current linenumber.int
getFontSize()
int
getLineAscent()
int
getLineHeight()
int
getLinesPerPage()
Return the number of lines that fit on a page.void
increaseLineSpacing(int percent)
Increase line spacing by a percentageprotected void
newline()
Internal method begins a new line method modified by Dennis Miller to add preview capabilityprotected void
newpage()
Internal method beings a new page and prints the header method modified by Dennis Miller to add preview capabilityvoid
pageBreak()
End the current page.void
setFontName(java.lang.String name)
void
setFontStyle(int style)
void
setTextColor(java.awt.Color c)
sets the default text colorprotected void
toolBarInit()
Create a print preview toolbar.void
write(char[] buffer, int index, int len)
Send text to Writer output.void
write(int rowStart, int colStart, int rowEnd, int colEnd)
Draw a line on the printout.void
write(java.awt.Color c, java.lang.String s)
Write a given String with the desired color.void
write(java.awt.Image c, java.awt.Component i)
Write a graphic to the printout.void
write(javax.swing.JWindow jW)
A Method to allow a JWindow to print itself at the current line positionvoid
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.void
writeNoScale(java.awt.Image c, java.awt.Component i)
Write a graphic to the printout.
-
-
-
Field Detail
-
job
protected java.awt.PrintJob job
-
page
protected java.awt.Graphics page
-
jobname
protected java.lang.String jobname
-
line
protected java.lang.String line
-
fontsize
protected int fontsize
-
time
protected java.lang.String time
-
pagesize
protected java.awt.Dimension pagesize
-
pagedpi
protected int pagedpi
-
font
protected java.awt.Font font
-
headerfont
protected java.awt.Font headerfont
-
fontName
protected java.lang.String fontName
-
fontStyle
protected int fontStyle
-
metrics
protected java.awt.FontMetrics metrics
-
headermetrics
protected java.awt.FontMetrics headermetrics
-
x0
protected int x0
-
y0
protected int y0
-
height
protected int height
-
width
protected int width
-
headery
protected int headery
-
charwidth
protected int charwidth
-
lineheight
protected int lineheight
-
lineascent
protected int lineascent
-
chars_per_line
protected int chars_per_line
-
lines_per_page
protected int lines_per_page
-
charnum
protected int charnum
-
linenum
protected int linenum
-
charoffset
protected int charoffset
-
pagenum
protected int pagenum
-
prFirst
protected int prFirst
-
color
protected java.awt.Color color
-
printHeader
protected boolean printHeader
-
isPreview
protected boolean isPreview
-
previewImage
protected java.awt.Image previewImage
-
pageImages
protected java.util.Vector<java.awt.Image> pageImages
-
previewFrame
protected JmriJFrame previewFrame
-
previewPanel
protected javax.swing.JPanel previewPanel
-
previewIcon
protected javax.swing.ImageIcon previewIcon
-
previewLabel
protected javax.swing.JLabel previewLabel
-
previewToolBar
protected javax.swing.JToolBar previewToolBar
-
frame
protected java.awt.Frame frame
-
nextButton
protected javax.swing.JButton nextButton
-
previousButton
protected javax.swing.JButton previousButton
-
closeButton
protected javax.swing.JButton closeButton
-
pageCount
protected javax.swing.JLabel pageCount
-
jobAttributes
java.awt.JobAttributes jobAttributes
-
pageAttributes
java.awt.PageAttributes pageAttributes
-
-
Constructor Detail
-
HardcopyWriter
public HardcopyWriter(java.awt.Frame frame, java.lang.String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview) throws HardcopyWriter.PrintCanceledException
-
HardcopyWriter
public HardcopyWriter(java.awt.Frame frame, java.lang.String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview, java.lang.String printerName, boolean landscape, boolean printHeader, java.awt.Dimension pagesize) throws HardcopyWriter.PrintCanceledException
-
-
Method Detail
-
toolBarInit
protected void toolBarInit()
Create a print preview toolbar.
-
displayPage
protected void displayPage()
Display a page image in the preview pane.Not part of the original HardcopyWriter class.
-
write
public void write(char[] buffer, int index, int len)
Send text to Writer output.- Specified by:
write
in classjava.io.Writer
- Parameters:
buffer
- block of text charactersindex
- position to start printinglen
- length (number of characters) of output
-
write
public void write(java.awt.Color c, java.lang.String s) throws java.io.IOException
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:
java.io.IOException
- if unable to write to printer
-
flush
public void flush()
- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
-
close
public void close()
Handle close event of pane. Modified to clean up the added preview capability.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
-
dispose
public void dispose()
Free up resources .Added so that a preview can be canceled.
-
setFontStyle
public void setFontStyle(int style)
-
getLineHeight
public int getLineHeight()
-
getFontSize
public int getFontSize()
-
getCharWidth
public int getCharWidth()
-
getLineAscent
public int getLineAscent()
-
setFontName
public void setFontName(java.lang.String name)
-
setTextColor
public void setTextColor(java.awt.Color c)
sets the default text color- Parameters:
c
- the new default text color
-
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 a page.- Returns:
- the number of characters in a line
-
getLinesPerPage
public int getLinesPerPage()
Return the number of lines that fit on a page.- Returns:
- the number of lines in a page
-
newline
protected void newline()
Internal method begins a new line method modified by Dennis Miller to add preview capability
-
newpage
protected void newpage()
Internal method beings a new page and prints the header method modified by Dennis Miller to add preview capability
-
write
public void write(java.awt.Image c, java.awt.Component i)
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
public void writeNoScale(java.awt.Image c, java.awt.Component i)
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
public void write(javax.swing.JWindow jW)
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
public void write(int rowStart, int colStart, int rowEnd, int colEnd)
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
public int 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
public void 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
public void increaseLineSpacing(int percent)
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
-
-