Interface MarkupTarget


  • public interface MarkupTarget
    A markup target is an adapter that allows modification of the text in user interface components that can contain markup text for a game component. The markup target presents a common interface for modifying the text in the target component so that the underlying component type is transparent to the user. Typical markup targets are text fields, text areas, and code editors.

    Although you can create a markup target for any valid component directly, it is more common to use the application markup target. For example, the commands in the Markup menu use the application markup target as the target of their commands.

    Since:
    3.0
    Author:
    Chris Jennings
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String FORCE_MARKUP_TARGET_PROPERTY
      If set in a component's client properties, forces whether a component is or is not considered to be a markup target.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void copy()
      Copies the current selection to the clipboard.
      void cut()
      Cuts the current selection to the clipboard.
      CodeEditorBase getCodeEditor()
      If the markup target is inside of a code editing component, returns the code editor containing the target.
      java.lang.String getSelectedText()
      Returns the selected text of the markup target.
      int getSelectionEnd()
      Returns the end offset of the selection.
      int getSelectionStart()
      Returns the start offset of the selection; if there is no selection, this will be the same as getSelectionEnd().
      java.lang.Object getTarget()
      Returns the actual target wrapped by this MarkupTarget.
      java.lang.String getText()
      Returns the current text of the markup target.
      java.lang.String getText​(int start, int length)
      Returns an arbitrary substring of the text of the markup target.
      boolean isCodeEditor()
      Returns true if the target is a source code editor, or false if the target is another type of text component.
      int length()
      Returns the length of the current text of the markup target.
      void paste()
      Replaces the current selection with the clipboard contents.
      void requestFocus()
      If the target is a component, then it will request input focus.
      void select​(int start, int end)
      Changes the selection in the markup target.
      void selectAll()
      Selects all text in the document.
      int selectionLength()
      Returns the length of the selected text of the markup target.
      void selectNone()
      Clears the selection without changing the caret position.
      int setSelectedText​(java.lang.String text)
      Inserts text at the cursor position.
      void setSelectionEnd​(int end)
      Sets the end of the selection.
      void setSelectionStart​(int start)
      Sets the start of the selection.
      void tagSelectedText​(java.lang.String prefix, java.lang.String suffix, boolean caseSensitive)
      Tags the selected text with a prefix and suffix.
    • Field Detail

      • FORCE_MARKUP_TARGET_PROPERTY

        static final java.lang.String FORCE_MARKUP_TARGET_PROPERTY
        If set in a component's client properties, forces whether a component is or is not considered to be a markup target. Set to Boolean.TRUE or Boolean.FALSE. Otherwise, markup target candidates are evaluated using heuristics. To be valid, the component must still be an acceptable type of control, and (in strict validation mode) showing, enabled, and editable.
        See Also:
        MarkupTargetFactory.isValidTarget(java.lang.Object, boolean), Constant Field Values
    • Method Detail

      • getText

        java.lang.String getText()
        Returns the current text of the markup target.
        Returns:
        the entire editable contents of the target
      • length

        int length()
        Returns the length of the current text of the markup target.
        Returns:
        the length of the entire editable contents of the target
      • getSelectedText

        java.lang.String getSelectedText()
        Returns the selected text of the markup target. If there is no selection, returns the empty string.
        Returns:
        the current selection
      • selectionLength

        int selectionLength()
        Returns the length of the selected text of the markup target. If there is no selection, returns 0.
        Returns:
        the length of the current selection
      • getText

        java.lang.String getText​(int start,
                                 int length)
        Returns an arbitrary substring of the text of the markup target. The returned text will be empty if the start position is past the end of the document or the length is 0. If there are fewer characters after the start offset than the requested length, then the rest of the document is returned.
        Parameters:
        start - the start index of the substring
        length - the number of characters to include
        Returns:
        the text of the markup target from start to end-1, inclusive
        Throws:
        java.lang.IllegalArgumentException - if start or length is negative
      • select

        void select​(int start,
                    int end)
        Changes the selection in the markup target. Invalid selections will be clamped to the valid range of the document. Note that start does not need to be less than end; the cursor will be located at the end offset.
        Parameters:
        start - the start offset of the new selection
        end - the end offset of the new selection
      • selectAll

        void selectAll()
        Selects all text in the document.
      • selectNone

        void selectNone()
        Clears the selection without changing the caret position.
      • getSelectionStart

        int getSelectionStart()
        Returns the start offset of the selection; if there is no selection, this will be the same as getSelectionEnd().
        Returns:
        the selection start offset
      • setSelectionStart

        void setSelectionStart​(int start)
        Sets the start of the selection. Invalid values will be clamped to the bounds of the document.
        Parameters:
        start - the new selection start
        See Also:
        getSelectionStart(), select(int, int)
      • getSelectionEnd

        int getSelectionEnd()
        Returns the end offset of the selection. The end offset is the offset of the cursor position within the document text.
        Returns:
        the selection end offset
      • setSelectionEnd

        void setSelectionEnd​(int end)
        Sets the end of the selection. Invalid values will be clamped to the bounds of the document.
        Parameters:
        end - the new selection end
        See Also:
        getSelectionEnd(), select(int, int)
      • setSelectedText

        int setSelectedText​(java.lang.String text)
        Inserts text at the cursor position. If there is an active selection, it will be replaced. The inserted text may be modified before insertion, so the actual number of characters inserted may not be the same as text.length().
        Parameters:
        text - the text to insert
        Returns:
        the number of characters inserted
        Throws:
        java.lang.NullPointerException - if text is null
      • tagSelectedText

        void tagSelectedText​(java.lang.String prefix,
                             java.lang.String suffix,
                             boolean caseSensitive)
        Tags the selected text with a prefix and suffix. If the selected text is already surrounded by the prefix and suffix, then the prefix and suffix will be removed. This is a simple way to add or remove modal markup tags around the selection. For example, to bold the selected text (or unbold if it is surround by a bold tag pair):
        tagSelection( "<b>", "</b>" )
        Parameters:
        prefix - the prefix to insert (or remove) at the start of the selection
        suffix - the suffix to insert (or remove) at the end of the selection
        caseSensitive - if true, the prefix and suffix are case-sensitive
      • cut

        void cut()
        Cuts the current selection to the clipboard.
      • copy

        void copy()
        Copies the current selection to the clipboard.
      • paste

        void paste()
        Replaces the current selection with the clipboard contents.
      • getTarget

        java.lang.Object getTarget()
        Returns the actual target wrapped by this MarkupTarget.
        Returns:
        the underlying object that is manipulated by this markup target instance
      • requestFocus

        void requestFocus()
        If the target is a component, then it will request input focus.
      • isCodeEditor

        boolean isCodeEditor()
        Returns true if the target is a source code editor, or false if the target is another type of text component.
        Returns:
        true if the editor is a code editor
      • getCodeEditor

        CodeEditorBase getCodeEditor()
        If the markup target is inside of a code editing component, returns the code editor containing the target. Otherwise returns null.
        Returns:
        the code editor component containing the the markup target, or null if the target is not part of a code editor