Package org.faceless.pdf2.viewer2
Class PagePanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- org.faceless.pdf2.viewer2.PagePanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
public class PagePanel extends JPanel
The
PagePanel
class is the lowest-level class for rendering aPDFPage
as aJPanel
. At it's most basic it will simply render the page via aPagePainter
, but when included inside aDocumentViewport
as part of aDocumentPanel
this class may also create subcomponents representingPDFAnnotation
s, as created by theAnnotationComponentFactory
class.Before a PagePanel is disposed of it should have
See the viewer tutorial for more detail on how to use this class and the "viewer" package.setParser(null)
called on it.This code is copyright the Big Faceless Organization. You're welcome to use, modify and distribute it in any form in your own projects, provided those projects continue to make use of the Big Faceless PDF library.
- Since:
- 2.8
- See Also:
DocumentViewport
, Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
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
-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
Constructors Constructor Description PagePanel()
Create a new PagePanel
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPagePanelInteractionListener(PagePanelInteractionListener listener)
Add aPagePanelInteractionListener
to this PagePanelvoid
addPagePanelListener(PagePanelListener listener)
Add aPagePanelListener
to this PagePanelvoid
doLayout()
Point
getAWTPoint(float x, float y)
Given a location on the page in points, return the equivalent position on this PagePanel in pixels.Point
getAWTPoint(Point2D f)
Given a location on the page in points, return the equivalent position on this PagePanel in pixels.Rectangle2D
getClip()
Return the clip area actually used by the PagePanel.DocumentPanel
getDocumentPanel()
Get theDocumentPanel
this PagePanel is contained inside, ornull
if this PagePanel was not created as part of aDocumentPanel
.float
getDPI()
Return the resolution of the page currently being displayed.static Rectangle2D
getFullPageView(PDFPage page)
Return the area of the page that is considered to be the "whole page" as far as the viewer is concerned - theViewBox
PDFPage
getPage()
Return thePDFPage
currently being displayed by this viewport.PageExtractor
getPageExtractor()
Return thePageExtractor
associated with this PagePanel.AffineTransform
getPageToScreenTransform()
Return an AffineTransform that will map Page co-ordinates to Screen co-ordinates.Point2D
getPDFPoint(int x, int y)
Given a location on this panel in pixels, return the equivalent position on the current page in points.Point2D
getPDFPoint(Point awt)
Given a location on this panel in pixels, return the equivalent position on the current page in points.Dimension
getPreferredSize()
AffineTransform
getScreenToPageTransform()
Return an AffineTransform that will map Page co-ordinates to Screen co-ordinates.Rectangle2D
getView()
Returns the area of the page currently being displayed, in points with (0,0) at the bottom-left.DocumentViewport
getViewport()
Get theDocumentViewport
this PagePanel is contained inside, ornull
if this PagePanel was not created as part of aDocumentPanel
void
paintComponent(Graphics g)
void
redrawAnnotation(PDFAnnotation annot)
Redraw the specified annotation on this page.void
redrawCurrentPage()
Force a redraw of the current pagevoid
removePagePanelInteractionListener(PagePanelInteractionListener listener)
Remove aPagePanelInteractionListener
from this PagePanelvoid
removePagePanelListener(PagePanelListener listener)
Remove aPagePanelListener
from this PagePanelvoid
setExtractText(boolean extract)
Set whether to extract text while rendering this page to aPageExtractor
void
setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi)
Redraw the page.void
setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi, Rectangle clip)
Redraw the page.void
setPage(PDFPage page, Rectangle2D position, float dpi)
Redraw the page.void
setPage(PDFPage page, Rectangle2D position, float dpi, Rectangle clip)
Redraw the page.void
setParser(PDFParser parser)
Set thePDFParser
object which should be used to render the pages.void
setRenderingHints(RenderingHints hints)
Set theRenderingHints
to be used when rendering pages in this PagePanel.void
setViewport(DocumentViewport viewport)
Set the viewport this PagePanel belongs to-
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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Method Detail
-
setParser
public void setParser(PDFParser parser)
Set thePDFParser
object which should be used to render the pages. Setting this to null will end the background thread that renders this object, and free any related resources.- Parameters:
parser
- the PDFParser
-
getFullPageView
public static Rectangle2D getFullPageView(PDFPage page)
Return the area of the page that is considered to be the "whole page" as far as the viewer is concerned - theViewBox
- Returns:
- the area of the page that's the full page, in points
- See Also:
PDFPage.getBox(java.lang.String)
,PDF.getOption(java.lang.String)
-
addPagePanelListener
public void addPagePanelListener(PagePanelListener listener)
Add aPagePanelListener
to this PagePanel
-
removePagePanelListener
public void removePagePanelListener(PagePanelListener listener)
Remove aPagePanelListener
from this PagePanel
-
addPagePanelInteractionListener
public void addPagePanelInteractionListener(PagePanelInteractionListener listener)
Add aPagePanelInteractionListener
to this PagePanel
-
removePagePanelInteractionListener
public void removePagePanelInteractionListener(PagePanelInteractionListener listener)
Remove aPagePanelInteractionListener
from this PagePanel
-
setRenderingHints
public void setRenderingHints(RenderingHints hints)
Set theRenderingHints
to be used when rendering pages in this PagePanel.- Parameters:
hints
- the RenderingHints to use - may be null
-
setExtractText
public void setExtractText(boolean extract)
Set whether to extract text while rendering this page to aPageExtractor
- Parameters:
extract
- true to extract the text, false otherwise
-
getPageExtractor
public PageExtractor getPageExtractor()
Return thePageExtractor
associated with this PagePanel. To render and extract text in a single pass, thesetExtractText(boolean)
method should be called before rendering, otherwise this method will run the extraction process in a separate pass.
-
setPage
public void setPage(PDFPage page, Rectangle2D position, float dpi)
Redraw the page. The page will be rerendered in the background and when it's complete this component will be resized and repainted. If annotations are being created they will be repositioned and redrawn as well. This method may be called from any thread. Note since 2.11.26, the page must be the same as any page passed into previous calls to this method.- Parameters:
page
- the page to drawposition
- the area of the page to draw, in pointsdpi
- the resolution
-
setPage
public void setPage(PDFPage page, Rectangle2D position, float dpi, Rectangle clip)
Redraw the page. The page will be rerendered in the background and when it's complete this component will be resized and repainted. If annotations are being created they will be repositioned and redrawn as well. This method may be called from any thread. Note since 2.11.26, the page must be the same as any page passed into previous calls to this method.- Parameters:
page
- the page to drawposition
- the area of the page to draw, in pointsdpi
- the resolutionclip
- The graphics clip for this panel, in pixels. The panel will not not render any of the page outside this rectangle.- Since:
- 2.10.4
-
setPage
public void setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi)
Redraw the page. The page will be rerendered in the background and when it's complete this component will be resized and repainted. If annotations are being created they will be repositioned and redrawn as well. This method may be called from any thread. Note since 2.11.26, the page must be the same as any page passed into previous calls to this method.- Parameters:
page
- the page to drawx1
- the left-most X co-ordinate to draw, in points from the bottom-lefty1
- the bottom-most Y co-ordinate to draw, in points from the bottom-leftx2
- the right-most X co-ordinate to draw, in points from the bottom-lefty2
- the top-most Y co-ordinate to draw, in points from the bottom-leftdpi
- the resolution
-
setPage
public void setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi, Rectangle clip)
Redraw the page. The page will be rerendered in the background and when it's complete this component will be resized and repainted. If annotations are being created they will be repositioned and redrawn as well. This method may be called from any thread. Note since 2.11.26, the page must be the same as any page passed into previous calls to this method.- Parameters:
page
- the page to drawx1
- the left-most X co-ordinate to draw, in points from the bottom-lefty1
- the bottom-most Y co-ordinate to draw, in points from the bottom-leftx2
- the right-most X co-ordinate to draw, in points from the bottom-lefty2
- the top-most Y co-ordinate to draw, in points from the bottom-leftdpi
- the resolutionclip
- the graphics clip for this panel in pixels. The panel will not render any of the page outside this rectangle.- Since:
- 2.10.4
-
redrawCurrentPage
public void redrawCurrentPage()
Force a redraw of the current page- Since:
- 2.11.7
-
getViewport
public DocumentViewport getViewport()
Get theDocumentViewport
this PagePanel is contained inside, ornull
if this PagePanel was not created as part of aDocumentPanel
-
getDocumentPanel
public DocumentPanel getDocumentPanel()
Get theDocumentPanel
this PagePanel is contained inside, ornull
if this PagePanel was not created as part of aDocumentPanel
. A shortcut forgetViewport().getDocumentPanel()
-
getPage
public PDFPage getPage()
-
getClip
public Rectangle2D getClip()
Return the clip area actually used by the PagePanel. This may be what was requested by the last call tosetPage
, or it may benull
if the PagePanel elected to draw the entire page instead.- Since:
- 2.11.25
-
getView
public Rectangle2D getView()
-
getPageToScreenTransform
public AffineTransform getPageToScreenTransform()
Return an AffineTransform that will map Page co-ordinates to Screen co-ordinates.- Since:
- 2.10.2
-
getScreenToPageTransform
public AffineTransform getScreenToPageTransform()
Return an AffineTransform that will map Page co-ordinates to Screen co-ordinates.- Since:
- 2.10.3
-
getDPI
public float getDPI()
-
getPDFPoint
public Point2D getPDFPoint(int x, int y)
Given a location on this panel in pixels, return the equivalent position on the current page in points.- See Also:
getAWTPoint(float, float)
-
getPDFPoint
public Point2D getPDFPoint(Point awt)
Given a location on this panel in pixels, return the equivalent position on the current page in points.- See Also:
getAWTPoint(float, float)
-
getAWTPoint
public Point getAWTPoint(float x, float y)
Given a location on the page in points, return the equivalent position on this PagePanel in pixels.- See Also:
getPDFPoint(int, int)
-
getAWTPoint
public Point getAWTPoint(Point2D f)
Given a location on the page in points, return the equivalent position on this PagePanel in pixels.- See Also:
getPDFPoint(int, int)
-
getPreferredSize
public Dimension getPreferredSize()
- Overrides:
getPreferredSize
in classJComponent
-
setViewport
public void setViewport(DocumentViewport viewport)
Set the viewport this PagePanel belongs to- Since:
- 2.11
-
redrawAnnotation
public void redrawAnnotation(PDFAnnotation annot)
Redraw the specified annotation on this page. This should be called if the annotation is changed, if it's newly added to the page or if it's been removed from the page. May be called from any thread.- Throws:
IllegalStateException
- if the PagePanel is not part of aDocumentPanel
and so has no annotations.
-
paintComponent
public void paintComponent(Graphics g)
- Overrides:
paintComponent
in classJComponent
-
-