com.qoppa.pdfNotes
Class PDFNotesBean

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended bycom.qoppa.pdfViewer.PDFViewerBean
                      extended bycom.qoppa.pdfNotes.PDFNotesBean
All Implemented Interfaces:
Accessible, ActionListener, EventListener, IDocumentListener, ImageObserver, IPassword, IPDFActionHandler, IPDFSaver, MenuContainer, Serializable

public class PDFNotesBean
extends PDFViewerBean
implements IDocumentListener, IPDFActionHandler, IPDFSaver

PDFNotesBean is a component that can be used to display and annotate PDF documents within an application or an applet. The bean takes a PDF document as a file name, a URL or an InputStream, reads the document and then displays the document, allowing the user to navigage and add annotations to the document.
The bean can save the document to a file but also allows the host application to define a custom 'saver' to be able to save the document somewhere different than a file (database, server, etc). The bean can be extendes and the save method overridden to get the same effect.

Author:
Qoppa Software
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
 
Fields inherited from class com.qoppa.pdfViewer.PDFViewerBean
SPLITPOLICY_NEVER_VISIBLE, SPLITPOLICY_USEDOCUMENTPAGEMODE, ZOOMMODE_FITPAGE, ZOOMMODE_FITWIDTH, ZOOMMODE_NORMAL
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
PDFNotesBean()
          Construct a PDFNotesBean.
 
Method Summary
 void actionPerformed(ActionEvent ae)
          This method handles actions from the toolbars in the bean.
 void addAnnotation(Annotation newAnnot, int pageIndex)
          Add an annotation to the document programmatically.
 void addPDFListener(IPDFListener listener)
          Adds a PDF Listener object to receive notifications when a new document is opened.
 SignatureField addSignatureField(String fieldName, Rectangle2D bounds, int pageIndex)
          Add a signature field to a page in the currently loaded document.
 boolean close(boolean checkSave)
          This method closes the current document.
 void documentChanged(DocumentEvent de)
          Internal method, do not use.
 void enableThumbPaneEditing(boolean enable)
           
 AnnotToolbar getAnnotToolbar()
          Returns the annotation tools toolbar.
 String getCurrentDocName()
          This method returns the current document name.
 String getCurrentDocPath()
          This method returns the current document path.
 EditToolbar getEditToolbar()
          Returns the standard toolbar.
static String getVersion()
          Returns version string for jPDFNotes.
 void handleAction(Action action)
          This method overrides the PDFViewerBean handleAction to take care of actions that are specific to jPDFNotes, such as saving the document.
 boolean isModified()
          Returns whether this document has been modified or not.
 void loadFDF(String fileName)
          Load an FDF file.
 void loadPDF(InputStream inStream)
          Load and display a PDF document using an InputStream.
 void loadPDF(String fileName)
          Load and display a PDF document using a file name.
 void loadPDF(URL url)
          Load and display a PDF document using a URL.
 void loadXFDF(String fileName)
          Load an XFDF file.
 void print(PrintSettings printSettings)
          Prints the PDF document to a printer.
 void reloadDocument()
          Reloads a document into the viewer.
 void removeAnnotation(Annotation annot, int pageIndex)
          Remove an annotation from the document programmatically.
 void revert()
          Reverts the loaded document to the saved document.
 boolean save()
          This method saves the current document by calling the currently registered PDF Saver's save method.
 boolean save(PDFNotesBean notesBean, String docName, File pdfFile)
          This method saves the pdf to a file.
 boolean saveAs()
          This method implements the standard 'Save As...' function by prompting for a new file name and calling the save method with this file name.
 void saveDocument(OutputStream outStream)
          Saves this document to an output stream.
 void saveDocument(String fileName)
          Saves this document to a file.
 void setFieldsHighlight(boolean highlight)
          Highlight any fields in the document.
