When you bring up the property sheet for TextPrinter (left), you will be able to see and edit all the page setup values supported by TextPrinter. Clicking on the "Text" field brings up a separate scrolling text area property editor, into which you can type or paste text to be printed. The text is one long string representing the entire text document to be printed. It may have hard line separators typed in explicitly by you. Or it may rely on TextPrinter's automatic line wrapping feature to break long lines. The rest of the properties may be set as desired, with values as defined in the "Using TextPrinter as a class" section below.
You can make the TextPrinter bean print by using your visual programming environment to perform event wiring from an actionPerformed event such as a button push to the TextPrinter "print" event target method. TextPrinter also exposes all the regular inherited component methods such as show, hide, enable, disable, etc.
TextPrinter is a subclass of Canvas. It overrides "paint" for purposes of displaying the printer icon during composition in your visual programming environment. The "paint", "print", "setFont", and "getFont" methods are the only methods that TextPrinter overrides.
All the TextPrinter properties are bound properties. You may use your visual programming environment to do property-to-property binding in either direction between TextPrinter and your other beans. None of the TextPrinter properties are constrained properties since TextPrinter computes no properties of its own and presumes values will be constrained where they originate. This frees you from having to place try...catch blocks around set calls in regular programming (if there is a reason you need some or all of the TextPrinter properties to be constrained, please contact products@wildcrest.com).
TextPrinter is fully serializable. After customizing any of their
properties (including the text), instances of TextPrinter beans can
be saved along with any other beans to which they may be wired. When
reloaded, the TextPrinter beans will each come back with their customized
values. No TextPrinter properties are declared transient.
Using TextPrinter as a class
![]() |
TextPrinter may also be used programmatically as a simple
class. TextPrinter is distributed in the package com.wildcrest. A com folder
with a wildcrest subfolder containing TextPrinter.class should be placed
somewhere in your classpath (see Installation instructions).
You may find it useful to begin your program with:
TextPrinter is instantiated with a zero-argument constructor:
You print by invoking a single call to the TextPrinter print method: print(String stringToPrint) That's all you need! The following is a very simple but complete Java program that prints: import com.wildcrest.TextPrinter;
|
Complete list of TextPrinter methods
TextPrinter has a single zero-argument constructor:
TextPrinter()
This constructs a TextPrinter object and initializes all values to
their defaults (see below).
TextPrinter has two print methods:
print(String string)
where string is a (long) string containing entire document
to be printed, which may (or may not) have embedded line.separators and
tabs. On any platform, you can use line feeds ('\n'), carriage returns
('\r'), or carriage returns followed immediately by a linefeed as your
line separators.
print()
This is the same as print(String string) but uses string from
most recent setText call (see below).
The rest of the TextPrinter methods are set and get methods for controlling the page formatting parameters. The defaults for all these values are given below and are also shown in the property sheet editor in the "Using TextPrinter as a JavaBean" section above (with the exception that the setText string is initially null).
setText(String string)
Sets the (long) text string containing the entire text document to
be printed. Can have embedded line.separators to indicate hard line boundaries
or can rely on line wrapping feature to break lines.
Default: null
String getText()
Returns the current value of the text string to be printed.
setInchesPerTab(double inchesPerTab)
Sets the inches per tab stop for the overall document.
Default: 0.5
double getInchesPerTab()
Returns the inches per tab stop.
setLineSpacing(double lineSpacing)
Sets the line spacing for the overall document, in multiples of fontHeight
(1.0 = single spacing, 2.0 = double spacing, etc.).
Default: 1.0
double getLineSpacing()
Returns the line spacing of the document.
setFont(Font font)
Sets the font for printing the overall body of the document.
Default: SansSerif, PLAIN, 14
Font getFont()
Returns the font specified for printing.
setLeftFooter(String leftFooter)
Sets the left footer of the document. All occurrences of ###
(3 pound signs) in leftFooter replaced by the current page number. All
strings between pairs of ||| (3 vertical bars) passed to the Java SimpleDateFormat
class and used to format the current date & time.
Default: Page ###
String getLeftFooter()
Returns the left footer of the document.
setRightFooter(String rightFooter)
Sets the right footer of the document. Page number and data &
time formatting same as for setLeftFooter.
Default: |||EEE, MMM d, yyyy 'at' hh:mm:ss a zzz||| (see Java SimpleDateFormat
class description for the codes used in this string)
String getRightFooter()
Returns the right footer of the document.
setLeftHeader(String leftHeader)
Sets the left header of the document. Page number and data & time
formatting same as for setLeftFooter.
Default: TextPrinter 1.0, (C) Copyright 1998
NOTE: value cannot be changed in free version.
String getLeftHeader()
Returns the left header of the document.
setRightHeader(String rightHeader)
Sets the right header of the document. Page number and data & time
formatting same as for setLeftFooter.
Default: Wildcrest Associates (http://www.wildcrest.com)
NOTE: value cannot be changed in free version.
String getRightHeader()
Returns the right header of the document.
setLeftMargin(double leftMargin)
Sets the left margin in inches (in addition to physical margin).
Default: 0.0
double getLeftMargin()
Returns the left margin of the document.
setRightMargin(double rightMargin)
Sets the right margin in inches (in addition to physical margin).
Default: 0.3
NOTE: due to cumulative font metrics and page width being imprecise
on certain platforms, setting rightMargin greater than 0 is recommended
to avoid clipping of rightmost characters. Also, due to a bug in the Windows
port of JDK 1.1.4 and earlier, printer pageWidth is underreported by about
1.65 inches. To compensate, negative values are also allowed for
the rightMargin and a value of -1.65 is recommended on Windows platforms.
double getRightMargin()
Returns the right margin of the document.
setTopMargin(double topMargin)
Sets the top margin above header in inches (in addition to physical
margin).
Default: 0.0
double getTopMargin()
Returns the top margin of the document.
setBottomMargin(double bottomMargin)
Sets the bottom margin below footer in inches (in addition to physical
margin).
Default 0.0
NOTE: due to a bug in the Windows port of JDK 1.1.4 and earlier,
printer pageHeight is underreported by about 2.0 inches. To compensate,
negative values are allowed for the bottomMargin and a value of -2.0 is
recommended on Windows platforms.
double getBottomMargin()
Returns the bottom margin of the document.
setGapBelowHeader(double gapBelowHeader)
Sets the gap between the header and first line of text in inches.
Default 0.3
double getGapBelowHeader()
Returns the gap between the header and first line of text in inches.
setGapAboveFooter(double gapAboveFooter)
Sets the gap between the last line of text and the footer in inches.
Default 0.3
double getGapAboveFooter()
Returns the gap between the last line of text and the footer in inches.
setWrap(boolean wrap)
Sets whether automatic line wrap is enabled or disabled.
Default: true (enabled)
boolean getWrap()
Returns whether automatic line wrapping is enabled or disabled.
TextPrinter overrides the standard Canvas paint method to draw the TextPrinter
printer icon in visual programming environments:
paint(Graphics g)
Draw the 32x32 color TextPrinter printer icon.
Finally, there are the two standard methods for registering interest
in TextPrinter bound properties:
addPropertyChangeListener(PropertyChangeListener
listener)
Add property change listener for TextPrinter bound properties
removePropertyChangeListener(PropertyChangeListener
listener)
Remove property change listener for TextPrinter bound properties