Class TerraTextInputSkin

    • Constructor Detail

      • TerraTextInputSkin

        public TerraTextInputSkin()
    • Method Detail

      • install

        public void install​(Component component)
        Description copied from class: ComponentSkin
        Must be implemented in every subclass in order to do component-specific operations at instantiation time, but every subclass must call this superclass method to setup the necessary listeners, etc.
        Specified by:
        install in interface Skin
        Overrides:
        install in class ComponentSkin
        Parameters:
        component - The component to which the skin is being attached.
      • getPreferredWidth

        public int getPreferredWidth​(int height)
        Description copied from interface: ConstrainedVisual
        Returns the visual's preferred width given the provided height constraint.
        Specified by:
        getPreferredWidth in interface ConstrainedVisual
        Parameters:
        height - The height by which to constrain the preferred width, or -1 for no constraint.
        Returns:
        The preferred width given the height constraint.
      • getPreferredHeight

        public int getPreferredHeight​(int width)
        Description copied from interface: ConstrainedVisual
        Returns the visual's preferred height given the provided width constraint.
        Specified by:
        getPreferredHeight in interface ConstrainedVisual
        Parameters:
        width - The width by which to constrain the preferred height, or -1 for no constraint.
        Returns:
        The preferred height given the width constraint.
      • getBaseline

        public int getBaseline​(int width,
                               int height)
        Description copied from class: ComponentSkin
        Should be implemented in every subclass.

        The default implementation here simply returns -1 (no baseline).

        Specified by:
        getBaseline in interface ConstrainedVisual
        Overrides:
        getBaseline in class ComponentSkin
        Parameters:
        width - Constrained width to compute the baseline for.
        height - Constrained height to compute the baseline for.
        Returns:
        The baseline relative to the origin of this visual, or -1 if this visual does not have a baseline.
      • layout

        public void layout()
        Description copied from interface: Skin
        If the component on which the skin is installed is a container, lays out the container's children.
        Specified by:
        layout in interface Skin
      • paint

        public void paint​(java.awt.Graphics2D graphics)
        Description copied from interface: Visual
        Paints the visual.
        Specified by:
        paint in interface Visual
        Parameters:
        graphics - The graphics context in which to paint the visual.
      • getInsertionPoint

        public int getInsertionPoint​(int x)
        Calculate the text insertion point given the mouse X-position relative to the component's X-position.

        Note: if the given X-position is on the right-hand side of a glyph then the insertion point will be after that character, while an X-position within the left half of a glyph will position the insert before that character.

        Specified by:
        getInsertionPoint in interface TextInput.Skin
        Parameters:
        x - The relative X-position.
        Returns:
        The offset into the text determined by the X-position.
      • getCharacterBounds

        public Bounds getCharacterBounds​(int index)
        Determine the bounding box of the character at the given index in the text in coordinates relative to the entire component (that is, adding in the insets and padding, etc.).
        Specified by:
        getCharacterBounds in interface TextInput.Skin
        Parameters:
        index - The 0-based index of the character to inquire about.
        Returns:
        The bounding box within the component where that character will be displayed, or null if there is no text.
      • getFont

        public final java.awt.Font getFont()
      • setFont

        public final void setFont​(java.awt.Font newFont)
        Set the new font to use to render the text in this component.

        Also calculate the averageCharacterSize value based on this font, which will be the width of the "missing glyph code" and the maximum height of any character in the font.

        Parameters:
        newFont - The new font to use.
        Throws:
        java.lang.IllegalArgumentException - if the newFont argument is null.
      • setFont

        public final void setFont​(java.lang.String fontString)
      • setFont

        public final void setFont​(Dictionary<java.lang.String,​?> fontDict)
      • getColor

        public final java.awt.Color getColor()
      • setColor

        public final void setColor​(java.awt.Color colorValue)
      • setColor

        public final void setColor​(java.lang.String colorString)
      • setColor

        public final void setColor​(int colorIndex)
      • getPromptColor

        public final java.awt.Color getPromptColor()
      • setPromptColor

        public final void setPromptColor​(java.awt.Color colorValue)
      • setPromptColor

        public final void setPromptColor​(java.lang.String colorString)
      • setPromptColor

        public final void setPromptColor​(int colorIndex)
      • getDisabledColor

        public final java.awt.Color getDisabledColor()
      • setDisabledColor

        public final void setDisabledColor​(java.awt.Color colorValue)
      • setDisabledColor

        public final void setDisabledColor​(java.lang.String colorString)
      • setDisabledColor

        public final void setDisabledColor​(int colorIndex)
      • getBackgroundColor

        public final java.awt.Color getBackgroundColor()
      • setBackgroundColor

        public final void setBackgroundColor​(java.awt.Color colorValue)
      • setBackgroundColor

        public final void setBackgroundColor​(java.lang.String colorString)
      • setBackgroundColor

        public final void setBackgroundColor​(int colorIndex)
      • getInvalidColor

        public final java.awt.Color getInvalidColor()
      • setInvalidColor

        public final void setInvalidColor​(java.awt.Color colorValue)
      • setInvalidColor

        public final void setInvalidColor​(java.lang.String colorString)
      • setInvalidColor

        public final void setInvalidColor​(int colorIndex)
      • getInvalidBackgroundColor

        public final java.awt.Color getInvalidBackgroundColor()
      • setInvalidBackgroundColor

        public final void setInvalidBackgroundColor​(java.awt.Color colorValue)
      • setInvalidBackgroundColor

        public final void setInvalidBackgroundColor​(java.lang.String colorString)
      • setInvalidBackgroundColor

        public final void setInvalidBackgroundColor​(int colorIndex)
      • getDisabledBackgroundColor

        public final java.awt.Color getDisabledBackgroundColor()
      • setDisabledBackgroundColor

        public final void setDisabledBackgroundColor​(java.awt.Color colorValue)
      • setDisabledBackgroundColor

        public final void setDisabledBackgroundColor​(java.lang.String colorString)
      • setDisabledBackgroundColor

        public final void setDisabledBackgroundColor​(int colorIndex)
      • getBorderColor

        public final java.awt.Color getBorderColor()
      • setBorderColor

        public final void setBorderColor​(java.awt.Color colorValue)
      • setBorderColor

        public final void setBorderColor​(java.lang.String colorString)
      • setBorderColor

        public final void setBorderColor​(int colorIndex)
      • getDisabledBorderColor

        public final java.awt.Color getDisabledBorderColor()
      • setDisabledBorderColor

        public final void setDisabledBorderColor​(java.awt.Color colorValue)
      • setDisabledBorderColor

        public final void setDisabledBorderColor​(java.lang.String colorString)
      • setDisabledBorderColor

        public final void setDisabledBorderColor​(int colorIndex)
      • getSelectionColor

        public final java.awt.Color getSelectionColor()
      • setSelectionColor

        public final void setSelectionColor​(java.awt.Color colorValue)
      • setSelectionColor

        public final void setSelectionColor​(java.lang.String colorString)
      • setSelectionColor

        public final void setSelectionColor​(int colorIndex)
      • getSelectionBackgroundColor

        public final java.awt.Color getSelectionBackgroundColor()
      • setSelectionBackgroundColor

        public final void setSelectionBackgroundColor​(java.awt.Color colorValue)
      • setSelectionBackgroundColor

        public final void setSelectionBackgroundColor​(java.lang.String colorString)
      • setSelectionBackgroundColor

        public final void setSelectionBackgroundColor​(int colorIndex)
      • getInactiveSelectionColor

        public final java.awt.Color getInactiveSelectionColor()
      • setInactiveSelectionColor

        public final void setInactiveSelectionColor​(java.awt.Color colorValue)
      • setInactiveSelectionColor

        public final void setInactiveSelectionColor​(java.lang.String colorString)
      • setInactiveSelectionColor

        public final void setInactiveSelectionColor​(int colorIndex)
      • getInactiveSelectionBackgroundColor

        public final java.awt.Color getInactiveSelectionBackgroundColor()
      • setInactiveSelectionBackgroundColor

        public final void setInactiveSelectionBackgroundColor​(java.awt.Color colorValue)
      • setInactiveSelectionBackgroundColor

        public final void setInactiveSelectionBackgroundColor​(java.lang.String colorString)
      • setInactiveSelectionBackgroundColor

        public final void setInactiveSelectionBackgroundColor​(int colorIndex)
      • getPadding

        public final Insets getPadding()
      • setPadding

        public final void setPadding​(Insets paddingValue)
      • setPadding

        public final void setPadding​(Dictionary<java.lang.String,​?> paddingDictionary)
      • setPadding

        public final void setPadding​(Sequence<?> paddingSequence)
      • setPadding

        public final void setPadding​(int paddingValue)
      • setPadding

        public final void setPadding​(java.lang.Number paddingValue)
      • setPadding

        public final void setPadding​(java.lang.String paddingString)
      • setHorizontalAlignment

        public final void setHorizontalAlignment​(HorizontalAlignment alignment)
      • mouseMove

        public boolean mouseMove​(Component component,
                                 int x,
                                 int y)
        Description copied from interface: ComponentMouseListener
        Called when the mouse is moved over a component.
        Specified by:
        mouseMove in interface ComponentMouseListener
        Overrides:
        mouseMove in class ComponentSkin
        Parameters:
        component - Component that is under the mouse.
        x - X position of the mouse.
        y - Y position of the mouse.
        Returns:
        true to consume the event; false to allow it to propagate (default return).
      • mouseDown

        public boolean mouseDown​(Component component,
                                 Mouse.Button button,
                                 int x,
                                 int y)
        Description copied from interface: ComponentMouseButtonListener
        Called when a mouse button is pressed over a component.
        Specified by:
        mouseDown in interface ComponentMouseButtonListener
        Overrides:
        mouseDown in class ComponentSkin
        Parameters:
        component - Component that is under the mouse pointer.
        button - Which mouse button was pressed.
        x - X position of the mouse.
        y - Y position of the mouse.
        Returns:
        true to consume the event; false to allow it to propagate (default).
      • mouseUp

        public boolean mouseUp​(Component component,
                               Mouse.Button button,
                               int x,
                               int y)
        Description copied from interface: ComponentMouseButtonListener
        Called when a mouse button is released over a component.
        Specified by:
        mouseUp in interface ComponentMouseButtonListener
        Overrides:
        mouseUp in class ComponentSkin
        Parameters:
        component - Component user the mouse pointer.
        button - Which mouse button that was released.
        x - X position of the mouse.
        y - Y position of the mouse.
        Returns:
        true to consume the event; false to allow it to propagate (default).
      • mouseClick

        public boolean mouseClick​(Component component,
                                  Mouse.Button button,
                                  int x,
                                  int y,
                                  int count)
        Description copied from interface: ComponentMouseButtonListener
        Called when a mouse button is clicked over a component.
        Specified by:
        mouseClick in interface ComponentMouseButtonListener
        Overrides:
        mouseClick in class ComponentSkin
        Parameters:
        component - Component user the mouse pointer.
        button - Which mouse button was clicked.
        x - X position of the mouse.
        y - Y position of the mouse.
        count - Number of clicks (1 = single click, 2 = double click, etc.).
        Returns:
        true to consume the event; false to allow it to propagate (default).
      • keyTyped

        public boolean keyTyped​(Component component,
                                char character)
        Description copied from interface: ComponentKeyListener
        Called when a key has been typed.
        Specified by:
        keyTyped in interface ComponentKeyListener
        Overrides:
        keyTyped in class ComponentSkin
        Parameters:
        component - Component that has the focus, that is receiving this key.
        character - The decoded character that was typed.
        Returns:
        true to consume the event; false to allow it to propagate.
      • keyPressed

        public boolean keyPressed​(Component component,
                                  int keyCode,
                                  Keyboard.KeyLocation keyLocation)
        DELETE Delete the character after the caret or the entire selection if there is one.
        BACKSPACE Delete the character before the caret or the entire selection if there is one.

        HOME Move the caret to the beginning of the text.
        LEFT + META Move the caret to the beginning of the text.

        HOME + SHIFT Select from the caret to the beginning of the text.
        LEFT + META + SHIFT Select from the caret to the beginning of the text.

        END Move the caret to the end of the text.
        RIGHT + META Move the caret to the end of the text.

        END + SHIFT Select from the caret to the end of the text.
        RIGHT + META + SHIFT Select from the caret to the end of the text.

        LEFT Clear the selection and move the caret back by one character.
        LEFT + SHIFT Add the previous character to the selection.
        LEFT + CTRL Clear the selection and move the caret to the beginning of the text.
        LEFT + CTRL + SHIFT Add all preceding text to the selection.

        RIGHT Clear the selection and move the caret forward by one character.
        RIGHT + SHIFT Add the next character to the selection.
        RIGHT + CTRL Clear the selection and move the caret to the end of the text.
        RIGHT + CTRL + SHIFT Add all subsequent text to the selection.

        CommandModifier + A Select all.
        CommandModifier + X Cut selection to clipboard (if not a password TextInput).
        CommandModifier + C Copy selection to clipboard (if not a password TextInput).
        CommandModifier + V Paste from clipboard.
        CommandModifier + Z Undo.

        Specified by:
        keyPressed in interface ComponentKeyListener
        Overrides:
        keyPressed in class ComponentSkin
        Parameters:
        component - Component that has the focus.
        keyCode - The key code for the key that was pressed.
        keyLocation - Location value for the key (left or right for shift keys, etc.).
        Returns:
        true to consume the event; false to allow it to propagate.
        See Also:
        Platform.getCommandModifier()
      • enabledChanged

        public void enabledChanged​(Component component)
        Description copied from interface: ComponentStateListener
        Called when a component's enabled state has changed.

        Called both when the component is enabled and when it is disabled. The component's enabled flag has already been set when this method is called so the new state can be determined by calling the Component.isEnabled() method.

        Specified by:
        enabledChanged in interface ComponentStateListener
        Overrides:
        enabledChanged in class ComponentSkin
        Parameters:
        component - The component whose enabled state is changing.
      • focusedChanged

        public void focusedChanged​(Component component,
                                   Component obverseComponent)
        Description copied from interface: ComponentStateListener
        Called when a component's focused state has changed.

        This will be called both when a component gains focus and when it loses focus. The currently focused component has already been set when this method is called, so that the new state of the component can be determined by calling the Component.isFocused() method.

        Specified by:
        focusedChanged in interface ComponentStateListener
        Overrides:
        focusedChanged in class ComponentSkin
        Parameters:
        component - The component that is either gaining focus or the one that previously had focus and is now losing it.
        obverseComponent - If the component is gaining focus, this is the component that is losing focus. If the component is losing focus this is the component that is gaining the focus instead.
      • textSizeChanged

        public void textSizeChanged​(TextInput textInput,
                                    int previousTextSize)
        Description copied from interface: TextInputListener
        Called when a text input's text size has changed.
        Specified by:
        textSizeChanged in interface TextInputListener
        Parameters:
        textInput - The source of this event.
        previousTextSize - The previous text size for the control
      • maximumLengthChanged

        public void maximumLengthChanged​(TextInput textInput,
                                         int previousMaximumLength)
        Description copied from interface: TextInputListener
        Called when a text input's maximum length has changed.
        Specified by:
        maximumLengthChanged in interface TextInputListener
        Parameters:
        textInput - The source of this event.
        previousMaximumLength - The previous maximum text length.
      • passwordChanged

        public void passwordChanged​(TextInput textInput)
        Description copied from interface: TextInputListener
        Called when a text input's password flag has changed.
        Specified by:
        passwordChanged in interface TextInputListener
        Parameters:
        textInput - The source of this event.
      • promptChanged

        public void promptChanged​(TextInput textInput,
                                  java.lang.String previousPrompt)
        Description copied from interface: TextInputListener
        Called when a text input's prompt has changed.
        Specified by:
        promptChanged in interface TextInputListener
        Parameters:
        textInput - The source of this event.
        previousPrompt - The previous prompt string.
      • textValidatorChanged

        public void textValidatorChanged​(TextInput textInput,
                                         Validator previousValidator)
        Description copied from interface: TextInputListener
        Called when the validator changes.
        Specified by:
        textValidatorChanged in interface TextInputListener
        Parameters:
        textInput - The source of this event.
        previousValidator - The previous validator for the text.
      • strictValidationChanged

        public void strictValidationChanged​(TextInput textInput)
        Description copied from interface: TextInputListener
        Called when a text input's strict validation flag has changed.
        Specified by:
        strictValidationChanged in interface TextInputListener
        Parameters:
        textInput - The text input that has changed.
      • previewInsertText

        public Vote previewInsertText​(TextInput textInput,
                                      java.lang.CharSequence text,
                                      int index)
        Description copied from interface: TextInputContentListener
        Called to preview a text insertion.
        Specified by:
        previewInsertText in interface TextInputContentListener
        Parameters:
        textInput - The source of the event.
        text - The text that will be inserted.
        index - The index at which the text will be inserted.
        Returns:
        The accumulated vote as to whether to allow this insertion.
      • textInserted

        public void textInserted​(TextInput textInput,
                                 int index,
                                 int count)
        Description copied from interface: TextInputContentListener
        Called when text has been inserted into a text input.
        Specified by:
        textInserted in interface TextInputContentListener
        Parameters:
        textInput - The source of the event.
        index - The index at which the text was inserted.
        count - The number of characters that were inserted.
      • previewRemoveText

        public Vote previewRemoveText​(TextInput textInput,
                                      int index,
                                      int count)
        Description copied from interface: TextInputContentListener
        Called to preview a text removal.
        Specified by:
        previewRemoveText in interface TextInputContentListener
        Parameters:
        textInput - The source of the event.
        index - The starting index from which the text will be removed.
        count - The count of characters to be removed starting from that index.
        Returns:
        The accumulated vote as to whether to allow this removal.
      • setSize

        public void setSize​(int width,
                            int height)
        Description copied from class: ComponentSkin
        Set the final size of the component after layout has finished.

        All subclasses must call this superclass method in order to set the ComponentSkin.width and ComponentSkin.height values, but may need to do additional calculations before doing so.

        Specified by:
        setSize in interface ConstrainedVisual
        Overrides:
        setSize in class ComponentSkin
        Parameters:
        width - The new (final) width of the component after layout.
        height - The new (final) height of the component after layout.
      • textRemoved

        public void textRemoved​(TextInput textInput,
                                int index,
                                int count)
        Description copied from interface: TextInputContentListener
        Called when text has been removed from a text input.
        Specified by:
        textRemoved in interface TextInputContentListener
        Parameters:
        textInput - The source of the event.
        index - The index from which the text was removed.
        count - The number of characters that were removed.
      • editableChanged

        public void editableChanged​(TextInput textInput)
        Description copied from interface: TextInputListener
        Called when the editable state has changed.
        Specified by:
        editableChanged in interface TextInputListener
        Parameters:
        textInput - The text input whose state has changed.
      • selectionChanged

        public void selectionChanged​(TextInput textInput,
                                     int previousSelectionStart,
                                     int previousSelectionLength)
        Description copied from interface: TextInputSelectionListener
        Called when a text input's selection state has changed.
        Specified by:
        selectionChanged in interface TextInputSelectionListener
        Parameters:
        textInput - The source of the event.
        previousSelectionStart - If the selection changed directly, the previous selection start index. Otherwise, the current selection start index.
        previousSelectionLength - If the selection changed directly, the previous selection length. Otherwise, the current selection length.
      • showCaret

        public void showCaret​(boolean show)
      • getTextInputMethodListener

        public TextInputMethodListener getTextInputMethodListener()
        Description copied from class: ComponentSkin
        Returns the input method listener for this component.

        Should be overridden by any component's skin that wants to handle Input Method events (such as TextInput).

        Overrides:
        getTextInputMethodListener in class ComponentSkin
        Returns:
        The input method listener (if any) for this component.