static boolean setKey(String key)
          Sets product key.
 void setModified(boolean modified)
          Flag this document as modified.
 void setPDFSaver(IPDFSaver saver)
          This method allows the host application to override the default PDF Saver, the class that saves the document when the save toolbar button is pressed.
 void signDocument(SignatureField signField)
          Starts the signing GUI for a given signature field.
 void signDocument(SignatureField signField, SigningInformation signingInfo, File outputFile)
          This method will sign and save the document.
 void startEdit(Annotation annot, boolean useDefault)
          This method starts an annotation editor appropriate to the type of annotation passed to it.
 void stopWidgetEditing()
           
 
Methods inherited from class com.qoppa.pdfViewer.PDFViewerBean
clearDocument, getAcroForm, getBookmarkTree, getDocument, getPageByLocation, getPageCount, getPageNumber, getPageView, getPasswordHandler, getPasswords, getRootPane, getRotation, getScale, getScrollPane, getSelectContextMenu, getSelectedText, getSelectToolbar, getSplitPane, getSplitPolicy, getSplitTabs, getToolbar, getZoomMode, isSplitOpen, isSplitVisible, rotateCCW, rotateCW, scrollToPage, setAppletKey, setDocument, setInvertMode, setPage, setPasswordHandler, setPrintSettings, setRotation, setScale, setSplitOpen, setSplitPolicy, setSplitVisible, setZoomMode, startMagnifyRect, startTextSelection, stopTextSelection, zoomToRect
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PDFNotesBean

public PDFNotesBean()
Construct a PDFNotesBean.

Method Detail

getVersion

public static String getVersion()
Returns version string for jPDFNotes. If this is the demo version, the return string will contain 'Demo Version' at the end.


setKey

public static boolean setKey(String key)
Sets product key. Use this method after purchasing to remove evaluation restrictions.

Parameters:
key - Product key.

getEditToolbar

public EditToolbar getEditToolbar()
Returns the standard toolbar. Host applications can use this method to be able to change the behaviour of the toolbar, such as making buttons visible/invisible, adding listeners, etc. Please see EditToolbar for details.

Returns:
The edit bean's toolbar.

reloadDocument

public void reloadDocument()
Reloads a document into the viewer. This method should be called when a document has been modified in some way that the viewer would not detect. When the method is called, bookmarks, page thumbviews, etc are re-generated.


removeAnnotation

public void removeAnnotation(Annotation annot,
                             int pageIndex)
                      throws PDFException
Remove an annotation from the document programmatically. Using this method, the host application can remove annotations from the document without user interaction.

Parameters:
annot - The annotation to be removed
pageIndex - The page where the annotation is currently displayed, pageIndex starts at 0.
Throws:
PDFException

getAnnotToolbar

public AnnotToolbar getAnnotToolbar()
Returns the annotation tools toolbar. This method provides access to the annotation toolbar so that the host application can modify the standard behaviour and buttons of the toolbar.

Returns:
Reference to the annotation toolbar.

enableThumbPaneEditing

public void enableThumbPaneEditing(boolean enable)

actionPerformed

public void actionPerformed(ActionEvent ae)
This method handles actions from the toolbars in the bean. The method overrides PDFViewerBean to handle editing commands and calls PDFViewerBean.actionPerformed for the standard buttons.

Specified by:
actionPerformed in interface ActionListener
Overrides:
actionPerformed in class PDFViewerBean
Parameters:
ae - The action event.

startEdit

public void startEdit(Annotation annot,
                      boolean useDefault)
This method starts an annotation editor appropriate to the type of annotation passed to it. The method will start different editors for the following annotation types: Circle, Square, Ink, FreeText, Text, Sound and Link.

Parameters:
annot - An annotation object.

revert

public void revert()
Reverts the loaded document to the saved document. This method only works if the document was loaded from a file. If reversion is desired, the host application needs to override this method with its own implementation.

Throws:
PDFException - If the document was not loaded from a file, the method throws a PDFException.

close

public boolean close(boolean checkSave)
This method closes the current document. The method first checks if the current document has been modified (optionally) and if it has, asks the user whether it should be saved.

