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 classHardcopyWriter.PrintCanceledException
-
Field Summary
Fields Modifier and Type Field Description protected intcharnumprotected intcharoffsetprotected intchars_per_lineprotected intcharwidthprotected javax.swing.JButtoncloseButtonprotected java.awt.Colorcolorprotected java.awt.Fontfontprotected java.lang.StringfontNameprotected intfontsizeprotected intfontStyleprotected java.awt.Frameframeprotected java.awt.Fontheaderfontprotected java.awt.FontMetricsheadermetricsprotected intheaderyprotected intheightprotected booleanisPreviewprotected java.awt.PrintJobjob(package private) java.awt.JobAttributesjobAttributesprotected java.lang.Stringjobnameprotected java.lang.Stringlineprotected intlineascentprotected intlineheightprotected intlinenumprotected intlines_per_pageprotected java.awt.FontMetricsmetricsprotected javax.swing.JButtonnextButtonprotected java.awt.Graphicspage(package private) java.awt.PageAttributespageAttributesprotected javax.swing.JLabelpageCountprotected intpagedpiprotected java.util.Vector<java.awt.Image>pageImagesprotected intpagenumprotected java.awt.Dimensionpagesizeprotected JmriJFramepreviewFrameprotected javax.swing.ImageIconpreviewIconprotected java.awt.ImagepreviewImageprotected javax.swing.JLabelpreviewLabelprotected javax.swing.JPanelpreviewPanelprotected javax.swing.JToolBarpreviewToolBarprotected javax.swing.JButtonpreviousButtonprotected intprFirstprotected booleanprintHeaderprotected java.lang.Stringtimeprotected intwidthprotected intx0protected inty0
-
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 isPreview)HardcopyWriter(java.awt.Frame frame, java.lang.String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean isPreview, java.lang.String printerName, boolean isLandscape, boolean isPrintHeader, java.awt.JobAttributes.SidesType sidesType, java.awt.Dimension pagesize)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Handle close event of pane.protected voiddisplayPage()Display a page image in the preview pane.voiddispose()Free up resources .voidflush()intgetCharactersPerLine()Return the number of columns of characters that fit on a page.intgetCharWidth()intgetCurrentLineNumber()Get the current linenumber.intgetFontSize()intgetLineAscent()intgetLineHeight()intgetLinesPerPage()Return 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 capabilityvoidpageBreak()End the current page.voidsetFontName(java.lang.String name)voidsetFontStyle(int style)voidsetTextColor(java.awt.Color c)sets the default text colorprotected voidtoolBarInit()Create 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(java.awt.Color c, java.lang.String s)Write a given String with the desired color.voidwrite(java.awt.Image c, java.awt.Component i)Write a graphic to the printout.voidwrite(javax.swing.JWindow jW)A Method to allow a JWindow to print itself at the current line positionvoidwriteBorders()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.voidwriteNoScale(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 isPreview) 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 isPreview, java.lang.String printerName, boolean isLandscape, boolean isPrintHeader, java.awt.JobAttributes.SidesType sidesType, 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:
writein 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:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer
-
close
public void close()
Handle close event of pane. Modified to clean up the added preview capability.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein 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
-
-