org.faceless.pdf2.viewer2

## Class AnnotationComponentFactory

- java.lang.Object
- - org.faceless.pdf2.viewer2.ViewerFeature
  - - org.faceless.pdf2.viewer2.AnnotationComponentFactory

- Direct Known Subclasses:
    AnnotationEllipseFactory, AnnotationLineFactory, AnnotationLinkFactory, AnnotationNoteFactory, AnnotationRectangleFactory, AnnotationSoundFactory, AnnotationStampFactory, AnnotationTextFactory, FormBarCodeWidgetFactory, FormBlankSignatureWidgetFactory, FormButtonWidgetFactory, FormChoiceWidgetFactory, FormRadioButtonWidgetFactory, FormSignedSignatureWidgetFactory, FormTextWidgetFactory

      public abstract class AnnotationComponentFactory
      extends ViewerFeature

  A type of ViewerFeature that creates a `JComponent` to represent a `PDFAnnotation` on the page. Typically AnnotationComponentFactories are singleton objects, as they do not need to be tied to a specific viewer. For viewing components, all that needs to be overridden are the `matches()` and possibly `createComponent()` methods. If you want to use this factory to edit and/or create new annotations, it's necessary to override the `createEditComponent()`, `getAnnotationType()` and `createNewAnnotation()` methods as well.
  The following initialization parameters can be specified to configure this feature or any of its subclasses.

  delete | If set to false, the "delete" option will not be available when an annotation is right-clicked
  edit | If set to false, the "edit" option will not be available when an annotation is right-clicked
  flatten | If set to false, the "flatten" option will not be available when an annotation is right-clicked
  edit.set.author | If set to true, editing an annotation will set the author. The default is false
  edit.display.field1 | When editing an annotation, the field to display in the top-left of the dialog. Can be set to "author", "subject", "creationDate" or "modifyDate", and the default is "creationDate"
  edit.display.field2 | When editing an annotation, the field to display in the top-right of the dialog. Can be set to "author", "subject", "creationDate" or "modifyDate", and the default is "author"

  For example, to remove the "flatten" option for all annotations and the "delete" option for `AnnotationStamp` objects only, you could insert this code for an application:

       System.setProperty("org.faceless.pdf2.viewer2.AnnotationComponentFactory.flatten", "false");
       System.setProperty("org.faceless.pdf2.viewer2.feature.AnnotationStampFactory.delete", "false");

  or add the following parameters for an applet.

       <param name="AnnotationComponentFactory.flatten" value="false" />
       <param name="feature.AnnotationStampFactory.delete" value="false" />

  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

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static Border` | `FOCUSBORDER`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AnnotationComponentFactory(String name)` Create a new AnnotationComponentFactory

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `addStockDetailsToEditComponent(PDFAnnotation annot, JComponent editorpane)` Convenience method that can be used by factories to add universal details about the annotation (date, author etc) to the EditComponent in a standardized way (assuming that the `editorpane` is using a GridBagLayout).
    `static void` | `bindComponentLocation(JComponent component, float[] rect)` Cause the specified JComponent to be positioned at the PDF co-ordinates specified by `rect`.
    `static void` | `bindComponentLocation(JComponent component, float x1, float y1, float x2, float y2)` Cause the specified JComponent to be positioned at the specified PDF co-ordinates.
    `static void` | `bindComponentLocation(JComponent component, PDFAnnotation annot)` Cause the specified JComponent to be positioned at same position as the PDFAnnotation.
    `static void` | `bindComponentLocation(JComponent component, Rectangle2D rect)` Cause the specified JComponent to be positioned at the PDF co-ordinates specified by `rect`.
    `protected void` | `copyAnnotationState(PDFAnnotation source, PDFAnnotation target)` Copies the properties of a given source annotation created by this factory to a target annotation of the same type.
    `JComponent` | `createComponent(PagePanel pagepanel, PDFAnnotation annot)` Return a JComponent that will visually represent the specified PDFAnnotation.
    `protected Action` | `createDeleteAction(PDFAnnotation annot, Component comp)`
    `protected Action` | `createEditAction(PDFAnnotation annot, Component comp)`
    `JComponent` | `createEditComponent(PDFAnnotation annot, boolean readonly, boolean create)` Return a JComponent that can be used to edit the annotation or display additional information.
    `protected Action` | `createFlattenAction(PDFAnnotation annot, Component comp)`
    `PDFAnnotation` | `createNewAnnotation()` Return a brand new annotation of the type that is edited with this factory.
    `PDFAnnotation` | `createNewAnnotation(float x1, float y1, float x2, float y2)` Returns a new annotation of this factory's type with specified bounds.
    `String` | `getAnnotationType()` Return the name of the type of widgets this AnnotationComponentFactory creates or edits.
    `Preferences` | `getPreferences()` Return the Preferences object used by the viewer (may be `null`)
    `PDFViewer` | `getViewer()` Return the Viewer this Factory is a part of
    `void` | `initialize(PDFViewer viewer)` Called when the feature is first added to a viewer
    `boolean` | `isFactoryReadOnly(DocumentPanel panel)` Indicates whether annotations may be created, removed, or edited.
    `void` | `makeComponentInteractive(JComponent comp, PDFAnnotation annot, boolean showproperties, boolean movable, boolean resizable, PagePanel pagepanel)` Given an Annotation component created by a subclass of this factory, add appropriate handlers to it to make it interact with mouse movement by the user.
    `abstract boolean` | `matches(PDFAnnotation annot)` Return true if this AnnotationComponentFactory could create a `JComponent` for the specified `PDFAnnotation`.
    `static void` | `paintComponent(JComponent comp, ComponentUI ui, Graphics g)` A convenient static method which can be called to paint the content of a Component with the standard PDF-centric way (painting its appearance streams).
    `protected void` | `paintComponentAnnotations(JComponent c, Graphics g)` Paint any visible annotations that should be drawn on top of the annotation.
    `protected void` | `popupPropertyMenu(PDFAnnotation annot, Component comp, Point where)` Display the Property menu for this annotation.
    `void` | `postEdit(PDFAnnotation annot, PagePanel pagepanel, String action)` Called after an annotation is added or edited - by default, a no-op
    `String` | `toString()`

    - ### Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature

      `getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, isEnabledByDefault, setFeatureName, teardown`

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

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

