org.faceless.pdf2.viewer2
Class DocumentPanel

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 org.faceless.pdf2.viewer2.DocumentPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class DocumentPanel
extends JPanel

A DocumentPanel is the basic component that displays a PDF, and may be instantiated on it's own or as part of a PDFViewer. It contains a DocumentViewport and optionally one or more SidePanel objects on the left, and may process PDFActions on the PDF. See the viewer tutorial for more detail on how to use this class and the "viewer" package.

The following initialization parameters may be specified
defaultViewportThe class name of the default viewport to use if not specified in the PDF. May be SinglePageDocumentViewport, MultiPageDocumentVieport or a fully-qualified class name of another DocumentViewport
useNamedSidePanelstrue or false (the default) - whether to show names on the side panel tabs rather than icons.

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:
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
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
DocumentPanel()
          Create a new DocumentPanel
 
Method Summary
 void addActionHandler(ActionHandler actionhandler)
          Add a ActionHandler to this DocumentPanel.
 void addAnnotationComponentFactory(AnnotationComponentFactory annotationfactory)
          Add a AnnotationComponentFactory to this DocumentPanel.
 void addDocumentPanelListener(DocumentPanelListener listener)
          Add a DocumentPanelListener to this DocumentPanel.
 void addSidePanel(SidePanel panel)
          Add the specified sidepanel to the DocumentPanel
 void addSidePanelFactory(SidePanelFactory panelfactory)
          Add a SidePanelFactory to this DocumentPanel.
 JSManager getJSManager()
          Return the JSManager object for this DocumentPanel.
 PDFPage getPage()
          Return the PDFPage currently being displayed by the DocumentViewport.
 int getPageNumber()
          Return the pagenumber of the currently displayed page starting at 0, or -1 if no page is being displayed.
 PDFParser getParser()
          Get the PDFParser being used to parse this PDF.
 PDF getPDF()
          Return the PDF currently being displayed by this DocumentPanel
 SidePanel getSelectedSidePanel()
          Return the currently selected SidePanel, or null if no panels are displayed.
 Collection getSidePanels()
          Return a read-only collection containing the SidePanel objects in use by this DocumentPanel.
 PDFViewer getViewer()
          Return the PDFViewer that contains this DocumentPanel.
 DocumentViewport getViewport()
          Return the DocumentViewport contained by this DocumentPanel
 float getZoom()
          Return the current zoom level.
 void print(PrintService fservice, PrintRequestAttributeSet fatts)
          Display a Print dialog for printing this document, or if a PrintService is specified, print directly to that service without displaying a dialog.
 void redraw(Object o)
          Redraw the specified object.
 void removeDocumentPanelListener(DocumentPanelListener listener)
          Remove a DocumentPanelListener from this DocumentPanel.
 void removeSidePanel(SidePanel panel)
          Remove the specified SidePanel from the DocumentPanel.
 boolean runAction(PDFAction action)
          Run the specified action on the PDF.
 void setJSManager(JSManager jsmanager)
          Set the JSManager object for this DocumentPanel.
 void setPage(PDFPage page)
          Set the page to display in the DocumentViewport.
 void setPage(PDFPage page, float x, float y, float zoom)
          Set the page to display in the DocumentViewport.
 void setPageNumber(int i)
          Set the page being displayed.
 void setPDF(PDF pdf)
          Set the PDF to be displayed by this DocumentPanel.
 void setPDF(PDFParser parser, PDFPage page)
          Set the PDF to be displayed by this DocumentPanel, and specify the initial page to display and the exact PDFParser to use.
 void setPDF(PDF pdf, PDFPage page)
          Set the PDF to be displayed by this DocumentPanel, and specify the initial page to display.
 void setSelectedSidePanel(SidePanel panel)
          Set the currently displayed SidePanel
 void setSidePanelSize(int threshold, int preferred)
          Control the size of the leftmost pane.
 void setViewport(DocumentViewport viewport)
          Set the DocumentViewport used by this DocumentPanel.
 void setZoom(float zoom)
          Set the current zoom level
 
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, 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
 
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
 

Constructor Detail

DocumentPanel

public DocumentPanel()
Create a new DocumentPanel

Method Detail

setViewport

public void setViewport(DocumentViewport viewport)
Set the DocumentViewport used by this DocumentPanel.

Parameters:
viewport - the Viewport

getViewport

public DocumentViewport getViewport()
Return the DocumentViewport contained by this DocumentPanel


getJSManager

public JSManager getJSManager()
Return the JSManager object for this DocumentPanel.

Since:
2.9

setJSManager

public void setJSManager(JSManager jsmanager)
Set the JSManager object for this DocumentPanel. This method should only be called if multiple DocumentPanel object are used in the same non-PDFViewer container.

Since:
2.9

getViewer

public PDFViewer getViewer()
Return the PDFViewer that contains this DocumentPanel. Note a DocumentPanel does not have to be contained inside a PDFViewer, in which case this method will return null.


setSidePanelSize

public void setSidePanelSize(int threshold,
                             int preferred)
Control the size of the leftmost pane. The two values specify the threshold below which the pane is considered to be closed, and the default size of the pane when it's opened.

Parameters:
threshold - the minimum size, below which the panel is assumed to be closed
preferred - the default size of the leftmost pane when opened

addSidePanelFactory

public void addSidePanelFactory(SidePanelFactory panelfactory)
Add a SidePanelFactory to this DocumentPanel. When a PDF is set, the panels that are appropriate for that PDF will be created from this list of factories.

Parameters:
panelfactory - the factory

addAnnotationComponentFactory

