jmri.util.davidflanagan
Class HardcopyWriter

java.lang.Object
  extended by java.io.Writer
      extended by jmri.util.davidflanagan.HardcopyWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable

public class HardcopyWriter
extends Writer

This is from Chapter 12 of the O'Reilly Java book by David Flanagan with the alligator on the front.

Author:
David Flanagan

Nested Class Summary
static class HardcopyWriter.PrintCanceledException
           
 
Field Summary
protected  int charnum
           
protected  int charoffset
           
protected  int chars_per_line
           
protected  int charwidth
           
protected  JButton closeButton
           
protected  Color color
           
protected  Font font
           
protected  String fontName
           
protected  int fontsize
           
protected  int fontStyle
           
protected  Frame frame
           
protected  Font headerfont
           
protected  FontMetrics headermetrics
           
protected  int headery
           
protected  int height
           
protected  boolean isPreview
           
protected  PrintJob job
           
protected  String jobname
           
protected  String line
           
protected  int lineascent
           
protected  int lineheight
           
protected  int linenum
           
protected  int lines_per_page
           
protected  FontMetrics metrics
           
protected  JButton nextButton
           
protected  Graphics page
           
protected  JLabel pageCount
           
protected  int pagedpi
           
protected  Vector<Image> pageImages
           
protected  int pagenum
           
protected  Dimension pagesize
           
protected  Graphics previewedPage
           
protected  JmriJFrame previewFrame
           
protected  ImageIcon previewIcon
           
protected  Image previewImage
           
protected  Graphics previewImagegr
           
protected  JLabel previewLabel
           
protected  JPanel previewPanel
           
protected  JToolBar previewToolBar
           
protected  JButton previousButton
           
protected  String time
           
protected  JLabel totalPages
           
protected  int width
           
protected  int x0
           
protected  int y0
           
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview)
           
HardcopyWriter(Frame frame, String jobname, int fontsize, double leftmargin, double rightmargin, double topmargin, double bottommargin, boolean preview, String printerName)
           
 
Method Summary
 void close()
          method modified by Dennis Miller to add preview capability
protected  void displayPage()
          Method to display a page image in the preview pane Not in original class but added later by Dennis Miller
 void dispose()
          Dispose added so that a preview can be canceled
 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 percentage This method should be invoked immediately after a new HardcopyWriter is created.
protected  void newline()
          Internal method begins a new line method modified by Dennis Miller to add preview capability
protected  void newpage()
          Internal method beings a new page and prints the header method modified by Dennis Miller to add preview capability
 void pageBreak()
          End the current page.
 void setFontName(String name)
           
 void setFontStyle(int style)
           
 void setTextColor(Color c)
          sets the default text color
protected  void toolBarInit()
          Creates a print preview toolbar added by Dennis Miller
 void write(char[] buffer, int index, int len)
          write method, implemented by all Write subclasses
 void write(Color c, String s)
          Write the String with the desired color.
 void write(Image c, Component i)
          Write a graphic to the printout.
 void write(int rowStart, int colStart, int rowEnd, int colEnd)
          Draw a line on the printout.
 void write(JWindow jW)
          A Method to allow a JWindow to print itself at the current line position This was not in the original class, but was added afterwards by Dennis Miller.
 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.
 void writeNoScale(Image c, Component i)
          Write a graphic to the printout.
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

job

protected PrintJob job

page

protected Graphics page

jobname

protected String jobname

line

protected String line

fontsize

protected int fontsize

time

protected String time

pagesize

protected Dimension pagesize

pagedpi

protected int pagedpi

font

protected Font font

headerfont

protected Font headerfont

fontName

protected String fontName

fontStyle

protected int fontStyle

metrics

protected FontMetrics metrics

headermetrics

protected 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

color

protected Color color

isPreview

protected boolean isPreview

previewedPage

protected Graphics previewedPage

previewImage

protected Image previewImage

previewImagegr

protected Graphics previewImagegr

pageImages

protected Vector<Image> pageImages

previewFrame

protected JmriJFrame previewFrame

previewPanel

protected JPanel previewPanel

previewIcon

protected ImageIcon previewIcon

previewLabel

protected JLabel previewLabel

previewToolBar

protected JToolBar previewToolBar

frame

protected Frame frame

nextButton

protected JButton nextButton

previousButton

protected JButton previousButton

closeButton

protected JButton closeButton

pageCount

protected JLabel pageCount

totalPages

protected JLabel totalPages
Constructor Detail

HardcopyWriter

public HardcopyWriter(Frame frame,
                      String jobname,
                      int fontsize,
                      double leftmargin,
                      double rightmargin,
                      double topmargin,
                      double bottommargin,
                      boolean preview)
               throws HardcopyWriter.PrintCanceledException
Throws:
HardcopyWriter.PrintCanceledException

HardcopyWriter

public HardcopyWriter(Frame frame,
                      String jobname,
                      int fontsize,
                      double leftmargin,
                      double rightmargin,
                      double topmargin,
                      double bottommargin,
                      boolean preview,
                      String printerName)
               throws HardcopyWriter.PrintCanceledException
Throws:
HardcopyWriter.PrintCanceledException
Method Detail

toolBarInit

protected void toolBarInit()
Creates a print preview toolbar added by Dennis Miller


displayPage

protected void displayPage()
Method to display a page image in the preview pane Not in original class but added later by Dennis Miller


write

public void write(char[] buffer,
                  int index,
                  int len)
write method, implemented by all Write subclasses

Specified by:
write in class Writer

write

public void write(Color c,
                  String s)
           throws IOException
Write the String with the desired color. Returns the text color back to the default after the string is written.

Parameters:
c - the color desired for this String
s - the String
Throws:
IOException

flush

public void flush()
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer

close

public void close()
method modified by Dennis Miller to add preview capability

Specified by:
close in interface Closeable
Specified by:
close in class Writer

dispose

public void dispose()
Dispose 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(String name)

setTextColor

public void setTextColor(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


getLinesPerPage

public int getLinesPerPage()
Return the number of lines that fit on 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(Image c,
                  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.


writeNoScale

public void writeNoScale(Image c,
                         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.


write

public void write(JWindow jW)
A Method to allow a JWindow to print itself at the current line position

This 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.


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


getCurrentLineNumber

public int getCurrentLineNumber()
Get the current linenumber.

This was not in the original class, but was added afterwards by Dennis Miller.


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 height

This was not in the original class, but was added afterwards by Dennis Miller.


increaseLineSpacing

public void increaseLineSpacing(int percent)
Increase line spacing by a percentage

This 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.



Copyright © 1997 - 2011 JMRI Community.
JMRI, DecoderPro, PanelPro, SoundPro, DispatcherPro and associated logos are our trademarks.

Additional information on copyright, trademarks and licenses is linked here.
Site hosted by: Get JMRI Model Railroad Interface at SourceForge.net. Fast, secure and Free Open Source software downloads