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 aJComponent
to represent aPDFAnnotation
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 thematches()
and possiblycreateComponent()
methods. If you want to use this factory to edit and/or create new annotations, it's necessary to override thecreateEditComponent()
,getAnnotationType()
andcreateNewAnnotation()
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" 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");
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 Description static Border
FOCUSBORDER
-
Constructor Summary
Constructors Constructor Description AnnotationComponentFactory(String name)
Create a new AnnotationComponentFactory
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method 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 theeditorpane
is using a GridBagLayout).static void
bindComponentLocation(JComponent component, float[] rect)
Cause the specified JComponent to be positioned at the PDF co-ordinates specified byrect
.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, Rectangle2D rect)
Cause the specified JComponent to be positioned at the PDF co-ordinates specified byrect
.static void
bindComponentLocation(JComponent component, PDFAnnotation annot)
Cause the specified JComponent to be positioned at same position as the PDFAnnotation.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 benull
)PDFViewer
getViewer()
Return the Viewer this Factory is a part ofvoid
initialize(PDFViewer viewer)
Called when the feature is first added to a viewerboolean
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 aJComponent
for the specifiedPDFAnnotation
.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-opString
toString()
-
Methods inherited from class org.faceless.pdf2.viewer2.ViewerFeature
getAllEnabledFeatures, getAllFeatures, getCustomJavaScript, getFeatureProperty, getFeatureURLProperty, getName, isEnabledByDefault, setFeatureName, teardown
-
-
-
-
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 classViewerFeature
-
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 benull
)- 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 classViewerFeature
-
matches
public abstract boolean matches(PDFAnnotation annot)
Return true if this AnnotationComponentFactory could create aJComponent
for the specifiedPDFAnnotation
.
-
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 callpaintComponent(this, this.ui, g)
followed bypaintComponentAnnotations(this, g)
- typically, the main reason to override this method is when a different type of object is required (eg. aJTextField
)- Parameters:
pagepanel
- the panel the JComponent will be added toannot
- 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 withPDFAnnotation
- 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 annotationreadonly
- whether we are displaying or editing the annotationcreate
- 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 theeditorpane
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 annotationpagepanel
- the PagePanel the Annotation was added onaction
- 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 returnnull
(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 coordinatey1
- the lower left y coordinatex2
- the top right x coordinatey2
- 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 thepaintComponent()
method of theJComponent
returned fromcreateComponent
to do the actual painting.- Parameters:
comp
- the JComponent we're paintingui
- theui
field of that componentg
- 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 byrect
. If the page is scrolled or zoomed the component will be zoomed and resized to match.- Parameters:
component
- the Componentrect
- 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 byrect
. If the page is scrolled or zoomed the component will be zoomed and resized to match.- Parameters:
component
- the Componentrect
- 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 Componentx1
- the left-most X co-ordinate of the component in PDF spacey1
- the bottom-most Y co-ordinate of the component in PDF spacex2
- the right-most X co-ordinate of the component in PDF spacey2
- 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 Componentannot
- 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 JComponentannot
- the PDFAnnotationshowproperties
- 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 isread-only
orlocked
this value will be overriddenresizable
- whether the Component should be resizable as opposed to just draggable. If the annotation isread-only
orlocked
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 fromtarget
- 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 anAnnotationComponentFactory
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)
-
-