Class TextAnnotationWrangler

Direct Known Subclasses:
CalloutAnnotationWrangler, IconifiedTextAnnotationWrangler, StampAnnotationWrangler

public class TextAnnotationWrangler extends DefaultWrangler<TextAnnotation>
Manages the creation of text annotations.

This class is referenced in annotation profiles by its full classname. It supports parameterization via annotation profiles.

  • Field Details

    • executeActionAfterCreation

      protected boolean executeActionAfterCreation
      Profile-injected parameter. Instructs this wrangler implementation to open the text editor automatically after creating a text annotation.

      Defaults to false.

    • showRotationHandle

      protected Boolean showRotationHandle
    • editorWidth

      protected int editorWidth
      Profile-injected parameter. Instructs this wrangler implementation to open the text editor with the minimum width defined in the annotation profile.

      Defaults to 50 px.

    • editorHeight

      protected int editorHeight
      Profile-injected parameter. Instructs this wrangler implementation to open the text editor with the minimum width defined in the annotation profile.

      Defaults to 50 px.

    • textSelection

      protected TextAnnotationWrangler.TextSelection textSelection
      Profile-injected parameter that defines the initial text selection behavior in the TextEditor.
    • cursorPosition

      protected TextAnnotationWrangler.CursorPosition cursorPosition
      Profile-injected parameter that defines the initial cursor position in the TextEditor.
    • forceAnnotationUpright

      protected TextAnnotationWrangler.ForceAnnotationUpright forceAnnotationUpright
      Profile-injected parameter that defines the initial behavior for rotated Pages
    • editorBehaviorOnOutsideClick

      protected TextAnnotationWrangler.EditorBehaviorOnOutsideClick editorBehaviorOnOutsideClick
      Profile injected parameter that defines the behavior of the TextEditor on an outside click.
    • expandHeight

      protected TextAnnotationWrangler.ExpandHeight expandHeight
      Profile injected parameter that defines the behavior of the annotation according to the text length
  • Constructor Details

    • TextAnnotationWrangler

      public TextAnnotationWrangler()
  • Method Details

    • setExpandHeight

      public void setExpandHeight(TextAnnotationWrangler.ExpandHeight expandHeight)
      Used to inject the value defined in the annotation profile.
      Parameters:
      expandHeight - The value defined in the annotation profile.
    • setExecuteActionAfterCreation

      public void setExecuteActionAfterCreation(boolean executeActionAfterCreation)
      Used to inject the value defined in the annotation profile.
      Parameters:
      executeActionAfterCreation - The value defined in the annotation profile.
    • setEditorWidth

      public void setEditorWidth(int width)
      Used to inject the value defined in the annotation profile.
      Parameters:
      width - The value defined in the annotation profile.
    • setEditorHeight

      public void setEditorHeight(int editorHeight)
      Used to inject the value defined in the annotation profile.
      Parameters:
      editorHeight - The value defined in the annotation profile.
    • isExecuteActionAfterCreation

      public boolean isExecuteActionAfterCreation()
      Indicates whether this wrangler executes an action after annotation creation.
      Returns:
      True, if afterCreate(EditEvent, TextAnnotation, Object...) will be called after each annotation creation. False, else.
    • getEditorWidth

      public int getEditorWidth()
      Returns the minimum text editor width.
      Returns:
      The minimum text editor width in px.
    • getEditorHeight

      public int getEditorHeight()
      Returns the minimum text editor height.
      Returns:
      The minimum text editor height in px.
    • isShowRotationHandle

      public boolean isShowRotationHandle()
      Returns if the handle to rotate the annotation is displayed.
      Returns:
      If the rotation handle is shown.
    • setShowRotationHandle

      public void setShowRotationHandle(boolean showRotationHandle)
      Used to inject the value defined in the annotation profile.
      Parameters:
      showRotationHandle - The value defined in the annotation profile.
    • getHandles

      public List<? extends Handle> getHandles(PageView pageView, Page page, TextAnnotation annotation)
      Description copied from class: Wrangler
      Creates handles for a specific annotation.
      Overrides:
      getHandles in class DefaultWrangler<TextAnnotation>
      Parameters:
      pageView - PageView the annotation is shown on (for example for repaint calls)
      page - The page that contains the annotation
      annotation - The annotation the wrangler should create handles for
      Returns:
      Handles that can be used to edit the annotation
    • isSelectionPoint

      public boolean isSelectionPoint(Annotation annotation, Point2D mousePoint, int tolerance, boolean b, int lineWidthFactor)
      Overrides:
      isSelectionPoint in class DefaultWrangler<TextAnnotation>
    • handleEditEvent

      public void handleEditEvent(EditEvent e, TextAnnotation selected, AnnotationEditor editor)
      Called whenever a text annotation is edited.

      Opens the text editor when a selected annotation is double clicked and appropriate permissions are existing.

      Overrides:
      handleEditEvent in class DefaultWrangler<TextAnnotation>
      Parameters:
      e - The event that triggered the editing
      selected - The annotation to be edited
      editor - The annotation editor that provides all editing options for the annotation
    • openTextEditor

      protected void openTextEditor(TextAnnotation selected, Page page, RenderControls controls, PageView pageView, int editorMinWidth, int editorMinHeight)
      Opens the text editor in a new popup.

      Width and height of the popup default to the width and height of the underlying annotation.

      Additionally supports parameters to enforce a minimum width and a minimum height of the editor popup. This is useful when the user creates a new, very small text annotation. In that case the editor's size is not calculated by the underlying very small annotation's size in order to provide a usable interface.

      Delegates the popup creation to the DefaultPopupExecutor.

      Parameters:
      selected - the selected TextAnnotation.
      page - the page containing selected annotation.
      controls - the RenderControls.
      pageView - the corresponding PageView.
      editorMinWidth - the minimum width of the editor popup in px.
      editorMinHeight - the minimum height of the editor popup in px.
    • createTextEditor

      protected TextEditor createTextEditor(int editorMinWidth, int editorMinHeight, TextAnnotation selected, double pageHeight)
      Creates a text editor. The editor for normal text annotations does not have a minimum size.
      Parameters:
      pageHeight -
      Returns:
      a new text editor instance.
    • updateCreated

      protected void updateCreated(EditEvent editEvent, TextAnnotation createAnno, Point2D createStart, Point2D createEnd)
      Overrides:
      updateCreated in class DefaultWrangler<TextAnnotation>
    • afterCreate

      public void afterCreate(EditEvent editEvent, TextAnnotation selected, Object... params)
      Opens the text editor directly after creating a text based annotation.

      Places the text editor popup at the upper left corner of the created annotation.

      Overrides:
      afterCreate in class DefaultWrangler<TextAnnotation>
      Parameters:
      editEvent - the last mouse event that is related to the creation.
      selected - the created annotation.
      params - an array containing the coordinates of the upper left corner of the annotation. The text editor is placed there.
    • contribute

      public void contribute(ContributionContext cc, MenuBuilder builder, List<? extends Annotation> selected)
      Contributes an icon to open the text editor popup.

      This is e.g. used in the AnnotationEditor that is displayed when selecting a text annotation.

      Overrides:
      contribute in class DefaultWrangler<TextAnnotation>
      Parameters:
      cc - the ContributionContext.
      builder - the MenuBuilder.
      selected - the set of Annotation objects.
    • getIcon

      protected EffectIcon getIcon(List<? extends Annotation> selected, Document doc)
      Returns:
      the icon used for the AnnotationEditor
    • getIconFont

      protected ToggleIconFont getIconFont(List<? extends Annotation> selected, Document doc)
      Returns:
      the icon used for the AnnotationEditor
    • getTextSelection

      public TextAnnotationWrangler.TextSelection getTextSelection()
    • setTextSelection

      public void setTextSelection(TextAnnotationWrangler.TextSelection textSelection)
    • getCursorPosition

      public TextAnnotationWrangler.CursorPosition getCursorPosition()
    • setCursorPosition

      public void setCursorPosition(TextAnnotationWrangler.CursorPosition cursorPosition)
    • getForceAnnotationUpright

      public TextAnnotationWrangler.ForceAnnotationUpright getForceAnnotationUpright()
    • setForceAnnotationUpright

      public void setForceAnnotationUpright(TextAnnotationWrangler.ForceAnnotationUpright forceAnnotationUpright)
    • setEditorBehaviorOnOutsideClick

      public void setEditorBehaviorOnOutsideClick(TextAnnotationWrangler.EditorBehaviorOnOutsideClick behaviorOnOutsideClick)
    • getEditorBehaviorOnOutsideClick

      public TextAnnotationWrangler.EditorBehaviorOnOutsideClick getEditorBehaviorOnOutsideClick()
    • calculateEditorBounds

      protected Rectangle calculateEditorBounds(PageView pageView, Page page, TextAnnotation selected)
      Calculates the editor bounds which should be the same size and position as the text annotation. After that the position will be slightly adapted according to the line width of the annotation.
      Parameters:
      pageView - the PageView containing the Annotation
      page - the page containing the Annotation
      selected - the selected Annotation
      Returns:
      the calculated editor bounds
    • getMultiplier

      protected float getMultiplier(PageView pageView, Page page)
      This method calculates the multiplier for the correct translation of units for a correct presentation and positioning of the editor.
      Parameters:
      pageView - the PageView containing the Annotation
      page - the Page containing the Annotation
      Returns:
      returns the multiplier for correct unit translation
    • scaleByEditorWidth

      public boolean scaleByEditorWidth()
      This can be overriden by any subclass to disable the initial resizing when an annotation is added with a single click.