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.

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 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
 String getSelectedSidePanel()
          Return the name of the currently selected SidePanel, or null if no panels are displayed.
 Map getSidePanels()
          Return a read-only map 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 service, PrintRequestAttributeSet atts)
          Display a Print dialog for printing this document, or if a PrintService is specified, print directly to that service without displaying a dialog.
 void raiseRedrawnEvent()
          Raise a "redrawn" event on this DocumentPanel.
 void redraw(Object o)
          Redraw the specified object.
 void removeDocumentPanelListener(DocumentPanelListener listener)
          Remove a DocumentPanelListener from this 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 DocumentFrame.
 void setSelectedSidePanel(String name)
          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

raiseRedrawnEvent

public void raiseRedrawnEvent()
Raise a "redrawn" event on this DocumentPanel. Can be called when the document has been altered externally - pages reoreder, removed etc. - and listeners need to be notified.

Since:
2.10.2

getSidePanels

public Map getSidePanels()
Return a read-only map containing the SidePanel objects in use by this DocumentPanel. The map is keyed by the name of the panel and the values are the SidePanel objects.


setSelectedSidePanel

public void setSelectedSidePanel(String name)
Set the currently displayed SidePanel

Parameters:
name - the name of the SidePanel to display, or null to hide the side panel frame. If no such panel exists this method performs no action.

getSelectedSidePanel

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


setPDF

public void setPDF(PDF pdf)
Set the PDF to be displayed by this DocumentFrame.

Parameters:
pdf - the PDF

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 service,
                  PrintRequestAttributeSet atts)
           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:
service - the PrintService to print to. If this value is null a dialog will be displayed allowing the selection of a service.
atts - the print attributes - may be set to an AttributeSet to control the printing, or null to use the default.
Throws:
PrintException
PrinterException


Copyright © 2001-2008 Big Faceless Organization