java.lang.Object
java.io.Writer
simula.runtime.RTS_PageWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Utility class PageWriter.
Link to GitHub: Source File.
- Author:
- Øystein Myhre Andersen
-
Nested Class Summary
Modifier and TypeClassDescriptionprivate class
Utility class to represent a printable sheet. -
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
If true: ask user to set font and paper orientation through a popup dialogue.private Book
The associated Bookprivate double
The bottom margin.private StringBuilder
The current lineprivate RTS_PageWriter.Sheet
The current sheetprivate String
The file name.private Font
The current Fontprivate static final double
1 inch == 0.02540 meterprivate double
The left margin.private float
The line gapprivate int
Number of lines per page.private int
The current paper sheet orientation.private PageFormat
The page formatprivate static final double
Pixels per meter.private static final double
Pixels per millimeter.private static final int
Dots Per Inch = 72private PrinterJob
The associated printerJob.private double
The right margin.private double
The top margin. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate void
addChar
(char c) Add a character to the current line.void
close()
void
flush()
int
Returns the number of lines per sheet.private boolean
Check if book is emptyprivate PrintService
Lookup print serviceprivate void
newLine()
Advance to the next line.void
newPage
(int n) Create a new page.void
open()
Sets defaultsprivate void
print()
Perfor printingvoid
Set font and paper orientation.void
setMargins
(double top, double left, double bot, double right) Set margins.private void
setMargins
(PageFormat sheet, double top, double left, double bot, double right) Set page format and the margins.private boolean
tryPrint()
Try to print, if failed open an error dialog.void
write
(char[] cbuf, int off, int len)
-
Field Details
-
inch
private static final double inch1 inch == 0.02540 meter- See Also:
-
printerDPI
private static final int printerDPIDots Per Inch = 72- See Also:
-
pixelsPerMeter
private static final double pixelsPerMeterPixels per meter.- See Also:
-
pixelsPerMilli
private static final double pixelsPerMilliPixels per millimeter.- See Also:
-
fileName
The file name. -
printerJob
The associated printerJob. -
book
The associated Book -
currentSheet
The current sheet -
pageFormat
The page format -
lineGap
private float lineGapThe line gap -
linesPerSheet
private int linesPerSheetNumber of lines per page. -
font
The current Font -
orientation
private int orientationThe current paper sheet orientation. -
ask
private boolean askIf true: ask user to set font and paper orientation through a popup dialogue. -
left
private double leftThe left margin. -
right
private double rightThe right margin. -
top
private double topThe top margin. -
bot
private double botThe bottom margin. -
currentLine
The current line
-
-
Constructor Details
-
RTS_PageWriter
Create a new PageWriter.- Parameters:
FN
- fileName
-
-
Method Details
-
setFont
Set font and paper orientation.- Parameters:
font
- the fontorientation
- 0:LANDSCAPE, 1:PORTRAITask
- 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
- marginleft
- marginbot
- marginright
- margin
-
open
public void open()Sets defaults -
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- 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
Set page format and the margins.- Parameters:
sheet
- the page formattop
- the top margin in mmleft
- the left margin in mmbot
- the bottom margin in mmright
- 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
Lookup print service- Returns:
- a print service
-