Class ComponentSkin

    • Constructor Detail

      • ComponentSkin

        public ComponentSkin()
    • Method Detail

      • getWidth

        public final int getWidth()
        Description copied from interface: Visual
        Returns the visual's width.
        Specified by:
        getWidth in interface Visual
        Returns:
        Current width of this visual.
      • getHeight

        public final int getHeight()
        Description copied from interface: Visual
        Returns the visual's height.
        Specified by:
        getHeight in interface Visual
        Returns:
        Current height of this visual.
      • getSize

        public final Dimensions getSize()
        Description copied from interface: Visual
        Default method to return the visual's complete size via a Dimensions object. Note that if the width and height calculations for a particular object are lengthy and could be better done together rather than separately, that component should be free to override this default implementation.
        Specified by:
        getSize in interface Visual
        Returns:
        The visual's complete size.
      • setSize

        public void setSize​(int newWidth,
                            int newHeight)
        Set the final size of the component after layout has finished.

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

        Specified by:
        setSize in interface ConstrainedVisual
        Parameters:
        newWidth - The new (final) width of the component after layout.
        newHeight - The new (final) height of the component after layout.
      • getBaseline

        public final int getBaseline()
        Description copied from interface: Visual
        Returns the visual's baseline.
        Specified by:
        getBaseline in interface Visual
        Returns:
        The baseline relative to the origin of the visual, or -1 if this visual does not have a baseline.
      • getBaseline

        public int getBaseline​(int trialWidth,
                               int trialHeight)
        Should be implemented in every subclass.

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

        Specified by:
        getBaseline in interface ConstrainedVisual
        Parameters:
        trialWidth - Constrained width to compute the baseline for.
        trialHeight - 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.
      • install

        public void install​(Component component)
        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
        Parameters:
        component - The component to which the skin is being attached.
      • getComponent

        public final Component getComponent()
        Description copied from interface: Skin
        Returns the component with which a skin is associated.
        Specified by:
        getComponent in interface Skin
        Returns:
        The installed component for this skin instance, set by install(org.apache.pivot.wtk.Component) (which therefore must be called by every subclass).
      • isFocusable

        public boolean isFocusable()
        By default, skins are focusable.
        Specified by:
        isFocusable in interface Skin
        Returns:
        true if this skin is focusable; false, otherwise.
      • isOpaque

        public boolean isOpaque()
        By default, skins are assumed to be opaque.
        Specified by:
        isOpaque in interface Skin
        Returns:
        true if this skin is opaque; false if any part of it is transparent or translucent.
      • parentChanged

        public void parentChanged​(Component component,
                                  Container previousParent)
        Description copied from interface: ComponentListener
        Called when a component's parent has changed (when the component is either added to or removed from a container).
        Specified by:
        parentChanged in interface ComponentListener
        Parameters:
        component - The component whose parent changed.
        previousParent - Previous parent of this component.
      • sizeChanged

        public void sizeChanged​(Component component,
                                int previousWidth,
                                int previousHeight)
        Description copied from interface: ComponentListener
        Called when a component's size has changed.
        Specified by:
        sizeChanged in interface ComponentListener
        Parameters:
        component - Component that changed size.
        previousWidth - Previous width of this component.
        previousHeight - Previous height of this component.
      • preferredSizeChanged

        public void preferredSizeChanged​(Component component,
                                         int previousPreferredWidth,
                                         int previousPreferredHeight)
        Description copied from interface: ComponentListener
        Called when a component's preferred size has changed.
        Specified by:
        preferredSizeChanged in interface ComponentListener
        Parameters:
        component - Component that changed.
        previousPreferredWidth - Previous value of the preferred width for this component.
        previousPreferredHeight - Previous preferred height for this component.
      • widthLimitsChanged

        public void widthLimitsChanged​(Component component,
                                       int previousMinimumWidth,
                                       int previousMaximumWidth)
        Description copied from interface: ComponentListener
        Called when a component's preferred width limits have changed.
        Specified by:
        widthLimitsChanged in interface ComponentListener
        Parameters:
        component - Component that changed.
        previousMinimumWidth - Previously specified preferred minimum width.
        previousMaximumWidth - Previous value of the preferred maximum width.
      • heightLimitsChanged

        public void heightLimitsChanged​(Component component,
                                        int previousMinimumHeight,
                                        int previousMaximumHeight)
        Description copied from interface: ComponentListener
        Called when a component's preferred height limits have changed.
        Specified by:
        heightLimitsChanged in interface ComponentListener
        Parameters:
        component - Component that has changed.
        previousMinimumHeight - Previously given minimum height value.
        previousMaximumHeight - Previous maximum height value.
      • locationChanged

        public void locationChanged​(Component component,
                                    int previousX,
                                    int previousY)
        Description copied from interface: ComponentListener
        Called when a component's location has changed.
        Specified by:
        locationChanged in interface ComponentListener
        Parameters:
        component - Component that has moved.
        previousX - The previous X position of the component.
        previousY - The previous Y position.
      • visibleChanged

        public void visibleChanged​(Component component)
        Description copied from interface: ComponentListener
        Called when a component's visible flag has changed.
        Specified by:
        visibleChanged in interface ComponentListener
        Parameters:
        component - Component that has changed visibility.
      • cursorChanged

        public void cursorChanged​(Component component,
                                  Cursor previousCursor)
        Description copied from interface: ComponentListener
        Called when a component's cursor has changed.
        Specified by:
        cursorChanged in interface ComponentListener
        Parameters:
        component - Component whose cursor has changed.
        previousCursor - Previous cursor for this component.
      • tooltipTextChanged

        public void tooltipTextChanged​(Component component,
                                       java.lang.String previousTooltipText)
        Description copied from interface: ComponentListener
        Called when a component's tooltip text has changed.
        Specified by:
        tooltipTextChanged in interface ComponentListener
        Parameters:
        component - Component that changed.
        previousTooltipText - Previous value of this component's tooltip text.
      • tooltipDelayChanged

        public void tooltipDelayChanged​(Component component,
                                        int previousTooltipDelay)
        Description copied from interface: ComponentListener
        Called when a component's tooltip delay has changed.
        Specified by:
        tooltipDelayChanged in interface ComponentListener
        Parameters:
        component - The component we're dealing with.
        previousTooltipDelay - The previous tooltip delay for this component.
      • dragSourceChanged

        public void dragSourceChanged​(Component component,
                                      DragSource previousDragSource)
        Description copied from interface: ComponentListener
        Called when a component's drag source has changed.
        Specified by:
        dragSourceChanged in interface ComponentListener
        Parameters:
        component - The component in question.
        previousDragSource - The previous value of the DragSource for this component.
      • dropTargetChanged

        public void dropTargetChanged​(Component component,
                                      DropTarget previousDropTarget)
        Description copied from interface: ComponentListener
        Called when a component's drop target has changed.
        Specified by:
        dropTargetChanged in interface ComponentListener
        Parameters:
        component - The component that is changing.
        previousDropTarget - The previous value of the DropTarget for this component.
      • menuHandlerChanged

        public void menuHandlerChanged​(Component component,
                                       MenuHandler previousMenuHandler)
        Description copied from interface: ComponentListener
        Called when a component's context menu handler has changed.
        Specified by:
        menuHandlerChanged in interface ComponentListener
        Parameters:
        component - The component that has changed.
        previousMenuHandler - The previous menu handler object for this component.
      • nameChanged

        public void nameChanged​(Component component,
                                java.lang.String previousName)
        Description copied from interface: ComponentListener
        Called when a component's name has changed.
        Specified by:
        nameChanged in interface ComponentListener
        Parameters:
        component - Component whose name changed.
        previousName - Previous name for this component.
      • 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
        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
        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.
      • 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
        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).
      • mouseOver

        public void mouseOver​(Component component)
        Description copied from interface: ComponentMouseListener
        Called when the mouse enters a component.

        Default is to do nothing.

        Specified by:
        mouseOver in interface ComponentMouseListener
        Parameters:
        component - Component that is now under the mouse pointer.
      • mouseOut

        public void mouseOut​(Component component)
        Description copied from interface: ComponentMouseListener
        Called when the mouse exits a component.

        Default is to do nothing.

        Specified by:
        mouseOut in interface ComponentMouseListener
        Parameters:
        component - Component that has now lost the mouse pointer.
      • 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
        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
        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
        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).
      • mouseWheel

        public boolean mouseWheel​(Component component,
                                  Mouse.ScrollType scrollType,
                                  int scrollAmount,
                                  int wheelRotation,
                                  int x,
                                  int y)
        Description copied from interface: ComponentMouseWheelListener
        Called when the mouse wheel is scrolled over a component.
        Specified by:
        mouseWheel in interface ComponentMouseWheelListener
        Parameters:
        component - Component under the mouse pointer.
        scrollType - What type of scroll was requested on the mouse.
        scrollAmount - Amount of scrolling.
        wheelRotation - Rotation value.
        x - X position of the mouse.
        y - Y position of the mouse.
        Returns:
        true to consume the event; false to allow it to propagate.
      • 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
        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)
        Keyboard handling (Tab key or Shift Tab).
        • TAB Transfers focus forwards
        • TAB + SHIFT Transfers focus backwards
        Specified by:
        keyPressed in interface ComponentKeyListener
        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.
      • keyReleased

        public boolean keyReleased​(Component component,
                                   int keyCode,
                                   Keyboard.KeyLocation keyLocation)
        Description copied from interface: ComponentKeyListener
        Called when a key has been released.
        Specified by:
        keyReleased in interface ComponentKeyListener
        Parameters:
        component - Component that has the focus, that is receiving this key event.
        keyCode - Code for the key that was released.
        keyLocation - Location of the key.
        Returns:
        true to consume the event; false to allow it to propagate.
      • tooltipTriggered

        public void tooltipTriggered​(Component component,
                                     int x,
                                     int y)
        Description copied from interface: ComponentTooltipListener
        Called when a tooltip has been triggered over a component.
        Specified by:
        tooltipTriggered in interface ComponentTooltipListener
        Parameters:
        component - The component in question.
        x - X position of the mouse.
        y - Y position of the mouse.
      • invalidateComponent

        protected void invalidateComponent()
        Mark the component's entire size as invalid, to be repainted when the event queue is empty.
      • repaintComponent

        protected void repaintComponent()
        Repaint the entire component when the event queue is empty.
      • repaintComponent

        protected void repaintComponent​(boolean immediate)
        Repaint the entire component with the option to do so immediately (vs. when the event queue is empty).
        Parameters:
        immediate - true to repaint the entire component now.
      • repaintComponent

        protected void repaintComponent​(Bounds area)
        Repaint the given area of the component when the event queue is empty.
        Parameters:
        area - The bounding box of the area to be repainted.
      • repaintComponent

        protected void repaintComponent​(int x,
                                        int y,
                                        int areaWidth,
                                        int areaHeight)
        Repaint the area of the component specified by the given location and size when the event queue is empty.
        Parameters:
        x - The starting X-position to paint.
        y - The starting Y-position to paint.
        areaWidth - The width of the area to repaint.
        areaHeight - The height of the area to repaint.
      • repaintComponent

        protected void repaintComponent​(int x,
                                        int y,
                                        int areaWidth,
                                        int areaHeight,
                                        boolean immediate)
        Repaint the area of the component specified by the given location and size with the option to do so immediately or when the event queue is empty.
        Parameters:
        x - The starting X-position to paint.
        y - The starting Y-position to paint.
        areaWidth - The width of the area to repaint.
        areaHeight - The height of the area to repaint.
        immediate - true to repaint the given area now.
      • decodeFont

        public static final java.awt.Font decodeFont​(java.lang.String value)
        Interpret a string as a font specification.
        Parameters:
        value - Either a JSON dictionary describing a font relative to the current theme, or one of the standard Java font specifications, with the additional capability of supplying a list of font names (comma-separated) (similar to CSS) if desired.
        Returns:
        The font corresponding to the specification.
        Throws:
        java.lang.IllegalArgumentException - if the given string is null or empty or the font specification cannot be decoded.
        See Also:
        FontUtilities.decodeFont(String)
      • currentTheme

        public final Theme currentTheme()
        Returns the current Theme.
        Returns:
        The currently loaded theme.
      • themeIsDark

        public final boolean themeIsDark()
        Returns whether the current Theme is dark. Usually this means that (if true) any color will be transformed in the opposite way.
        Returns:
        true if it is dark, false otherwise (default)
      • themeIsFlat

        public final boolean themeIsFlat()
        Returns whether the current Theme is flat. Note that flat themes usually have no bevel, gradients, shadow effects, and in some cases even no borders.
        Returns:
        true if it is flat, false otherwise (default)
      • themeHasTransitionEnabled

        public final boolean themeHasTransitionEnabled()
        Returns whether the current Theme has transitions enabled.
        Returns:
        true if transitions are enabled (default), false otherwise
      • themeHasThickFocusRectangle

        public final boolean themeHasThickFocusRectangle()
        Returns whether the current Theme has thick focus rectangles.
        Returns:
        true if thick focus rectangles are drawn (new default), or false otherwise (default for previous versions).
      • defaultBackgroundColor

        public final java.awt.Color defaultBackgroundColor()
        Returns the Theme default background color.
        Returns:
        Color.WHITE if the theme is not dark (default), or Color.BLACK.
      • defaultForegroundColor

        public final java.awt.Color defaultForegroundColor()
        Returns the Theme default foreground color.
        Returns:
        Color.BLACK if the theme is not dark (default), or Color.WHITE.
      • getFocusRectangleStroke

        public final java.awt.BasicStroke getFocusRectangleStroke()
        Returns a dashed line stroke for drawing focus rectangles, based on the current theme setting for "thick" ones.
        Returns:
        A line stroke object with the correct thickness and dash pattern.
      • getColor

        public final java.awt.Color getColor​(int index)
        Returns the current theme color indicated by the index value.
        Parameters:
        index - Index into the theme's color palette.
        Returns:
        The current theme color value.
      • colorFromObject

        public final java.awt.Color colorFromObject​(java.lang.Object colorValue,
                                                    boolean allowNull)
        Interpret an object as a color value.
        Parameters:
        colorValue - One of a String (interpreted by GraphicsUtilities.decodeColor(String,String)), a straight Color, one of our CSSColor values, or an integer index into the theme's color palette.
        allowNull - Whether or not to allow a null color.
        Returns:
        The real Color value.
        Throws:
        java.lang.IllegalArgumentException - if the colorValue is null (unless allowNull is true), or of a type we don't recognize.
        See Also:
        ColorUtilities.fromObject(java.lang.Object, java.lang.String, boolean)
      • getThemeFont

        public final java.awt.Font getThemeFont()
        Returns the current font setting for the theme.
        Returns:
        The default font for the theme.
      • setDefaultStyles

        public final void setDefaultStyles()
        Sets the default styles for this skin by calling Theme.setDefaultStyles(T) with the current skin object.
      • getTextInputMethodListener

        public TextInputMethodListener getTextInputMethodListener()
        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).

        Returns:
        The input method listener (if any) for this component.