public class PagePanel extends JPanel
The PagePanel
class is the lowest-level class for rendering a PDFPage
as a JPanel
. At it's most basic it will simply render the page via a PagePainter
,
but when included inside a DocumentViewport
as part of a DocumentPanel
this class may also create subcomponents representing PDFAnnotation
s, as created by the
AnnotationComponentFactory
class.
Before a PagePanel is disposed of it should have 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.
DocumentViewport
,
Serialized FormJPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
PagePanel()
Create a new PagePanel
|
Modifier and Type | Method and Description |
---|---|
void |
addPagePanelInteractionListener(PagePanelInteractionListener listener)
Add a
PagePanelInteractionListener to this PagePanel |
void |
addPagePanelListener(PagePanelListener listener)
Add a
PagePanelListener to this PagePanel |
void |
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 the
DocumentPanel this PagePanel is contained inside, or
null if this PagePanel was not created as part of a
DocumentPanel . |
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 - the
ViewBox |
PDFPage |
getPage()
Return the
PDFPage currently being displayed by this viewport. |
PageExtractor |
getPageExtractor()
Return the
PageExtractor 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 the
DocumentViewport this PagePanel is contained inside, or
null if this PagePanel was not created as part of a
DocumentPanel |
void |
paintComponent(Graphics g) |
void |
redrawAnnotation(PDFAnnotation annot)
Redraw the specified annotation on this page.
|
void |
redrawCurrentPage()
Force a redraw of the current page
|
void |
removePagePanelInteractionListener(PagePanelInteractionListener listener)
Remove a
PagePanelInteractionListener from this PagePanel |
void |
removePagePanelListener(PagePanelListener listener)
Remove a
PagePanelListener from this PagePanel |
void |
setExtractText(boolean extract)
Set whether to extract text while rendering this page to a
PageExtractor |
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 the
PDFParser object which should be used to render the pages. |
void |
setRenderingHints(RenderingHints hints)
Set the
RenderingHints to be used when rendering pages
in this PagePanel. |
void |
setViewport(DocumentViewport viewport)
Set the viewport this PagePanel belongs to
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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
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
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, 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, transferFocusBackward, transferFocusUpCycle
public void setParser(PDFParser parser)
PDFParser
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.parser
- the PDFParserpublic static Rectangle2D getFullPageView(PDFPage page)
ViewBox
PDFPage.getBox(java.lang.String)
,
PDF.getOption(java.lang.String)
public void addPagePanelListener(PagePanelListener listener)
PagePanelListener
to this PagePanelpublic void removePagePanelListener(PagePanelListener listener)
PagePanelListener
from this PagePanelpublic void addPagePanelInteractionListener(PagePanelInteractionListener listener)
PagePanelInteractionListener
to this PagePanelpublic void removePagePanelInteractionListener(PagePanelInteractionListener listener)
PagePanelInteractionListener
from this PagePanelpublic void setRenderingHints(RenderingHints hints)
RenderingHints
to be used when rendering pages
in this PagePanel.hints
- the RenderingHints to use - may be nullpublic void setExtractText(boolean extract)
PageExtractor
extract
- true to extract the text, false otherwisepublic PageExtractor getPageExtractor()
PageExtractor
associated with this PagePanel.
To render and extract text in a single pass, the setExtractText(boolean)
method should be called before rendering, otherwise this method
will run the extraction process in a separate pass.public void setPage(PDFPage page, Rectangle2D position, float dpi)
page
- the page to drawposition
- the area of the page to draw, in pointsdpi
- the resolutionpublic void setPage(PDFPage page, Rectangle2D position, float dpi, Rectangle clip)
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.public void setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi)
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 resolutionpublic void setPage(PDFPage page, float x1, float y1, float x2, float y2, float dpi, Rectangle clip)
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.public void redrawCurrentPage()
public DocumentViewport getViewport()
DocumentViewport
this PagePanel is contained inside, or
null
if this PagePanel was not created as part of a
DocumentPanel
public DocumentPanel getDocumentPanel()
DocumentPanel
this PagePanel is contained inside, or
null
if this PagePanel was not created as part of a
DocumentPanel
. A shortcut for getViewport().getDocumentPanel()
public PDFPage getPage()
public Rectangle2D getClip()
setPage
,
or it may be null
if the PagePanel elected to draw
the entire page instead.public Rectangle2D getView()
public AffineTransform getPageToScreenTransform()
public AffineTransform getScreenToPageTransform()
public float getDPI()
public Point2D getPDFPoint(int x, int y)
getAWTPoint(float, float)
public Point2D getPDFPoint(Point awt)
getAWTPoint(float, float)
public Point getAWTPoint(float x, float y)
getPDFPoint(int, int)
public Point getAWTPoint(Point2D f)
getPDFPoint(int, int)
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public void setViewport(DocumentViewport viewport)
public void redrawAnnotation(PDFAnnotation annot)
IllegalStateException
- if the PagePanel is not part of
a DocumentPanel
and so has no annotations.public void paintComponent(Graphics g)
paintComponent
in class JComponent
Copyright © 2001-2017 Big Faceless Organization