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 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.

  See the viewer tutorial for more detail on how to use this class and the "viewer" package.

  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 and Description
    `PagePanel()` Create a new PagePanel

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    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

    - ### 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, 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`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### PagePanel

          public PagePanel()

      Create a new PagePanel

  - ### Method Detail

    - #### setParser

          public void setParser(PDFParser parser)

      Set the `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.
      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 - the `ViewBox`
      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 a `PagePanelListener` to this PagePanel

    - #### removePagePanelListener

          public void removePagePanelListener(PagePanelListener listener)

      Remove a `PagePanelListener` from this PagePanel

    - #### addPagePanelInteractionListener

          public void addPagePanelInteractionListener(PagePanelInteractionListener listener)

      Add a `PagePanelInteractionListener` to this PagePanel

    - #### removePagePanelInteractionListener

          public void removePagePanelInteractionListener(PagePanelInteractionListener listener)

      Remove a `PagePanelInteractionListener` from this PagePanel

    - #### setRenderingHints

          public void setRenderingHints(RenderingHints hints)

      Set the `RenderingHints` 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 a `PageExtractor`
      Parameters:
        `extract` - true to extract the text, false otherwise

    - #### getPageExtractor

          public PageExtractor getPageExtractor()

      Return the `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.

    - #### 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 draw
        `position` - the area of the page to draw, in points
        `dpi` - 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 draw
        `position` - the area of the page to draw, in points
        `dpi` - the resolution
        `clip` - 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 draw
        `x1` - the left-most X co-ordinate to draw, in points from the bottom-left
        `y1` - the bottom-most Y co-ordinate to draw, in points from the bottom-left
        `x2` - the right-most X co-ordinate to draw, in points from the bottom-left
        `y2` - the top-most Y co-ordinate to draw, in points from the bottom-left
        `dpi` - 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 draw
        `x1` - the left-most X co-ordinate to draw, in points from the bottom-left
        `y1` - the bottom-most Y co-ordinate to draw, in points from the bottom-left
        `x2` - the right-most X co-ordinate to draw, in points from the bottom-left
        `y2` - the top-most Y co-ordinate to draw, in points from the bottom-left
        `dpi` - the resolution
        `clip` - 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 the `DocumentViewport` this PagePanel is contained inside, or `null` if this PagePanel was not created as part of a `DocumentPanel`

    - #### getDocumentPanel

          public DocumentPanel getDocumentPanel()

      Get the `DocumentPanel` this PagePanel is contained inside, or `null` if this PagePanel was not created as part of a `DocumentPanel`. A shortcut for `getViewport().getDocumentPanel()`

    - #### getPage

          public PDFPage getPage()

      Return the `PDFPage` currently being displayed by this viewport. Note this method returns the page being displayed, not the page currently being rendered, so it's value will not immediately reflect the page passed in to `setPage()`, and will be `null` if the first page has not yet finished rendering.

    - #### getClip

          public Rectangle2D getClip()

      Return the clip area actually used by the PagePanel. This may be what was requested by the last call to `setPage`, or it may be `null` if the PagePanel elected to draw the entire page instead.
      Since:
        2.11.25

    - #### getView

          public Rectangle2D getView()

      Returns the area of the page currently being displayed, in points with (0,0) at the bottom-left. Like `getPage()` the return value of this method will not immediately reflect the position passed in to `setPage()`, and will be `null` if the first page has not yet finished rendering.

    - #### 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()

      Return the resolution of the page currently being displayed. Like `getPage()` the return value of this method will not immediately reflect the position passed in to `setPage()`, and will be 0 if the fist page has not yet finished rendering.

    - #### 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 class `JComponent`

    - #### setViewport

          public void setViewport(DocumentViewport viewport)

      Set the viewport this PagePanel belongs to
      Since:
        2.11

    - #### doLayout

          public void doLayout()

      Overrides:
        `doLayout` in class `Container`

    - #### 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 a `DocumentPanel` and so has no annotations.

    - #### paintComponent

          public void paintComponent(Graphics g)

      Overrides:
        `paintComponent` in class `JComponent`

Copyright © 2001-2015 Big Faceless Organization