Package furbelow

Class AbstractComponentDecorator

java.lang.Object
furbelow.AbstractComponentDecorator
Direct Known Subclasses:
GhostedDragImage, ListAnimator, TreeAnimator, WaitIndicator

public abstract class AbstractComponentDecorator extends Object
Provide a method for consistently augmenting the appearance of a given component by painting something on it after the component itself gets painted. If not explicitly removed via dispose(), an instance of this object will live as long as its target component.

By default, the decorator matches the location and size of the decorated component, but the bounds can be adjusted by overriding getDecorationBounds(). The synch() method should be called whenever the bounds returned by getDecorationBounds() would change.

The decoration is clipped to the bounds set on the decoration, which does not necessarily need to be the same as the decorated component's bounds. The decoration may extend beyond the decorated component bounds, or it may be reduced to a smaller region.

  • Field Details

  • Constructor Details

    • AbstractComponentDecorator

      public AbstractComponentDecorator(JComponent c)
      Create a decorator for the given component.
    • AbstractComponentDecorator

      public AbstractComponentDecorator(JComponent c, int layerOffset)
      Create a decorator for the given component, indicating the layer offset from the target component. Negative values mean the decoration is painted before the target component is painted.
    • AbstractComponentDecorator

      public AbstractComponentDecorator(JComponent c, int layerOffset, int position)
      Create a decorator with the given position within its layer. Use TOP to cover other decorations, or BOTTOM to be covered by other decorations.

      WARNING: BOTTOM doesn't currently work, probably a JLayeredPane bug in either the code or documentation.

      See Also:
  • Method Details

    • setToolTipText

      public void setToolTipText(String text)
      Set the text to be displayed when the mouse is over the decoration.
      See Also:
    • getToolTipText

      public String getToolTipText()
      Return the currently set default tooltip text.
      See Also:
    • getToolTipText

      public String getToolTipText(MouseEvent e)
      Provide for different tool tips depending on the actual location over the decoration. Note that if you only override this method, you must also invoke setToolTipText(String) with a non-null argument.
      See Also:
    • isVisible

      public boolean isVisible()
      Indicate whether the decoration is visible. The decoration may be clipped by ancestor scroll panes or by being moved outside if the visible region of its parent window.
    • setVisible

      public void setVisible(boolean visible)
      Use this to change the visibility of the decoration.
    • attach

      protected void attach()
    • synch

      protected void synch()
      Ensure the size of the decorator matches the current decoration bounds with appropriate clipping to viewports.
    • clipDecorationBounds

      protected Rectangle clipDecorationBounds(Rectangle decorated)
      Adjust the painting offsets and size of the decoration to account for ancestor clipping. This might be due to scroll panes or having the decoration lie outside the parent layered pane.
    • getDecorationBounds

      protected Rectangle getDecorationBounds()
      Return the bounds, relative to the decorated component, of the decoration. The default covers the entire component. Note that this method will be called from the constructor, so be careful when overriding and referencing derived class state.
    • setDecorationBounds

      public void setDecorationBounds(Rectangle bounds)
      Change the bounds of the decoration, relative to the decorated component. The special value DEFAULT_BOUNDS means the bounds will track the component bounds.
    • setDecorationBounds

      public void setDecorationBounds(int x, int y, int w, int h)
      Change the bounds of the decoration, relative to the decorated component.
    • setPainterBounds

      protected void setPainterBounds(int x, int y, int w, int h)
    • getComponent

      protected JComponent getComponent()
      Returns the decorated component.
    • getPainter

      protected JComponent getPainter()
      Returns the component used to paint the decoration and optionally track events.
    • setCursor

      public void setCursor(Cursor cursor)
      Set the cursor to appear anywhere over the decoration bounds. If null, the cursor of the decorated component will be used.
    • repaint

      public void repaint()
      Force a refresh of the underlying component and its decoration.
    • dispose

      public void dispose()
      Stop decorating.
    • paint

      public abstract void paint(Graphics g)
      Define the decoration's appearance. The point (0,0) represents the upper left corner of the decorated component. The default clip mask will be the extents of the decoration bounds, as indicated by getDecorationBounds(), which defaults to the decorated component bounds.
    • toString

      public String toString()
      Overrides:
      toString in class Object