public class SinglePageDocumentViewport extends DocumentViewport
DocumentViewport
that displays a single page. The Page can be zoomed
in or out, and if it grows beyond the size of this viewport scrollbars will be displayed.
Zoom levels are translated to DPI (as required by the PagePainter) using the
Toolkit.getScreenResolution()
method.
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.
DocumentPanel
,
Serialized FormJPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
CURSOR_GRAB, CURSOR_GRABBING, interpagemargin, margin, mouseWheelUnit, ZOOM_FIT, ZOOM_FITHEIGHT, ZOOM_FITWIDTH, ZOOM_NONE
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 |
---|
SinglePageDocumentViewport()
Create a new SinglePageDocumentViewport
|
Modifier and Type | Method and Description |
---|---|
void |
addPagePanelInteractionListener(PagePanelInteractionListener listener)
Add a
PagePanelInteractionListener to any PagePanel objects that have been
or will be created by this DocumentViewport |
void |
addPagePanelListener(PagePanelListener listener)
Add a
PagePanelListener to any PagePanel objects that have been
or will be created by this DocumentViewport |
void |
ensureVisible(PDFPage page,
double x,
double y)
Ensure the specified point on the page is visible.
|
Adjustable |
getAdjustable(int position)
Return the "Adjustable" object for the specified position - typically this
is the horizontal or vertical
JScrollBar , although this method may
return null or accept other parameters. |
PagePanel |
getPagePanel()
Get the currently displayed PagePanel.
|
Collection<PagePanel> |
getPagePanels()
Returns a read only Collection containing all the PagePanels currently
displayed in this Viewport.
|
PDFPage |
getRenderingPage()
Return the page that is currently in the process of rendering.
|
float |
getTargetZoom(int zoommode,
PDFPage page)
Return the appropriate zoom level when switching to the specified page.
|
JComponent |
getView()
Get the JComponent that directly contains the PagePanel objects, not including
scrollbars or other similar items.
|
Dimension |
getViewportSize()
Return the size in pixels of the space available to display pages in this viewport,
not including scrollbars or other decoration
|
float |
getZoom()
Get the current zoom level
|
boolean |
isDraggable()
Indicates whether the contents of this viewport can be dragged with
the mouse to position them.
|
boolean |
isPageVisible(PDFPage page,
double x,
double y)
Indicates whether the specified point in the specified page is
visible in the viewport.
|
void |
propertyChange(PropertyChangeEvent event)
The viewport implements PropertyChangeListener, and will be called
whenever the PDF has been updated.
|
void |
removePagePanelInteractionListener(PagePanelInteractionListener listener)
Remove a
PagePanelInteractionListener from any PagePanel objects
that have been created by this DocumentViewport |
void |
removePagePanelListener(PagePanelListener listener)
Remove a
PagePanelListener from any PagePanel objects that have been
created by this DocumentViewport |
void |
setAdjustableValues(int horizontal,
int vertical)
Set the values of the adjustables returned by
DocumentViewport.getAdjustable(int) . |
void |
setDocumentPanel(DocumentPanel panel)
Set the DocumentPanel that contains this DocumentViewport.
|
void |
setDraggable(boolean draggable)
Sets whether to allow the contents of this viewport to be dragged
with the mouse.
|
void |
setPage(PDFPage page,
double x,
double y,
double zoom)
Set the currently displayed page.
|
void |
setRenderingHints(RenderingHints hints)
Set the
RenderingHints that should be used when rendering the pages |
void |
setZoom(float zoom)
Set the zoom level of this DocumentViewport.
|
void |
setZoomMode(int zoommode)
Control how the document in the viewport is redrawn when the Viewport is resized.
|
getBorderColor, getDefaultRenderingHints, getDocumentPanel, getNextSelectablePageIndex, getPage, getPreviousSelectablePageIndex, getShadowColor, getZoomMode, isSmoothScrolling, paintPageBorder, smoothScroll
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, getPreferredSize, 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, paintComponent, 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, 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, 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 SinglePageDocumentViewport()
public void setDocumentPanel(DocumentPanel panel)
DocumentViewport
super.setDocumentPanel(panel)
setDocumentPanel
in class DocumentViewport
public boolean isDraggable()
DocumentViewport
isDraggable
in class DocumentViewport
public void setDraggable(boolean draggable)
DocumentViewport
setDraggable
in class DocumentViewport
draggable
- if true, contents may be draggedpublic void setPage(PDFPage page, double x, double y, double zoom)
DocumentViewport
setPage
in class DocumentViewport
page
- the page to displayx
- the left-most X position of the page, relative to PagePanel.getFullPageView(org.faceless.pdf2.PDFPage)
. A value of NaN means keep the current value. 0 means the left edgey
- the top-most Y position of the page, relative to PagePanel.getFullPageView(org.faceless.pdf2.PDFPage)
. A value of NaN means keep the current value. 0 means the top edgezoom
- the zoom level. A value of <= 0 or NaN means keep the current zoom. A value of one means 72dpipublic void ensureVisible(PDFPage page, double x, double y)
DocumentViewport
ensureVisible
in class DocumentViewport
x
- the X position of the page in absolute PDF points (ie measured from the bottom left)y
- the Y position of the page in absolute PDF points (ie measured from the bottom left)public boolean isPageVisible(PDFPage page, double x, double y)
DocumentViewport
x
or y
is
NaN
, indicates whether any part of the page is visible.isPageVisible
in class DocumentViewport
x
- the X position of the page in pointsy
- the Y position of the page in pointspublic JComponent getView()
DocumentViewport
getView
in class DocumentViewport
public float getZoom()
DocumentViewport
getZoom
in class DocumentViewport
public void setZoom(float zoom)
DocumentViewport
setZoom
in class DocumentViewport
public Dimension getViewportSize()
DocumentViewport
getViewportSize
in class DocumentViewport
public PagePanel getPagePanel()
DocumentViewport
setPage()
, the exact
implementation of this method depends on the type of viewport, but the idea is
it returns the PagePanel that is the primary focus of this viewport.getPagePanel
in class DocumentViewport
public Collection<PagePanel> getPagePanels()
DocumentViewport
getPagePanels
in class DocumentViewport
public PDFPage getRenderingPage()
DocumentViewport
DocumentViewport.getPage()
getRenderingPage
in class DocumentViewport
public Adjustable getAdjustable(int position)
DocumentViewport
JScrollBar
, although this method may
return null
or accept other parameters. The adjustable is
measured in AWT space (pixels from the top left). This method may return
null if there is no adjustable.getAdjustable
in class DocumentViewport
position
- one of Adjustable.HORIZONTAL
or Adjustable.VERTICAL
public void setAdjustableValues(int horizontal, int vertical)
DocumentViewport
DocumentViewport.getAdjustable(int)
.
Calling this method is preferable to setting the values of each adjustable
individually when both are to be setsetAdjustableValues
in class DocumentViewport
horizontal
- the value for the Adjustable.HORIZONTAL
adjustable.vertical
- the value for the Adjustable.VERTICAL
adjustable.public void setRenderingHints(RenderingHints hints)
DocumentViewport
RenderingHints
that should be used when rendering the pagessetRenderingHints
in class DocumentViewport
public void addPagePanelListener(PagePanelListener listener)
DocumentViewport
PagePanelListener
to any PagePanel
objects that have been
or will be created by this DocumentViewportaddPagePanelListener
in class DocumentViewport
listener
- the listenerpublic void removePagePanelListener(PagePanelListener listener)
DocumentViewport
PagePanelListener
from any PagePanel
objects that have been
created by this DocumentViewportremovePagePanelListener
in class DocumentViewport
listener
- the listenerpublic void addPagePanelInteractionListener(PagePanelInteractionListener listener)
DocumentViewport
PagePanelInteractionListener
to any PagePanel
objects that have been
or will be created by this DocumentViewportaddPagePanelInteractionListener
in class DocumentViewport
listener
- the listenerpublic void removePagePanelInteractionListener(PagePanelInteractionListener listener)
DocumentViewport
PagePanelInteractionListener
from any PagePanel
objects
that have been created by this DocumentViewportremovePagePanelInteractionListener
in class DocumentViewport
listener
- the listenerpublic void setZoomMode(int zoommode)
DocumentViewport
DocumentViewport.ZOOM_NONE
, which means no action is performed, but other
actions include DocumentViewport.ZOOM_FIT
, DocumentViewport.ZOOM_FITWIDTH
and DocumentViewport.ZOOM_FITHEIGHT
,
which will ensure that the document is always zoomed to fit completely, fit the width
or fit the height of the viewport respectivelysetZoomMode
in class DocumentViewport
public float getTargetZoom(int zoommode, PDFPage page)
DocumentViewport
zoommode
is DocumentViewport.ZOOM_NONE
then this
just returns the value of DocumentViewport.getZoom()
, otherwise the returned zoom level
will correctly fit the page to the Viewport.getTargetZoom
in class DocumentViewport
page
- the PDFPage that we are calculating the zoom for.DocumentViewport.getZoomMode()
public void propertyChange(PropertyChangeEvent event)
DocumentViewport
propertyChange
in interface PropertyChangeListener
propertyChange
in class DocumentViewport
Copyright © 2001-2017 Big Faceless Organization