|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsophware.print.Printer
Printer offers an easy to use interface to
print any graphical component.
Print options can be modified programmatically using the methods
described below, or with the optional Page Setup dialog.

This Page Setup Dialog allows its user to modify the paper margins,
paper size and paper orientation. It also allows scaling of the
image to be printed and anchoring the image to different locations
within the page and for JTextComponents it will allow
automatic page break detection.
The thumbnail preview shows the pages to be printed. When the thumbnail is clicked upon, it pops up a dialog containing a full scale preview.

Indirect Use:
The simplest way to use the Printer class is indirectly
through the JPrintButton or JPrintMenuItem
components. Including either of these components in your frame provides
it with instant Printer access.
import sophware.print.*;
...
JPanel p = new JPanel();
p.add(new JPrintButton()); // add a print button to your frame
and/or
JMenubar mb = new JMenuBar();
JMenu m = new JMenu("File");
m.add(new JPrintMenuItem()); // add a print button to your menu bar
mb.add(m);
setJMenuBar(mb);
Direct Use:Printer class directly, the standard
pattern is roughly as follows:
import sophware.print.*; ... Printer printer = new Printer(myFrame); printer.setDefaultMaxWidth(1); // prevent image from extending beyond one page in width printer.print(myComponent); // print my component
JPrintButton,
JPrintMenuItem| Field Summary | |
static int |
CENTER
Anchor component in the center |
static int |
EAST
Anchor component right justified centered vertically |
static int |
NORTH
Anchor component to the top of the page centered |
static int |
NORTHEAST
Anchor component to the top of the page right justified |
static int |
NORTHWEST
Anchor component to the top of the page left justified |
static int |
SOUTH
Anchor component to the bottom and centered |
static int |
SOUTHEAST
Anchor component to the bottom right justified |
static int |
SOUTHWEST
Anchor component to the bottom left justified |
static int |
UNLIMITED_PAGES
Value for unlimited number of pages |
static int |
WEST
Anchor component left justified centered vertically |
| Constructor Summary | |
Printer()
Constructs a new Printer instance
With the default constructor, none of the setup dialogs
can be used unless a Frame is supplied on
a subsequent call to print |
|
Printer(java.awt.Frame frame)
Constructs a new Printer instance |
|
| Method Summary | |
int |
getDefaultAnchor()
Gets the default anchor position |
int |
getDefaultMaxHeight()
Returns the default maximum height (in pages). |
int |
getDefaultMaxWidth()
Returns the default width (in pages). |
int |
getDefaultOrientation()
Get the default page orientation |
double |
getDefaultPaperHeight()
Gets the default paper height (in inches). |
double |
getDefaultPaperWidth()
Gets the default paper width (in inches). |
double |
getDefaultTextScale()
Get default scaling for text components. |
boolean |
isAutoOrientEnabled()
Indicates whether or not automatic page orientation is enabled whether or not automatic orientation adjustments are enabled |
boolean |
isDefaultTextFormatingEnabled()
Indicates whether or not text formating is enabled whether or not text formating is enabled |
boolean |
isFormatedAsText(java.awt.Component comp)
Indicates whether or not the given component will be formatted as text. |
boolean |
isNativePageSetupEnabled()
Indicates whether or not the native page setup Dialog
is enabled. |
boolean |
isNativePrinterSetupEnabled()
Indicates whether or not the native Printer Setup Dialog is enabled. |
boolean |
isPageSetupEnabled()
Indicates whether or not the Page Setup Dialog is
enabled. |
boolean |
print(java.awt.Component comp)
Print the given component. |
boolean |
print(java.awt.Component comp,
int copies)
Print the given number of copies of the given component. |
boolean |
print(java.awt.Frame frame,
java.awt.Component comp,
int copies)
Print the given number of copies of the given component using the given base Frame. |
void |
restoreDefaults()
Restore printer values to their defaults. |
void |
setAutoOrientEnabled(boolean enable)
Enables and disables automatic orientation changes. |
void |
setDefaultAnchor(int anchor)
Sets the default position of how the component should be placed within the page or pages. |
void |
setDefaultMargins(double top,
double bottom,
double left,
double right)
Sets the default margins (in inches) for subsequent calls to print(). |
void |
setDefaultMaxHeight(int pages)
Sets the default maximum height (in pages) of a print request. |
void |
setDefaultMaxWidth(int pages)
Sets the default maximum width (in pages) of a print request. |
void |
setDefaultOrientation(int orientation)
Sets the default page orientation for subsequent calls to print(). |
void |
setDefaultPaperSize(double width,
double height)
Sets the default paper size (in inches). |
void |
setDefaultTextFormatingEnabled(boolean enable)
Enables and disables text formating on text components. |
void |
setDefaultTextScale(double scale)
Set default scaling for text components. |
void |
setNativePageSetupEnabled(boolean enabled)
Enables or disables the native Page Setup Dialog The native Page Setup Dialog is a platform specific
dialog. |
void |
setNativePrinterSetupEnabled(boolean enabled)
Enables or disables the native printer Setup Dialog. |
void |
setPageSetupEnabled(boolean enabled)
Enables or disables the class Page Setup Dialog |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final int UNLIMITED_PAGES
setDefaultMaxWidth(int),
setDefaultMaxHeight(int),
getDefaultMaxWidth(),
getDefaultMaxHeight(),
Constant Field Valuespublic static final int NORTHWEST
public static final int NORTH
public static final int NORTHEAST
public static final int WEST
public static final int CENTER
public static final int EAST
public static final int SOUTHWEST
public static final int SOUTH
public static final int SOUTHEAST
| Constructor Detail |
public Printer()
Printer instance
With the default constructor, none of the setup dialogs
can be used unless a Frame is supplied on
a subsequent call to print
print(java.awt.Component)public Printer(java.awt.Frame frame)
Printer instance
frame - is the base frame associated with any dialogs| Method Detail |
public void setDefaultOrientation(int orientation)
print(). Use of this method disables
automatic orientation.
orientation - one of the constants PageFormat.PORTRAIT,
PageFormat.LANDSCAPE, PageFormat.REVERSE_LANDSCAPEgetDefaultOrientation(),
setAutoOrientEnabled(boolean),
print(java.awt.Component)public int getDefaultOrientation()
setDefaultOrientation(int),
print(java.awt.Component)
public void setDefaultMargins(double top,
double bottom,
double left,
double right)
print().
Margins are subject to physical constraints of your printer.
Your values may be adjusted to conform to your printer
specifications.
top - margin at top of page in inches
& @param bottom margin at bottom of page in inchesleft - margin at left of page in inchesright - margin at right of page in inchesprint(java.awt.Component)public void setDefaultMaxWidth(int pages)
pages - the default width or constant UNLIMITED_PAGES default is
UNLIMITED_PAGES.getDefaultMaxWidth(),
print(java.awt.Component)public int getDefaultMaxWidth()
setDefaultMaxWidth(int),
print(java.awt.Component)public void setDefaultMaxHeight(int pages)
pages - the default height or constant UNLIMITED_PAGES.
Default is UNLIMITED_PAGES.getDefaultMaxHeight(),
print(java.awt.Component)public int getDefaultMaxHeight()
setDefaultMaxHeight(int),
print(java.awt.Component)
public void setDefaultPaperSize(double width,
double height)
width - paper width in inchesheight - paper width in inchesgetDefaultPaperWidth(),
getDefaultPaperHeight()public double getDefaultPaperWidth()
setDefaultPaperSize(double, double)public double getDefaultPaperHeight()
setDefaultPaperSize(double, double)public void setNativePrinterSetupEnabled(boolean enabled)
Dialog.
The Printer Setup Dialog is a platform specific dialog.
The Printer class has no control over its look and feel.
If your application requires access to more than one printer, or
if you want to be able to access the paper source, you will need
to have this feature activated.
enabled - true or false. The default value is false.isNativePrinterSetupEnabled()public boolean isNativePrinterSetupEnabled()
setNativePrinterSetupEnabled(boolean)public void setNativePageSetupEnabled(boolean enabled)
Dialog is a platform specific
dialog. The Printer class has no control over its
look and feel. This dialog may or may not recognize your
default settings for (margins, orientation, etc...). This is
dependent upon the implementation and printer configuration.
enabled - true or false. The default value is false.setPageSetupEnabled(boolean),
isNativePageSetupEnabled()public boolean isNativePageSetupEnabled()
Dialog
is enabled.
DialogsetNativePageSetupEnabled(boolean)public void setPageSetupEnabled(boolean enabled)
Dialog
enabled - true or false. The default value is true.isPageSetupEnabled()public boolean isPageSetupEnabled()
Dialog is
enabled.
DialogsetPageSetupEnabled(boolean)public void setAutoOrientEnabled(boolean enable)
enable - true or false. The default value is true.isAutoOrientEnabled()public boolean isAutoOrientEnabled()
setAutoOrientEnabled(boolean)public double getDefaultTextScale()
setDefaultTextScale(double)public void setDefaultTextScale(double scale)
scale - scaling value to be used by defaultgetDefaultTextScale()public void setDefaultTextFormatingEnabled(boolean enable)
Printer class will attempt to find
best fit page breaks when the component being printed is a
JTextComponent.
enable - true or false. The default value is true.isDefaultTextFormatingEnabled()public boolean isDefaultTextFormatingEnabled()
setDefaultTextFormatingEnabled(boolean)public boolean isFormatedAsText(java.awt.Component comp)
setDefaultTextFormatingEnabled(boolean),
isDefaultTextFormatingEnabled()public void setDefaultAnchor(int anchor)
anchor - one of 9 positions (e.g. NORTH, NORTHEAST, ...)getDefaultAnchor()public int getDefaultAnchor()
setDefaultAnchor(int)public void restoreDefaults()
public boolean print(java.awt.Component comp)
comp - Component to be printed
public boolean print(java.awt.Component comp,
int copies)
comp - Component to be printedcopies - number of copies to be printed
public boolean print(java.awt.Frame frame,
java.awt.Component comp,
int copies)
Frame.
base Frame for any subsequent
dialogs, overrides that
which was given in the constructor.
frame - base Frame used for dialogscomp - Component to be printedcopies - number of copies to be printed
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||