JComponentPack 1.5.0

com.zfqjava.swing
Class JPrintPreview

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by com.zfqjava.swing.JPrintPreview
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class JPrintPreview
extends JComponent
implements Accessible

JPrintPreview provides a print preview component.

Client Property:

NameValueDefault Value
JPrintPreview.pageViewMode
  • SinglePage
  • ContinuousPage
SinglePage

See Also:
Serialized Form

Nested Class Summary
protected  class JPrintPreview.AccessibleJPrintPreview
          This class implements accessibility support for the JPrintPreview class.
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int CLOSE_CONTROL
          Type used for close button on the pane.
static int COLOR
          Identifies the color for print preview.
static int HELP_CONTROL
          Type used for help button on the pane.
static int MONOCHROME
          Identifies the monochrome for print preview.
static int PAGE_SETUP_CONTROL
          Type used for page setup button on the pane.
static int PRINT_CONTROL
          Type used for print button on the pane.
 
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
JPrintPreview()
          Constructs a print preview component.
JPrintPreview(Object printData)
          Constructs a print preview component with the print data for preview.
 
Method Summary
 void close()
          Called by JPrintPreview when the user hits the Close button.
protected  BufferedImage createBufferedImage(int width, int height, int colorType)
          Creates the buffered image for preview.
protected  JDialog createDialog(Component parent, String title)
          Creates a dialog for the JPrintPreview.
protected  JFrame createFrame(String title)
          Creates a frame for the JPrintPreview.
 AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this JPrintPreview.
 int getColorType()
          Returns the color type for print preview.
 JButton getControlButton(int controlType)
          Gets the control button of the type.
 PrinterJob getDefaultPrinterJob()
          Gets the PrinterJob.
 JFrame getFrame()
          Returns the opened frame after invoke the methods showFrame() or showFrame(String).
 int getPageCount()
          Returns the page count.
 PageFormat getPageFormat()
          Returns the page format object current set.
 int getPageHeight(int index)
          Returns the page height.
 BufferedImage getPageImage(int index)
          Returns the page image used for preview.
 int getPageIndex()
          Returns the current page index.
 int getPageWidth(int index)
          Returns the page width.
 Object getPrintData()
          Returns the print data for current preview.
 PrintPreviewUI getUI()
          Returns the look and feel (L&F) object that renders this component.
 String getUIClassID()
          Returns a string that specifies the name of the L&F class that renders this component.
 double getZoomFactor()
          Returns the current zoom factor.
 void help()
          Called by JPrintPreview when the user hits the Help button.
 void pageSetup()
          Called by JPrintPreview when the user hits the Page Setup button.
protected  String paramString()
          Returns a string representation of this JPrintPreview.
 void print()
          Called by JPrintPreview when the user hits the Print button.
 void print(Object printData)
          Print the print data.
 void setColorType(int colorType)
          Sets the color type for print preview.
 void setPageFormat(PageFormat pageFormat)
          Sets the page format for current preview.
 void setPageIndex(int pageIndex)
          Sets the page index to view.
 void setPrintData(Object printData)
          Sets the print data for preview.
 void setUI(PrintPreviewUI ui)
          Sets the look and feel (L&F) object that renders this component.
 void setZoomFactor(double zoomFactor)
          Sets the zoom factor for view.
 void showApplet(Applet applet)
          Shows the applet contains the JPrintPreview.
 void showDialog(Component parent)
          Pops up a dialog contains the JPrintPreview with the dialog having a default title.
 void showDialog(Component parent, String title)
          Pops up a dialog contains the JPrintPreview and with the dialog having a title title.
 void showFrame()
          Pops up a frame contains the JPrintPreview with the frame having a default title.
 void showFrame(JFrame frame)
          Shows the JPrintPreview in the specified frame.
 void showFrame(String title)
          Pops up a frame contains the JPrintPreview and with the frame having a title title.
 void showInternalFrame(JInternalFrame internalFrame)
          Shows the JPrintPreview in the specified internalFrame.
 void updateUI()
          Resets the UI property with a value from the current look and feel.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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
 

Field Detail

PRINT_CONTROL

public static final int PRINT_CONTROL
Type used for print button on the pane.

