Class AnnotationComponentFactory

    • 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

      • 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
      • 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