Class HardcopyWriter

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

public class HardcopyWriter extends 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.

  • Field Details

  • Constructor Details

  • Method Details

    • 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 class Writer
      Parameters:
      buffer - block of text characters
      index - position to start printing
      len - length (number of characters) of output
    • write

      public void write(Color c, String s) throws 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 String
      s - the String
      Throws:
      IOException - if unable to write to printer
    • flush

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

      public void close()
      Handle close event of pane. Modified to clean up the added preview capability.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class 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(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.
      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(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.

      Parameters:
      c - image to write
      i - ignored, but maintained for API compatibility
    • 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.

      Parameters:
      c - the image to print
      i - ignored but maintained for API compatibility
    • 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.

      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 position
      colStart - horizontal starting position
      rowEnd - vertical ending position
      colEnd - 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 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.

      Parameters:
      percent - percentage by which to increase line spacing