|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent com.wildcrest.j2printerworks.J2Printer com.wildcrest.j2printerworks.J2Printer14
A J2Printer subclass supporting JDK 1.4 printing features, including printer discovery and selection,
print request attribute sets, cross-platform page setup and print dialogs, and print to Postscript
This class includes methods for specifying a PrintRequestAttributeSet, which is a class in JDK 1.4 (or later)
for specifying desired printer characteristics. If setCrossPlatformDialogs(false) is specified, the native
page setup and print dialogs are used (the same as are used under JDK 1.2 or 1.3).
If setCrossPlatformDialogs(true) is specified, then the cross-platform page setup and print dialogs are used,
initialized to the values specified in the PrintRequestAttributeSet.
J2Printer14 includes methods for finding the names of all printers accessible from the
user's machine that match a specified PrintRequestAttributeSet (or all printers if no
attributes are given) and for finding the name of the user's default printer.
J2Printer14 then lets you specify by name which printer to use for printing.
Programs using the J2Printer parent class can build and run on any JDK 1.2 or later.
Use the J2Printer14 subclass to access the JDK 1.4 printing features, but you must build and run under JDK 1.4 or later.
(C) Copyright 2009, Wildcrest Associates (http://www.wildcrest.com). All rights reserved.
Nested Class Summary |
Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Field Summary |
Fields inherited from class com.wildcrest.j2printerworks.J2Printer |
BEFORE, BOTTOM, BOX, CENTER, FIRST, GLOBAL, LANDSCAPE, LEFT, LINE, NEVER, NONE, OUTLINE, PLAIN, PORTRAIT, PPI72, printerJob, printerJobSeparateThread, REST, REVERSE_LANDSCAPE, RIGHT, SHADOW, TOP, WAIT |
Fields inherited from class javax.swing.JComponent |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
J2Printer14()
Construct a J2Printer14 object with no serial number, a default printer, and an empty Pageable. |
|
J2Printer14(java.awt.print.PrinterJob printerJob)
Construct a J2Printer14 object with no serial number, a given PrinterJob, and an empty Pageable. |
|
J2Printer14(java.lang.String serialNum)
Construct a J2Printer14 object with given serial number, default printer, and empty Pageable. |
|
J2Printer14(java.lang.String serialNum,
java.awt.print.PrinterJob printerJob)
Construct a J2Printer14 object with given serial number and PrinterJob, and empty Pageable. |
Method Summary | |
java.lang.String[] |
getAllPrinterNames()
Method which returns the names of all available "Pageable" printers for this system. |
boolean |
getCollate()
Returns the SheetCollate attribute from the current print request attribute set as a boolean. |
int |
getCopies()
Returns the number of copies to be printed from the Copies attribute in current print request attribute set. |
java.lang.String |
getDefaultPrinterName()
Method which returns the name of the default printer for the user's machine. |
java.lang.String |
getJobName()
Returns the job name for the print job based on the JobName attribute in current print request attribute set. |
java.lang.String |
getMediaSize()
Returns the media size specified in the current print request attribute set as a user-friendly String, e.g., Letter, Legal |
java.lang.String[] |
getMediaSizes()
Returns the supported media sizes for the current printer as a String array of user-friendly names, e.g., Letter, Legal. |
double |
getMinimumBottomMargin(int orientation)
Returns the minimum (physically unprintable) bottom margin for the current printer. |
double |
getMinimumLeftMargin(int orientation)
Returns the minimum (physically unprintable) left margin for the current printer. |
double |
getMinimumRightMargin(int orientation)
Returns the minimum (physically unprintable) right margin for the current printer. |
double |
getMinimumTopMargin(int orientation)
Returns the minimum (physically unprintable) top margin for the current printer. |
int |
getOrientation()
Returns the paper orientation from the specified OrientationRequested attribute in the current print request attribute set. |
java.lang.String |
getPageRanges()
Returns the PageRanges attribute from the current print request attribute set as a user-friendly String. |
double |
getPaperHeight()
Returns the paper height from the specified MediaSize attribute in the current print request attribute set. |
double |
getPaperWidth()
Returns the paper width from the specified MediaSize attribute in the current print request attribute set. |
java.lang.String |
getPrinter()
Method used to get the name of the currently selected printer. |
java.lang.String[] |
getPrinterNames()
Method which returns the names of available printers given the current PrintRequestAttributeSet, with the printer names returned as an array of Strings. |
javax.print.attribute.PrintRequestAttributeSet |
getPrintRequestAttributeSet()
Returns the currently specified PrintRequestAttributeSet used by J2Printer14. |
boolean |
isCrossPlatformDialogs()
Returns whether the cross-platform printing dialogs are to be used instead of the native printing dialogs. |
byte[] |
printToPS()
Utility method for printing the current document to Postscript stored in an in-memory byte array. |
void |
printToPS(java.io.OutputStream outputStream)
Utility method for printing the current document to Postscript and storing in a provided OutputStream. |
void |
printToPS(java.lang.String file)
Utility method for printing the current document to a Postscript (.ps) file, suitable for dumping to a Postscript printer, viewing with a program such as GhostScript, or converting to PDF using programs such as Adobe Acrobat Distiller or PS2PDF (part of Ghostscript). |
void |
sendBytesToPrinter(byte[] byteArray)
Utility method for sending the specified byte array as raw data to the current printer. |
void |
setBottomMargin(double bottom)
Sets the "global" (overall, default) bottom margin below footer in inches from the edge of the page (when viewing content). |
void |
setCollate(boolean collate)
Sets the SheetCollate attribute in the current print request attribute set. |
void |
setCopies(int numCopies)
Sets the number of copies to be printed as a Copies attribute in the current print request attribute set as well as in the current PrinterJob instance. |
void |
setCrossPlatformDialogs(boolean crossPlatformDialogs)
Sets whether to use the cross-platform printing dialogs instead of the native printing dialogs. |
void |
setJobName(java.lang.String jobName)
Sets the job name for the print job as a JobName attribute in the current print request attribute set as well as in the current PrinterJob instance. |
void |
setLeftMargin(double left)
Sets the "global" (overall, default) left margin in inches from the edge of the page (when viewing content). |
void |
setMargins(double left,
double right,
double top,
double bottom)
Convenience method for setting all four margins at once. |
void |
setMediaSize(java.lang.String mediaName)
Sets the Media attribute in the current print request attribute set. |
void |
setOrientation(int o)
Sets "global" (overall, default) page orientation (causes corresponding reordering of unprintable margin settings) |
void |
setPageFormat(java.awt.print.PageFormat pf)
Convenience method for setting this J2Printer's "global" margins, page size, and orientation from an external PageFormat instance. |
void |
setPageRanges(java.lang.String pageRanges)
Sets the PageRanges attribute in the current print request attribute set. |
void |
setPaperSize(double pW,
double pH)
Sets the "global" (overall, default) paper width and height in 1/72nds of an inch when paper viewed in PORTRAIT. |
boolean |
setPrinter(java.lang.String name)
Method used to set the desired printer. |
void |
setPrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet aset)
Method for setting a PrintRequestAttributeSet for specifying desired printing attributes to be used for printing if the cross-platform dialogs are used. |
void |
setRightMargin(double right)
Sets the "global" (overall, default) right margin in inches from the edge of the page (when viewing content). |
void |
setTopMargin(double top)
Sets the "global" (overall, default) top margin above header in inches from the edge of the page when viewing content). |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public J2Printer14()
public J2Printer14(java.awt.print.PrinterJob printerJob)
public J2Printer14(java.lang.String serialNum)
public J2Printer14(java.lang.String serialNum, java.awt.print.PrinterJob printerJob)
Method Detail |
public void setPrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet aset)
If setCrossPlatformDialogs(true) is specified, the cross-platform page setup and print dialogs will be used, and the specified PrintRequestAttributeSet will be use to set the desired printing attributes. If the values for number of copies, print job name, paper size, and/or orientation are specified by the PrintRequestAttributeSet, this will be used, otherwise the values set by the J2Printer setNumberOfCopies, setPrintJobName, setPaperSize, and/or setOrientation methods will be used.
Example:
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
aset.add(new JobName("My print job name", null));
aset.add(OrientationRequested.LANDSCAPE);
aset.add(MediaSizeName.NA_NUMBER_10_ENVELOPE); // or MediaSizeName.ISO_A4, etc.
aset.add(new PageRanges(1,getPageable().getNumberOfPages()));
aset.add(PrintQuality.DRAFT);
aset.add(Chromaticity.MONOCHROME);
j2printer14.setPrintRequestAttributeSet(aset);
See JDK 1.4 class PrintRequestAttributeSet for additional attributes that may be selected.
The values in the PrintRequestAttributeSet will be used in initializing the page setup and print dialogs.
The values may be modified by the system depending on the capabilities of the current printer
when presented in the page setup or print dialogs to the end user. The
end user may then modify these choices further in the page setup and/or print dialogs
to arrive at the settings actually used in printing.
The value of the PrintRequestAttributeSet specified by this method
(and returned by getPrintRequestAttributeSet()
) will automatically be
updated to reflect these page setup and/or print dialog modifications.
Default: initialized to new HashPrintRequestAttributeSet(), which is an empty list of attributes.
aset
- the printing attributes to be used for this print operation.public javax.print.attribute.PrintRequestAttributeSet getPrintRequestAttributeSet()
public java.lang.String[] getPrinterNames()
public java.lang.String[] getAllPrinterNames()
public java.lang.String getDefaultPrinterName()
public boolean setPrinter(java.lang.String name)
name
- String The name of the printer to be used.public java.lang.String getPrinter()
public void printToPS(java.lang.String file)
file
- The file name into which the Postscript file will be written (if missing,
assumes ./out.ps, if doesn't end in .ps, will add .ps, all folders in path must already exist).public byte[] printToPS()
public void printToPS(java.io.OutputStream outputStream)
outputStream
- A provided java.io.OutputStream into which the Postscript will be written.public void sendBytesToPrinter(byte[] byteArray)
byte[] bytes = printToPS();
dumpBytesToPrinter(bytes);
public int getCopies()
public void setCopies(int numCopies)
numCopies
- int number of copies to be printedpublic java.lang.String getJobName()
public void setJobName(java.lang.String jobName)
jobName
- String job name for the print job to be printedpublic java.lang.String getPageRanges()
public void setPageRanges(java.lang.String pageRanges)
pageRanges
- String user-friendly page ranges string, e.g. 1-3,6,9-12public boolean getCollate()
public void setCollate(boolean collate)
collate
- boolean print collated if true, not collated if falsepublic java.lang.String[] getMediaSizes()
public java.lang.String getMediaSize()
public void setMediaSize(java.lang.String mediaName)
mediaName
- String user-friendly media size name, e.g., Letter, Legal.public int getOrientation()
getOrientation
in class J2Printer
public double getPaperWidth()
getPaperWidth
in class J2Printer
public double getPaperHeight()
getPaperHeight
in class J2Printer
public double getMinimumLeftMargin(int orientation)
public double getMinimumRightMargin(int orientation)
public double getMinimumTopMargin(int orientation)
public double getMinimumBottomMargin(int orientation)
public void setOrientation(int o)
J2Printer
setOrientation
in class J2Printer
o
- J2Printer.PORTRAIT or .LANDSCAPE or .REVERSE_LANDSCAPE
used when Pageable instance value is negative (e.g., GLOBAL).
(same as PageFormat.PORTRAIT, etc.). Default: PORTRAITpublic void setPaperSize(double pW, double pH)
J2Printer
setPaperSize
in class J2Printer
pW
- paper width in 1/72nds of an inch ("points") when viewed in PORTRAITpH
- paper height in 1/72nds of an inch ("points") when viewed in PORTRAITpublic void setLeftMargin(double left)
J2Printer
setLeftMargin
in class J2Printer
left
- double representing left margin in inches.
Used when Pageable instance value is negative (e.g., GLOBAL).
Default: 0.0public void setRightMargin(double right)
J2Printer
setRightMargin
in class J2Printer
right
- double representing right margin in inches.
Used when Pageable instance value is negative (e.g., GLOBAL).
Default: 0.0public void setTopMargin(double top)
J2Printer
setTopMargin
in class J2Printer
top
- double representing top margin above header in inches.
Used when Pageable instance value is negative (e.g., GLOBAL).
Default: 0.0public void setBottomMargin(double bottom)
J2Printer
setBottomMargin
in class J2Printer
bottom
- double representing bottom margin below footer in inches.
Used when Pageable instance value is negative (e.g., GLOBAL).
Default: 0.0public void setPageFormat(java.awt.print.PageFormat pf)
J2Printer
setPageFormat
in class J2Printer
pf
- PageFormat whose values will be used to set the J2Printer margins, page size,
and orientation.public void setMargins(double left, double right, double top, double bottom)
public void setCrossPlatformDialogs(boolean crossPlatformDialogs)
crossPlatformDialogs
- boolean representing whether to use the cross-platform printing dialogs instead of the
native printing dialogs. Default: truepublic boolean isCrossPlatformDialogs()
isCrossPlatformDialogs
in class J2Printer
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |