Module Simula

Class RTS_PageWriter

java.lang.Object
java.io.Writer
simula.runtime.RTS_PageWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class RTS_PageWriter extends Writer
Utility class PageWriter.

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • inch

      private static final double inch
      1 inch == 0.02540 meter
      See Also:
    • printerDPI

      private static final int printerDPI
      Dots Per Inch = 72
      See Also:
    • pixelsPerMeter

      private static final double pixelsPerMeter
      Pixels per meter.
      See Also:
    • pixelsPerMilli

      private static final double pixelsPerMilli
      Pixels per millimeter.
      See Also:
    • fileName

      private String fileName
      The file name.
    • printerJob

      private PrinterJob printerJob
      The associated printerJob.
    • book

      private Book book
      The associated Book
    • currentSheet

      private RTS_PageWriter.Sheet currentSheet
      The current sheet
    • pageFormat

      private PageFormat pageFormat
      The page format
    • lineGap

      private float lineGap
      The line gap
    • linesPerSheet

      private int linesPerSheet
      Number of lines per page.
    • font

      private Font font
      The current Font
    • orientation

      private int orientation
      The current paper sheet orientation.
    • ask

      private boolean ask
      If true: ask user to set font and paper orientation through a popup dialogue.
    • left

      private double left
      The left margin.
    • top

      private double top
      The top margin.
    • bot

      private double bot
      The bottom margin.
    • currentLine

      private StringBuilder currentLine
      The current line
  • Constructor Details

    • RTS_PageWriter

      public RTS_PageWriter(String FN)
      Create a new PageWriter.
      Parameters:
      FN - fileName
  • Method Details

    • setFont

      public void setFont(Font font, int orientation, boolean ask)
      Set font and paper orientation.
      Parameters:
      font - the font
      orientation - 0:LANDSCAPE, 1:PORTRAIT
      ask - true: ask user through a popup dialogue
    • setMargins

      public void setMargins(double top, double left, double bot, double right)
      Set margins.

      All fields are desimal numbers measured in mm.

      Parameters:
      top - margin
      left - margin
      bot - margin
      right - margin
    • open

      public void open()
      Sets defaults
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException
    • write

      public void write(char[] cbuf, int off, int len) throws IOException
      Specified by:
      write in class Writer
      Throws:
      IOException
    • flush

      public void flush() throws IOException
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException
    • newPage

      public void newPage(int n)
      Create a new page.
      Parameters:
      n - page number
    • getLinesPerSheet

      public int getLinesPerSheet()
      Returns the number of lines per sheet.
      Returns:
      the number of lines per sheet
    • addChar

      private void addChar(char c)
      Add a character to the current line.
      Parameters:
      c - the character to add
    • newLine

      private void newLine()
      Advance to the next line. If there is no space on the current page, create a new page
    • setMargins

      private void setMargins(PageFormat sheet, double top, double left, double bot, double right)
      Set page format and the margins.
      Parameters:
      sheet - the page format
      top - the top margin in mm
      left - the left margin in mm
      bot - the bottom margin in mm
      right - the right margin in mm
    • isBookEmpty

      private boolean isBookEmpty()
      Check if book is empty
      Returns:
      true if book is empty
    • print

      private void print()
      Perfor printing
    • tryPrint

      private boolean tryPrint()
      Try to print, if failed open an error dialog.
      Returns:
      false if success.
    • lookupPrintService

      private PrintService lookupPrintService()
      Lookup print service
      Returns:
      a print service