Parameters:
checkSave - Tells the method whether to ask the user to save the current document if it has been modified.
Returns:
true if the document was closed, false if user pressed cancel

save

public boolean save(PDFNotesBean notesBean,
                    String docName,
                    File pdfFile)
This method saves the pdf to a file. If there is no file name available, the method will prompt the user for a file name and then save to that file. This method fulfills the IPDFSaver interface and will be called by the Save button on the toolbar unless the saver has been set by the host application.
This method can be overridden by a class that extends PDFNotesBean to customize saving behaviour. Alternatively, a host application can call setPDFSaver with an object that implements IPDFSaver to use a custom saver. After setPDFSaver is called, all save functions will use the saver supplied by the host application.

Specified by:
save in interface IPDFSaver
Parameters:
notesBean - Reference to the PDFNotesBean that holds the document.
docName - The name of the PDF document, normally the file name.
pdfFile - A reference to a file object if the PDF was loaded from a file, null if the PDF was opened from a URL or an InputStream.
Returns:
true if the document was saved properly, false if there was any errors.

saveDocument

public void saveDocument(String fileName)
                  throws PDFException,
                         IOException
Saves this document to a file.

Parameters:
fileName - Name of the file to save the document.
Throws:
PDFException
IOException

saveDocument

public void saveDocument(OutputStream outStream)
                  throws IOException,
                         PDFException
Saves this document to an output stream. This method can be used in conjunction with a ByteArrayOutputStream to get a byte array holding the PDF document.

Parameters:
outStream - OutputStream where the document will be written to.
Throws:
IOException
PDFException

saveAs

public boolean saveAs()
This method implements the standard 'Save As...' function by prompting for a new file name and calling the save method with this file name.

Returns:
true if the document was saved properly, false if there was any errors or if user cancelled.

save

public boolean save()
This method saves the current document by calling the currently registered PDF Saver's save method.

Returns:
true if the document was saved properly, false if there was any errors.

loadPDF

public void loadPDF(InputStream inStream)
             throws PDFException
Load and display a PDF document using an InputStream.

Overrides:
loadPDF in class PDFViewerBean
Parameters:
inStream - InputStream used to read the PDF document.
Throws:
PDFException

loadFDF

public void loadFDF(String fileName)
             throws PDFException
Load an FDF file. This method will open the corresponding PDF file and import the FDF data in the document.

Parameters:
fileName - Name of the FDF document file.
Throws:
PDFException

loadXFDF

public void loadXFDF(String fileName)
              throws PDFException
Load an XFDF file. This method will open the corresponding PDF file and import the XFDF data in the document.

Parameters:
fileName - Name of the xFDF document file.
Throws:
PDFException

loadPDF

public void loadPDF(String fileName)
             throws PDFException
Load and display a PDF document using a file name.

Overrides:
loadPDF in class PDFViewerBean
Parameters:
fileName - Name of the PDF document file.
Throws:
PDFException

loadPDF

public void loadPDF(URL url)
             throws PDFException
Load and display a PDF document using a URL.

Overrides:
loadPDF in class PDFViewerBean
Parameters:
url - URL pointing to the location of the PDF document.
Throws:
PDFException

print

public void print(PrintSettings printSettings)
           throws PDFPermissionException,
                  PrinterException
Description copied from class: PDFViewerBean
Prints the PDF document to a printer. This method will first prompt the user to choose a system printer and then it will print the document.

If finer control of printing is necessary, the IPDFDocument object return by the getDocument() method implements both Printable and Pageable. The host application can then create its own PrinterJob and set any settings necessary, then call either setPageable or setPrintable with the IPDFDocument object and then start the print job.

Overrides:
print in class PDFViewerBean
Parameters:
printSettings - Print job settings. Use this object to tell jPDFViewer how to print the document. If null, the library will print using default settings.
Throws:
PDFPermissionException
PrinterException

setPDFSaver