- - ### Field Detail

    - #### FOCUSBORDER

          public static final transient Border FOCUSBORDER

  - ### Constructor Detail

    - #### AnnotationComponentFactory

          public AnnotationComponentFactory(String name)

      Create a new AnnotationComponentFactory
      Parameters:
        `name` - the name of this ViewerFeature

  - ### Method Detail

    - #### initialize

          public void initialize(PDFViewer viewer)

      Description copied from class: `ViewerFeature`
      Called when the feature is first added to a viewer
      Overrides:
        `initialize` in class `ViewerFeature`

    - #### isFactoryReadOnly

          public boolean isFactoryReadOnly(DocumentPanel panel)

      Indicates whether annotations may be created, removed, or edited.

    - #### getPreferences

          public Preferences getPreferences()

      Return the Preferences object used by the viewer (may be `null`)
      Since:
        2.11.7

    - #### getViewer

          public PDFViewer getViewer()

      Return the Viewer this Factory is a part of
      Since:
        2.11.7

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `ViewerFeature`

    - #### matches

          public abstract boolean matches(PDFAnnotation annot)

      Return true if this AnnotationComponentFactory could create a `JComponent` for the specified `PDFAnnotation`.

    - #### createComponent

          public JComponent createComponent(PagePanel pagepanel,
                                            PDFAnnotation annot)

      Return a JComponent that will visually represent the specified PDFAnnotation. The default implementation returns a JPanel that will display the annotation appearance - it's usually best to call super.createComponent() then add any required listeners in the subclasses.

      By default this method returns a JCompoment whose `paintComponent()` method is overridden to call `paintComponent(this, this.ui, g)` followed by `paintComponentAnnotations(this, g)` - typically, the main reason to override this method is when a different type of object is required (eg. a `JTextField`)

      Parameters:
        `pagepanel` - the panel the JComponent will be added to
        `annot` - the annotation
      See Also:
        `paintComponentAnnotations()`, `paintComponent()`

    - #### paintComponentAnnotations

          protected void paintComponentAnnotations(JComponent c,
                                                   Graphics g)

      Paint any visible annotations that should be drawn on top of the annotation. These are not to be confused with `PDFAnnotation` - these annotations are simply graphical additions to the AWT component. A good example is digital signature fields, which should display a tick, cross or question-mark depending on the current verified status of the signature. The default implementation is a no-op.
      Since:
        2.11.7
      See Also:
        `paintComponent()`, `createComponent()`

    - #### createEditComponent

          public JComponent createEditComponent(PDFAnnotation annot,
                                                boolean readonly,
                                                boolean create)

      Return a JComponent that can be used to edit the annotation or display additional information. If the annotation has no dialog that should work with it in this way, this method should return null (the default)
      Parameters:
        `annot` - the annotation
        `readonly` - whether we are displaying or editing the annotation
        `create` - if readonly if false, whether we are editing an existing or creating a new annotation
      Since:
        2.10

    - #### addStockDetailsToEditComponent

          protected void addStockDetailsToEditComponent(PDFAnnotation annot,
                                                        JComponent editorpane)

      Convenience method that can be used by factories to add universal details about the annotation (date, author etc) to the EditComponent in a standardized way (assuming that the `editorpane` is using a GridBagLayout).
      Since:
        2.11.19

    - #### postEdit

          public void postEdit(PDFAnnotation annot,
                               PagePanel pagepanel,
                               String action)

      Called after an annotation is added or edited - by default, a no-op
      Parameters:
        `annot` - the annotation
        `pagepanel` - the PagePanel the Annotation was added on
        `action` - one of "create", "edit", "flatten" or "delete"
      Since:
        2.11.12

    - #### getAnnotationType

          public String getAnnotationType()

      Return the name of the type of widgets this AnnotationComponentFactory creates or edits.
      Since:
        2.10

    - #### createNewAnnotation

          public PDFAnnotation createNewAnnotation()

      Return a brand new annotation of the type that is edited with this factory. If this factory cannot be used to create a new annotation, this method can return `null` (the default)
      Since:
        2.10

    - #### createNewAnnotation

          public PDFAnnotation createNewAnnotation(float x1,
                                                   float y1,
                                                   float x2,
                                                   float y2)

      Returns a new annotation of this factory's type with specified bounds.
      Parameters:
        `x1` - the lower left x coordinate
        `y1` - the lower left y coordinate
        `x2` - the top right x coordinate
        `y2` - the top right y coordinate

    - #### paintComponent

          public static final void paintComponent(JComponent comp,
                                                  ComponentUI ui,
                                                  Graphics g)

      A convenient static method which can be called to paint the content of a Component with the standard PDF-centric way (painting its appearance streams). This is usually called by the `paintComponent()` method of the `JComponent` returned from `createComponent` to do the actual painting.
      Parameters:
        `comp` - the JComponent we're painting
        `ui` - the `ui` field of that component
        `g` - the Graphics object we're painting to
      Since:
        2.11.7
      See Also:
        `paintComponentAnnotations()`, `createComponent()`

    - #### bindComponentLocation

          public static final void bindComponentLocation(JComponent component,
                                                         Rectangle2D rect)

      Cause the specified JComponent to be positioned at the PDF co-ordinates specified by `rect`. If the page is scrolled or zoomed the component will be zoomed and resized to match.
      Parameters:
        `component` - the Component
        `rect` - the component location in PDF space
      Since:
        2.11.25

    - #### bindComponentLocation

          public static final void bindComponentLocation(JComponent component,
                                                         float[] rect)

      Cause the specified JComponent to be positioned at the PDF co-ordinates specified by `rect`. If the page is scrolled or zoomed the component will be zoomed and resized to match.
      Parameters:
        `component` - the Component
        `rect` - the component location in PDF space, specified as [x1, y1, x2, y2]

    - #### bindComponentLocation

          public static final void bindComponentLocation(JComponent component,
                                                         float x1,
                                                         float y1,
                                                         float x2,
                                                         float y2)

      Cause the specified JComponent to be positioned at the specified PDF co-ordinates. If the page is scrolled or zoomed the component will be zoomed and resized to match.
      Parameters:
        `component` - the Component
        `x1` - the left-most X co-ordinate of the component in PDF space
        `y1` - the bottom-most Y co-ordinate of the component in PDF space
        `x2` - the right-most X co-ordinate of the component in PDF space
        `y2` - the top-most Y co-ordinate of the component in PDF space

    - #### bindComponentLocation

          public static final void bindComponentLocation(JComponent component,
                                                         PDFAnnotation annot)

      Cause the specified JComponent to be positioned at same position as the PDFAnnotation. If the page is scrolled or zoomed the component will be zoomed and resized to match.
      Parameters:
        `component` - the Component
        `annot` - the PDFAnnotation to bind the components position to

    - #### makeComponentInteractive

          public void makeComponentInteractive(JComponent comp,
                                               PDFAnnotation annot,
                                               boolean showproperties,
                                               boolean movable,
                                               boolean resizable,
                                               PagePanel pagepanel)

      Given an Annotation component created by a subclass of this factory, add appropriate handlers to it to make it interact with mouse movement by the user.
      Parameters:
        `comp` - the JComponent
        `annot` - the PDFAnnotation
        `showproperties` - whether the Component should show properties on double-click or popup menu on right-click. If the component is read-only the dialog will not allow edits.
        `movable` - whether the Component should be movable. If the annotation is `read-only` or `locked` this value will be overridden
        `resizable` - whether the Component should be resizable as opposed to just draggable. If the annotation is `read-only` or `locked` this value will be overridden
      Since:
        2.12

    - #### copyAnnotationState

          protected void copyAnnotationState(PDFAnnotation source,
                                             PDFAnnotation target)

      Copies the properties of a given source annotation created by this factory to a target annotation of the same type. This is used to make a temporary copy of an annotation for editing purposes.
      Parameters:
        `source` - the annotation to copy properties from
        `target` - the annotation to copy properties to
      Since:
        2.11.7

    - #### popupPropertyMenu

          protected void popupPropertyMenu(PDFAnnotation annot,
                                           Component comp,
                                           Point where)

      Display the Property menu for this annotation. This method is called by an `AnnotationComponentFactory` when the component is right-clicked, and it should display the edit and delete actions.
      Since:
        2.11.7

    - #### createEditAction

          protected Action createEditAction(PDFAnnotation annot,
                                            Component comp)

    - #### createDeleteAction

          protected Action createDeleteAction(PDFAnnotation annot,
                                              Component comp)

    - #### createFlattenAction

          protected Action createFlattenAction(PDFAnnotation annot,
                                               Component comp)

Copyright © 2001-2015 Big Faceless Organization