public void addAnnotationComponentFactory(AnnotationComponentFactory annotationfactory)
Add a AnnotationComponentFactory to this DocumentPanel. Any PDF's displayed by this panel will have annotations created by these factories.

Parameters:
annotationfactory - the factory

addActionHandler

public void addActionHandler(ActionHandler actionhandler)
Add a ActionHandler to this DocumentPanel. Any actions passed to runAction(org.faceless.pdf2.PDFAction) will by handled by this list of handlers.

Parameters:
actionhandler - the handler

runAction

public boolean runAction(PDFAction action)
Run the specified action on the PDF. Actions are handled by ActionHandlers, which should be registered with this class via the addActionHandler() method.

Parameters:
action - the PDFAction to run.
Returns:
true if the action was recognised and run successfully, false otherwise.

addDocumentPanelListener

public void addDocumentPanelListener(DocumentPanelListener listener)
Add a DocumentPanelListener to this DocumentPanel.

Parameters:
listener - the listener

removeDocumentPanelListener

public void removeDocumentPanelListener(DocumentPanelListener listener)
Remove a DocumentPanelListener from this DocumentPanel.

Parameters:
listener - the listener

getSidePanels

public Collection getSidePanels()
Return a read-only collection containing the SidePanel objects in use by this DocumentPanel.

Since:
2.10.3 (prior to this release a Map was returned instead)

removeSidePanel

public void removeSidePanel(SidePanel panel)
Remove the specified SidePanel from the DocumentPanel.

Since:
2.10.3

addSidePanel

public void addSidePanel(SidePanel panel)
Add the specified sidepanel to the DocumentPanel

Since:
2.10.3

setSelectedSidePanel

public void setSelectedSidePanel(SidePanel panel)
Set the currently displayed SidePanel

Parameters:
panel - the SidePanel to display.
Since:
2.10.3 (prior to this release the name of the panel was specified instead)

getSelectedSidePanel

public SidePanel getSelectedSidePanel()
Return the currently selected SidePanel, or null if no panels are displayed.

Since:
2.10.3 (prior to this release the name of the panel was returned instead)

setPDF

public void setPDF(PDF pdf)
Set the PDF to be displayed by this DocumentPanel. A value of null will remove the current PDF from this object and free any resources that reference it - this should be done before this object is disposed of.

Parameters:
pdf - the PDF, or null to remove the current PDF

setPDF

public void setPDF(PDF pdf,
                   PDFPage page)
Set the PDF to be displayed by this DocumentPanel, and specify the initial page to display.

Parameters:
pdf - the PDF, or null to remove the current PDF
page - the initial page to display, or null to not display an initial page (exactly how this is handled depends on the Viewport). This will be ignored if the DocumentPanel is part of a PDFViewer and the PDF has an open action that sets the page.
Since:
2.11

setPDF

public void setPDF(PDFParser parser,
                   PDFPage page)
Set the PDF to be displayed by this DocumentPanel, and specify the initial page to display and the exact PDFParser to use.

Parameters:
parser - the PDFParser to use to retrieve the PDF from
page - the initial page to display, or null to not display an initial page (exactly how this is handled depends on the Viewport). This will be ignored if the DocumentPanel is part of a PDFViewer and the PDF has an open action that sets the page.
Since:
2.11.3

getParser

public PDFParser getParser()
Get the PDFParser being used to parse this PDF.


getPDF

public PDF getPDF()
Return the PDF currently being displayed by this DocumentPanel


getPage

public PDFPage getPage()
Return the PDFPage currently being displayed by the DocumentViewport. If no PDF is set or the first page is still being rendered, this method will return null.


setPageNumber

public void setPageNumber(int i)
Set the page being displayed. A shortcut for setPage(getPDF().getPage(i)).


getPageNumber

public int getPageNumber()
Return the pagenumber of the currently displayed page starting at 0, or -1 if no page is being displayed.


getZoom

public float getZoom()
Return the current zoom level. A value of 1 means the document is being displayed at it's actual size, 0.5 means 50% and so on.


setZoom

public void setZoom(float zoom)
Set the current zoom level

Parameters:
zoom - the zoom level

setPage

public void setPage(PDFPage page)
Set the page to display in the DocumentViewport. The page is displayed at it's top-left and at the current zoom level.

Parameters:
page - the page

setPage

public void setPage(PDFPage page,
                    float x,
                    float y,
                    float zoom)
Set the page to display in the DocumentViewport. The page is displayed at the co-ordinates supplied and at the specified zoom level.

Parameters:
page - the page
x - the left-most position of the page to display, in units relative to PagePanel.getFullPageView(org.faceless.pdf2.PDFPage)
y - the top-most position of the page to display, in units relative to PagePanel.getFullPageView(org.faceless.pdf2.PDFPage)
zoom - the zoom level

redraw

public void redraw(Object o)
Redraw the specified object. This method passes the object to the SidePanel.redraw(java.lang.Object) and DocumentViewport.redraw(java.lang.Object) methods, and should be called when the PDF has been updated somehow - ie a page or annotation has been altered. param o the Object that has been altered - typically a PDFPage or PDFAnnotation


print

public void print(PrintService fservice,
                  PrintRequestAttributeSet fatts)
           throws PrintException,
                  PrinterException
Display a Print dialog for printing this document, or if a PrintService is specified, print directly to that service without displaying a dialog.

Parameters:
fservice - the PrintService to print to. If this value is null a dialog will be displayed allowing the selection of a service.
fatts - the print attributes - may be set to an AttributeSet to control the printing, or null to use the default.
Throws:
PrintException
PrinterException


Copyright © 2001-2009 Big Faceless Organization