See Also:
Constant Field Values

PAGE_SETUP_CONTROL

public static final int PAGE_SETUP_CONTROL
Type used for page setup button on the pane.

See Also:
Constant Field Values

HELP_CONTROL

public static final int HELP_CONTROL
Type used for help button on the pane.

See Also:
Constant Field Values

CLOSE_CONTROL

public static final int CLOSE_CONTROL
Type used for close button on the pane.

See Also:
Constant Field Values

MONOCHROME

public static final int MONOCHROME
Identifies the monochrome for print preview.

See Also:
Constant Field Values

COLOR

public static final int COLOR
Identifies the color for print preview.

See Also:
Constant Field Values
Constructor Detail

JPrintPreview

public JPrintPreview()
Constructs a print preview component.


JPrintPreview

public JPrintPreview(Object printData)
Constructs a print preview component with the print data for preview.

Method Detail

updateUI

public void updateUI()
Resets the UI property with a value from the current look and feel.

Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()

getUI

public PrintPreviewUI getUI()
Returns the look and feel (L&F) object that renders this component.

Returns:
the PrintPreviewUI object that renders this component

setUI

public void setUI(PrintPreviewUI ui)
Sets the look and feel (L&F) object that renders this component.

Parameters:
ui - the PrintPreviewUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

getUIClassID

public String getUIClassID()
Returns a string that specifies the name of the L&F class that renders this component.

Overrides:
getUIClassID in class JComponent
Returns:
"PrintPreviewUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setPrintData

public void setPrintData(Object printData)
Sets the print data for preview. Following type current support:

Parameters:
printData - the print data for preview
See Also:
getPrintData()

getPrintData

public Object getPrintData()
Returns the print data for current preview. Following type current support:

Returns:
the print data for current preview
See Also:
setPrintData(java.lang.Object)

setPageFormat

public void setPageFormat(PageFormat pageFormat)
Sets the page format for current preview. Apply the following rules: If the print data is java.awt.print.Printable or java.awt.print.Pageable, and the page format is not null, all print method in Printable pass this parameter. If the page format is null, use print data page format object, if the page format for that object is null, use the default page format object gets from default print job object.

Parameters:
pageFormat - the page format object
See Also:
getPageFormat()

getPageFormat

public PageFormat getPageFormat()
Returns the page format object current set. Default is null.

Returns:
the page format object current set
See Also:
setPageFormat(java.awt.print.PageFormat)

setPageIndex

public void setPageIndex(int pageIndex)
Sets the page index to view.

Parameters:
pageIndex - the page index
See Also:
getPageIndex()

getPageIndex

public int getPageIndex()
Returns the current page index.

Returns:
the current page index
See Also:
setPageIndex(int)

getPageCount

public int getPageCount()
Returns the page count.

Returns:
the page count

getPageImage

public BufferedImage getPageImage(int index)
Returns the page image used for preview.

Parameters:
index - the page index
Returns:
the page image for preview

getPageWidth

public int getPageWidth(int index)
Returns the page width. Sets the zoom factor will change the page width.

Parameters:
index - the page index
Returns:
the page width

getPageHeight

public int getPageHeight(int index)
Returns the page height. Sets the zoom factor will change the page height.

Parameters:
index - the page index
Returns:
the page height

setZoomFactor

public void setZoomFactor(double zoomFactor)
Sets the zoom factor for view.

Parameters:
zoomFactor - the zoom factor
Throws:
IllegalAugumentException - if zoomFactor <= 0
See Also:
getZoomFactor()

getZoomFactor

public double getZoomFactor()
Returns the current zoom factor.

Returns:
the current zoom factor
See Also:
setZoomFactor(double)

setColorType

public void setColorType(int colorType)
Sets the color type for print preview.

Parameters:
colorType - the color type:
  • JPrintPreview.MONOCHROME
  • JPrintPreview.COLOR
Since:
JDataGrid 1.5.1
See Also:
getColorType()

getColorType

public int getColorType()
Returns the color type for print preview.

One of 2 legal values:

Returns:
the color type
Since:
JDataGrid 1.5.1
See Also:
setColorType(int)