public void setPDFSaver(IPDFSaver saver)
This method allows the host application to override the default PDF Saver, the class that saves the document when the save toolbar button is pressed.

Parameters:
saver - A reference to an object that implements the IPDFSaver interface.

addPDFListener

public void addPDFListener(IPDFListener listener)
Adds a PDF Listener object to receive notifications when a new document is opened.

Parameters:
listener - The new listener.

getCurrentDocName

public String getCurrentDocName()
This method returns the current document name. The name changes according to whether the document was opened from a file (name of the file), a URL (the URL file) or from an input stream ().

Returns:
The name of the current document.

getCurrentDocPath

public String getCurrentDocPath()
This method returns the current document path. The name changes according to whether the document was opened from a file (absolute path of the file), a URL (the URL) or from an input stream ().

Returns:
The path of the current document.

setModified

public void setModified(boolean modified)
Flag this document as modified. If the host application modifies the document programmatically, it should call this method to flag the document as modified. Methods such as open and close check this flag to decide whether to prompt the user to save the current document or not.

Parameters:
modified - Flag indicating whether this document has been modified.

isModified

public boolean isModified()
Returns whether this document has been modified or not.

Returns:
true if the document has changed, false otherwise.

documentChanged

public void documentChanged(DocumentEvent de)
Internal method, do not use.

Specified by:
documentChanged in interface IDocumentListener
Overrides:
documentChanged in class PDFViewerBean

stopWidgetEditing

public void stopWidgetEditing()

addAnnotation

public void addAnnotation(Annotation newAnnot,
                          int pageIndex)
                   throws PDFException
Add an annotation to the document programmatically. Using this method, the host application can add annotations to the document without user interaction.

Parameters:
newAnnot - The new annotation.
pageIndex - The page at which to add the annotation, pageIndex starts at 0.
Throws:
PDFException

addSignatureField

public SignatureField addSignatureField(String fieldName,
                                        Rectangle2D bounds,
                                        int pageIndex)
                                 throws PDFException
Add a signature field to a page in the currently loaded document. Signature fields are used to digitally sign PDF documents. When this method is called, an empty signature field is added that can be signed by a user. To sign the document programmatically, the host application can call signDocument.

Parameters:
fieldName - The name of the field.
bounds - The bounds on the page for the field.
pageIndex - The page number.
Throws:
PDFException

signDocument

public void signDocument(SignatureField signField)
                  throws PDFException
Starts the signing GUI for a given signature field. This method will display a number of dialogs to the user to to choose a PKCS#12 file and to get any additional information needed to sign the document. After the signature is applied, the method will save the document to the same file or to a new file according to what the user chose.

Parameters:
signField - The signature field to apply the signature to.
Throws:
PDFException

signDocument

public void signDocument(SignatureField signField,
                         SigningInformation signingInfo,
                         File outputFile)
                  throws PDFException
This method will sign and save the document. The signature information is passed in to the method, so the method does not prompt the user for any additional information. After signing, the document will be saved to outputFile.

Parameters:
signField - The signature field to apply the signature to.
signingInfo - The signature information.
outputFile - The output file to save the document to. If this is null, the document will be saved to the current file.
Throws:
PDFException

setFieldsHighlight

public void setFieldsHighlight(boolean highlight)
Highlight any fields in the document. Highlighting fields will display a semi-transparent blue rectangle over the field position so that the fields can be more easily seen by the user.

Parameters:
highlight - Boolean flag indicating whether the fields should be highlighted.

handleAction

public void handleAction(Action action)
This method overrides the PDFViewerBean handleAction to take care of actions that are specific to jPDFNotes, such as saving the document. This method can be further overridden to handle actions in a custom manner. The parameter passed in will be an instance of an object derived from Action and can be tested using 'instanceof' to determine the kind of action.

Specified by:
handleAction in interface IPDFActionHandler
Overrides:
handleAction in class PDFViewerBean
Parameters:
action - Object describing the action.