Copyright 2012-02-25 Werner Randelshofer

ch.randelshofer.pdf
Class JPDFPagePanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by ch.randelshofer.pdf.JPDFPagePanel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable

public class JPDFPagePanel
extends javax.swing.JPanel
implements javax.swing.Scrollable

A Swing-based panel that displays a single PDF page.

Version:
2.2.1 2010-03-25 Werner Randelshofer paintComponents crashed when the Graphics object returned null for the rendering hints map.
2.2 2010-01-29 Werner Randelshofer Enable/Disable subpixel antialiasing.
2.1 2009-11-28 Werner Randelshofer Added support for subpixel antialiasing.
2.0 2008-09-18 Werner Randelshofer Reworked for use in an applet.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static java.lang.String PAGE_PROPERTY
          Name of the "page" property.
static java.lang.String PREFERRED_ZOOM_FACTOR_PROPERTY
          Name of the "preferredZoomFactor" property.
static java.lang.String ZOOM_FACTOR_PROPERTY
          Name of the "zoomFactor" property.
 
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
JPDFPagePanel()
          Create a new PagePanel, with a default size of 800 by 600 pixels.
 
Method Summary
 void addOpenURIListener(OpenURIListener pl)
          Adds a PageChangeListener to receive notification of page clicks.
 void addPageChangeListener(PageChangeListener pl)
          Adds a PageChangeListener to receive notification of page clicks.
 java.awt.geom.Rectangle2D.Float getClipRect()
           
 com.sun.pdfview.annotation.LinkAnnotation getLinkAt(java.awt.Point point)
           
 com.sun.pdfview.PDFPage getPage()
          Gets the page currently being displayed
 java.awt.Dimension getPreferredScrollableViewportSize()
           
 double getPreferredZoomFactor()
          Gets the preferred zoom factor from device space to page space.
 int getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
           
 boolean getScrollableTracksViewportHeight()
           
 boolean getScrollableTracksViewportWidth()
           
 int getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)
           
 java.awt.Rectangle getViewRect()
           
 double getZoomFactor()
          Gets the current zoom factor from device space to page space.
 boolean isSubpixAAEnabled()
           
 java.awt.Point pageToView(java.awt.geom.Point2D.Float p)
          Converts a point in view coordinates to page coordinates.
 void paintComponent(java.awt.Graphics gr)
          Draw the renderedImage.
 void removeOpenURIListener(OpenURIListener pl)
          Removes a PageChangeListener from the notification list.
 void removePageChangeListener(PageChangeListener pl)
          Removes a PageChangeListener from the notification list.
 void scrollPageRectToVisible(java.awt.geom.Rectangle2D.Float r)
           
 void setPage(com.sun.pdfview.PDFPage newValue)
           
 void setPreferredZoomFactor(double newValue)
           
 void setSubpixAAEnabled(boolean newValue)
           
protected  void stopRendering()
           
 void updatePreferredSize()
           
 java.awt.geom.Point2D.Float viewToPage(java.awt.Point p)
          Converts a point in view coordinates to page coordinates.
 void waitForCurrentPage()
          Waits until the page is either complete or had an error.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
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, 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

PREFERRED_ZOOM_FACTOR_PROPERTY

public static final java.lang.String PREFERRED_ZOOM_FACTOR_PROPERTY
Name of the "preferredZoomFactor" property.

See Also:
Constant Field Values

ZOOM_FACTOR_PROPERTY

public static final java.lang.String ZOOM_FACTOR_PROPERTY
Name of the "zoomFactor" property.

See Also:
Constant Field Values

PAGE_PROPERTY

public static final java.lang.String PAGE_PROPERTY
Name of the "page" property.

See Also:
Constant Field Values
Constructor Detail

JPDFPagePanel

public JPDFPagePanel()
Create a new PagePanel, with a default size of 800 by 600 pixels.

Method Detail

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize()
Specified by:
getPreferredScrollableViewportSize in interface javax.swing.Scrollable

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Rectangle visibleRect,
                                      int orientation,
                                      int direction)
Specified by:
getScrollableUnitIncrement in interface javax.swing.Scrollable

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Rectangle visibleRect,
                                       int orientation,
                                       int direction)
Specified by:
getScrollableBlockIncrement in interface javax.swing.Scrollable

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth()
Specified by:
getScrollableTracksViewportWidth in interface javax.swing.Scrollable

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight()
Specified by:
getScrollableTracksViewportHeight in interface javax.swing.Scrollable

stopRendering

protected void stopRendering()

setPage

public void setPage(com.sun.pdfview.PDFPage newValue)

getPage

public com.sun.pdfview.PDFPage getPage()
Gets the page currently being displayed


setSubpixAAEnabled

public void setSubpixAAEnabled(boolean newValue)

isSubpixAAEnabled

public boolean isSubpixAAEnabled()

paintComponent

public void paintComponent(java.awt.Graphics gr)
Draw the renderedImage.

Overrides:
paintComponent in class javax.swing.JComponent

getPreferredZoomFactor

public double getPreferredZoomFactor()
Gets the preferred zoom factor from device space to page space.


setPreferredZoomFactor

public void setPreferredZoomFactor(double newValue)

getZoomFactor

public double getZoomFactor()
Gets the current zoom factor from device space to page space.


waitForCurrentPage

public void waitForCurrentPage()
Waits until the page is either complete or had an error.


getViewRect

public java.awt.Rectangle getViewRect()

getClipRect

public java.awt.geom.Rectangle2D.Float getClipRect()

updatePreferredSize

public void updatePreferredSize()

viewToPage

public java.awt.geom.Point2D.Float viewToPage(java.awt.Point p)
Converts a point in view coordinates to page coordinates.


pageToView

public java.awt.Point pageToView(java.awt.geom.Point2D.Float p)
Converts a point in view coordinates to page coordinates.


getLinkAt

public com.sun.pdfview.annotation.LinkAnnotation getLinkAt(java.awt.Point point)

addPageChangeListener

public void addPageChangeListener(PageChangeListener pl)
Adds a PageChangeListener to receive notification of page clicks.


removePageChangeListener

public void removePageChangeListener(PageChangeListener pl)
Removes a PageChangeListener from the notification list.


addOpenURIListener

public void addOpenURIListener(OpenURIListener pl)
Adds a PageChangeListener to receive notification of page clicks.


removeOpenURIListener

public void removeOpenURIListener(OpenURIListener pl)
Removes a PageChangeListener from the notification list.


scrollPageRectToVisible

public void scrollPageRectToVisible(java.awt.geom.Rectangle2D.Float r)

Copyright 2012-02-25 Werner Randelshofer