Package org.fife.print
Class RPrintUtilities
java.lang.Object
org.fife.print.RPrintUtilities
A collection of static methods useful for printing text from Swing text components.
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
A tab expander for the document currently being printed with the font being used for the printing. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]
private static int
private static FontMetrics
The metrics of the font currently being used to print.private static int
private static Element
private static int
The length of a tab, in spaces.private static int
The x-offset (for the page margin) when printing. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static int
getLineBreakPoint
(String line, int maxCharsPerLine) Returns the position closest to, but before, positionmaxCharsPerLine
inline
of one of the chars inbreakChars
, or simply returnsmaxCharsPerLine-1
if none of thebreakChars
comes before that position.static int
printDocumentMonospaced
(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using a monospaced font, and does no word wrapping (ie, words will wrap mid-word to the next line).static int
printDocumentMonospacedWordWrap
(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using a monospaced font, word wrapping on the characters ' ', '\t', '\n', ',', '.', and ';'.static int
printDocumentWordWrap
(Graphics g, JTextComponent textComponent, Font font, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using the specified font, word wrapping on the characters ' ', '\t', '\n', ',', '.', and ';'.private static Segment
removeEndingWhitespace
(Segment segment) Removes any spaces or tabs from the end of the segment.
-
Field Details
-
currentDocLineNumber
private static int currentDocLineNumber -
numDocLines
private static int numDocLines -
rootElement
-
BREAK_CHARS
private static final char[] BREAK_CHARS -
xOffset
private static int xOffsetThe x-offset (for the page margin) when printing. -
tabSizeInSpaces
private static int tabSizeInSpacesThe length of a tab, in spaces. -
fm
The metrics of the font currently being used to print.
-
-
Constructor Details
-
RPrintUtilities
public RPrintUtilities()
-
-
Method Details
-
getLineBreakPoint
Returns the position closest to, but before, positionmaxCharsPerLine
inline
of one of the chars inbreakChars
, or simply returnsmaxCharsPerLine-1
if none of thebreakChars
comes before that position. This position represents the logical line break for thisjava.lang.String
if it is being printed in a monospaced font when lines can only bemaxCharsPerLine
characters long.- Parameters:
line
- The text being printed.maxCharsPerLine
- Only up-to this many characters fromline
can be printed on one line.- Returns:
- The logical position at which to stop printing
line
to simulate word wrap.
-
printDocumentMonospaced
public static int printDocumentMonospaced(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using a monospaced font, and does no word wrapping (ie, words will wrap mid-word to the next line). This method is expected to be called from Printable 'print(Graphics g)' functions.- Parameters:
g
- The graphics context to write to.doc
- Thejavax.swing.text.Document
to print.fontSize
- the point size to use for the monospaced font.pageIndex
- The page number to print.pageFormat
- The format to print the page with.tabSize
- The number of spaces to expand tabs to.- Returns:
- One of the constants from
Printable
. - See Also:
-
printDocumentMonospacedWordWrap
public static int printDocumentMonospacedWordWrap(Graphics g, Document doc, int fontSize, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using a monospaced font, word wrapping on the characters ' ', '\t', '\n', ',', '.', and ';'. This method is expected to be called from Printable 'print(Graphics g)' functions.- Parameters:
g
- The graphics context to write to.doc
- Thejavax.swing.text.Document
to print.fontSize
- the point size to use for the monospaced font.pageIndex
- The page number to print.pageFormat
- The format to print the page with.tabSize
- The number of spaces to expand tabs to.- Returns:
- One of the constants from
Printable
. - See Also:
-
printDocumentWordWrap
public static int printDocumentWordWrap(Graphics g, JTextComponent textComponent, Font font, int pageIndex, PageFormat pageFormat, int tabSize) Prints aDocument
using the specified font, word wrapping on the characters ' ', '\t', '\n', ',', '.', and ';'. This method is expected to be called from Printable 'print(Graphics g)' functions.- Parameters:
g
- The graphics context to write to.textComponent
- Thejavax.swing.text.JTextComponent
whose text you're printing.font
- The font to use for printing. Ifnull
, thentextComponent
's font is used.pageIndex
- The page number to print.pageFormat
- The format to print the page with.tabSize
- The number of spaces to convert tabs to.- Returns:
- One of the constants from
Printable
.
-
removeEndingWhitespace
Removes any spaces or tabs from the end of the segment.- Parameters:
segment
- The segment from which to remove tailing whitespace.- Returns:
segment
with trailing whitespace removed.
-