Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.pjsofts.eurobudget.gui
Class PrintableComponent  view PrintableComponent download PrintableComponent.java

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.pjsofts.eurobudget.gui.PrintableComponent
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Pageable, java.awt.print.Printable, java.io.Serializable

public class PrintableComponent
extends javax.swing.JComponent
implements java.awt.print.Printable, java.awt.print.Pageable

Basic Component that is able to print or preview another component. Receive an awt Component in parameters and prints it. Could be useed as a Printable or as a JComponent (to preview the printing)


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
private  boolean autoFit
          flag: make the component fit in page width if needed
private  int bufferH
          same as
private  int bufferW
          final width for buffer to be in page (same as buffer )
private  java.awt.Component component
          Initial awt component to render
private  int currentPage
          current index of page to display (starting from 0 like Print API)
private  double fitRatio
          fit ratio
private  boolean keepRatio
          if component is resized; keep its ratio
private  int numberOfPages
          last computed value for this
private  java.awt.print.PageFormat pageFormat
          Page format to use
private  int pageHeight
           
private  int pageWidth
          width of the page on screen in pixel (could be different as the one in page format) due of zoom
private  int portionH
          portion height, same as imageableHeight in one portion
private  double zoom
          zoom value
 
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.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
 
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PrintableComponent(java.awt.Component component, java.awt.print.PageFormat pf)
          convenient constructor that take autofit value from preferences
PrintableComponent(java.awt.Component component, java.awt.print.PageFormat pf, boolean autoFit)
           
 
Method Summary
 java.awt.Component getComponent()
          Getter for property component.
 int getCurrentPage()
          Getter for property currentPage.
 int getNumberOfPages()
          Returns the number of pages in the set.
 java.awt.print.PageFormat getPageFormat()
          Getter for property pageFormat.
 java.awt.print.PageFormat getPageFormat(int pageIndex)
          Returns the PageFormat of the page specified by pageIndex.
 java.awt.print.Printable getPrintable(int pageIndex)
          Returns the Printable instance responsible for rendering the page specified by pageIndex.
 double getZoom()
          Getter for property zoom.
 boolean isAutoFit()
          Getter for property autoFit.
 boolean isOpaque()
          Returns true if this component is completely opaque.
protected  void paintComponent(java.awt.Graphics graph)
          Invoked by Swing to draw components.
 int print(java.awt.Graphics graphics, java.awt.print.PageFormat pf, int pageIndex)
          throws PrinterExceptionPrints the page at the specified index into the specified Graphics context in the specified format.
 void setAutoFit(boolean autoFit)
          Setter for property autoFit.
 void setComponent(java.awt.Component component)
          Setter for property component.
 void setCurrentPage(int currentPage)
          Setter for property currentPage.
 void setPageFormat(java.awt.print.PageFormat pageFormat)
          Setter for property pageFormat.
 void setZoom(double zoom)
          Setter for property zoom.
private  void updateInternalData()
          update current number of pages and cache of original component image.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, 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, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, 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, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, 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, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, 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, 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, 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, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

component

private java.awt.Component component
Initial awt component to render


pageFormat

private java.awt.print.PageFormat pageFormat
Page format to use


autoFit

private boolean autoFit
flag: make the component fit in page width if needed


keepRatio

private boolean keepRatio
if component is resized; keep its ratio


currentPage

private int currentPage
current index of page to display (starting from 0 like Print API)


numberOfPages

private int numberOfPages
last computed value for this


fitRatio

private double fitRatio
fit ratio


zoom

private double zoom
zoom value


bufferW

private int bufferW
final width for buffer to be in page (same as buffer )


bufferH

private int bufferH
same as


portionH

private int portionH
portion height, same as imageableHeight in one portion


pageWidth

private int pageWidth
width of the page on screen in pixel (could be different as the one in page format) due of zoom


pageHeight

private int pageHeight
Constructor Detail

PrintableComponent

public PrintableComponent(java.awt.Component component,
                          java.awt.print.PageFormat pf,
                          boolean autoFit)

PrintableComponent

public PrintableComponent(java.awt.Component component,
                          java.awt.print.PageFormat pf)
convenient constructor that take autofit value from preferences

Method Detail

print

public int print(java.awt.Graphics graphics,
                 java.awt.print.PageFormat pf,
                 int pageIndex)
throws PrinterExceptionPrints the page at the specified index into the specified Graphics context in the specified format. A PrinterJob calls the Printable interface to request that a page be rendered into the context specified by graphics. The format of the page to be drawn is specified by pageFormat. The zero based index of the requested page is specified by pageIndex. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The Graphics class or subclass implements the PrinterGraphics interface to provide additional information. If the Printable object aborts the print job then it throws a PrinterException. Parameters: graphics - the context into which the page is drawn pageFormat - the size and orientation of the page being drawn pageIndex - the zero based index of the page to be drawn Returns: PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if pageIndex specifies a non-existent page. Throws: PrinterException - thrown when the print job is terminated.

Specified by:
print in interface java.awt.print.Printable

paintComponent

protected void paintComponent(java.awt.Graphics graph)
Invoked by Swing to draw components.


updateInternalData

private void updateInternalData()
update current number of pages and cache of original component image. compute new size of component (width, height) to fit the page. To call each time pageFormat or component changed.


getNumberOfPages

public int getNumberOfPages()
Returns the number of pages in the set. To enable advanced printing features, it is recommended that Pageable implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant.

Specified by:
getNumberOfPages in interface java.awt.print.Pageable

isOpaque

public boolean isOpaque()
Returns true if this component is completely opaque.

An opaque component paints every pixel within its rectangular bounds. A non-opaque component paints only a subset of its pixels or none at all, allowing the pixels underneath it to "show through". Therefore, a component that does not fully paint its pixels provides a degree of transparency.

Subclasses that guarantee to always completely paint their contents should override this method and return true.


getPageFormat

public java.awt.print.PageFormat getPageFormat(int pageIndex)
                                        throws java.lang.IndexOutOfBoundsException
Returns the PageFormat of the page specified by pageIndex.

Specified by:
getPageFormat in interface java.awt.print.Pageable

getPrintable

public java.awt.print.Printable getPrintable(int pageIndex)
                                      throws java.lang.IndexOutOfBoundsException
Returns the Printable instance responsible for rendering the page specified by pageIndex.

Specified by:
getPrintable in interface java.awt.print.Pageable

isAutoFit

public boolean isAutoFit()
Getter for property autoFit.


setAutoFit

public void setAutoFit(boolean autoFit)
Setter for property autoFit.


getPageFormat

public java.awt.print.PageFormat getPageFormat()
Getter for property pageFormat.


setPageFormat

public void setPageFormat(java.awt.print.PageFormat pageFormat)
Setter for property pageFormat.


getComponent

public java.awt.Component getComponent()
Getter for property component.


setComponent

public void setComponent(java.awt.Component component)
Setter for property component.


getCurrentPage

public int getCurrentPage()
Getter for property currentPage.


setCurrentPage

public void setCurrentPage(int currentPage)
Setter for property currentPage.


getZoom

public double getZoom()
Getter for property zoom.


setZoom

public void setZoom(double zoom)
Setter for property zoom.