showDialog

public void showDialog(Component parent)
Pops up a dialog contains the JPrintPreview with the dialog having a default title.


showDialog

public void showDialog(Component parent,
                       String title)
Pops up a dialog contains the JPrintPreview and with the dialog having a title title.

Parameters:
title - the title of the dialog

createDialog

protected JDialog createDialog(Component parent,
                               String title)
Creates a dialog for the JPrintPreview.

Parameters:
parent - the parent of the dialog
title - the title of the dialog
See Also:
showDialog(Component,String), showDialog(Component)

showFrame

public void showFrame()
Pops up a frame contains the JPrintPreview with the frame having a default title.

Since:
JDataGrid 1.2
See Also:
showDialog(Component), showDialog(Component,String), showFrame(String)

showFrame

public void showFrame(String title)
Pops up a frame contains the JPrintPreview and with the frame having a title title.

Parameters:
title - the title of the frame
Since:
JDataGrid 1.2
See Also:
showDialog(Component), showDialog(Component,String), showFrame()

getFrame

public JFrame getFrame()
Returns the opened frame after invoke the methods showFrame() or showFrame(String).

Since:
JDataGrid 2.6.0

showFrame

public void showFrame(JFrame frame)
Shows the JPrintPreview in the specified frame.

Since:
JDataGrid 1.6.0
See Also:
showDialog(java.awt.Component), showFrame()

createFrame

protected JFrame createFrame(String title)
Creates a frame for the JPrintPreview.

Parameters:
title - the title of the frame
Since:
JDataGrid 1.2
See Also:
showFrame(), showFrame(String)

showInternalFrame

public void showInternalFrame(JInternalFrame internalFrame)
Shows the JPrintPreview in the specified internalFrame.

Since:
JDataGrid 1.6.0
See Also:
showDialog(java.awt.Component), showFrame(), showInternalFrame(javax.swing.JInternalFrame)

showApplet

public void showApplet(Applet applet)
Shows the applet contains the JPrintPreview.

Since:
JDataGrid 1.8
See Also:
showDialog(java.awt.Component), showFrame(), showInternalFrame(javax.swing.JInternalFrame)

getControlButton

public JButton getControlButton(int controlType)
Gets the control button of the type.

Parameters:
controlType - the type of the button to be selected:
  • JPrintPreview.PRINT_CONTROL
  • JPrintPreview.PAGE_SETUP_CONTROL
  • JPrintPreview.HELP_CONTROL
  • JPrintPreview.CLOSE_CONTROL
Returns:
the button for the specify type

print

public void print()
Called by JPrintPreview when the user hits the Print button. This can also be called by the programmer.


print

public void print(Object printData)
Print the print data.

Parameters:
printData - print the print data
Since:
JDataGrid 1.6.0

pageSetup

public void pageSetup()
Called by JPrintPreview when the user hits the Page Setup button. This can also be called by the programmer.


help

public void help()
Called by JPrintPreview when the user hits the Help button. This can also be called by the programmer.


close

public void close()
Called by JPrintPreview when the user hits the Close button. This can also be called by the programmer.


getDefaultPrinterJob

public PrinterJob getDefaultPrinterJob()
Gets the PrinterJob. The default behavior return PrinterJob.getPrinterJob().

Returns:
PrinterJob the PrinterJob object

createBufferedImage

protected BufferedImage createBufferedImage(int width,
                                            int height,
                                            int colorType)
Creates the buffered image for preview.

Parameters:
width - the image width
height - the image height
colorType - the image color type
Since:
JDataGrid 1.5.1

paramString

protected String paramString()
Returns a string representation of this JPrintPreview. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null.

Overrides:
paramString in class JComponent
Returns:
a string representation of this JPrintPreview.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JPrintPreview. For JPrintPreviews, the AccessibleContext takes the form of an AccessibleJPrintPreview. A new AccessibleJPrintPreview instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JComponent
Returns:
an AccessibleJPrintPreview that serves as the AccessibleContext of this JPrintPreview

JComponentPack 1.5.0

Send your Feedback
JComponentPack 1.5.0
Copyright © 2001-2007 Extreme Component, Inc. All rights reserved.