abbot.editor.widgets
Class AbstractComponentDecorator

java.lang.Object
  extended by abbot.editor.widgets.AbstractComponentDecorator
Direct Known Subclasses:
Highlighter, 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.


Nested Class Summary
protected  class AbstractComponentDecorator.Painter
          Used to hook into the Swing painting and event architecture.
 
Field Summary
static Rectangle DEFAULT_BOUNDS
           
static int TOP
           
 
Constructor Summary
AbstractComponentDecorator(JComponent c)
          Create a decorator for the given component.
AbstractComponentDecorator(JComponent c, int layerOffset)
          Create a decorator for the given component, indicating the layer offset from the target component.
AbstractComponentDecorator(JComponent c, int layerOffset, int position)
          Create a decorator with the given position within its layer.
 
Method Summary
protected  void attach()
           
protected  Rectangle clipDecorationBounds(Rectangle decorated)
          Adjust the painting offsets and size of the decoration to account for ancestor clipping.
 void dispose()
          Stop decorating.
protected  JComponent getComponent()
          Returns the decorated component.
protected  Rectangle getDecorationBounds()
          Return the bounds, relative to the decorated component, of the decoration.
protected  JComponent getPainter()
          Returns the component used to paint the decoration and optionally track events.
 String getToolTipText()
          Return the currently set default tooltip text.
 String getToolTipText(MouseEvent e)
          Provide for different tool tips depending on the actual location over the decoration.
 boolean isShowing()
          Indicate whether the decoration is showing.
 boolean isVisible()
          Indicate whether any of the decoration is visible.
abstract  void paint(Graphics g)
          Define the decoration's appearance.
 void repaint()
          Force a refresh of the underlying component and its decoration.
 void setCursor(Cursor cursor)
          Set the cursor to appear anywhere over the decoration bounds.
 void setDecorationBounds(int x, int y, int w, int h)
          Change the bounds of the decoration, relative to the decorated component.
 void setDecorationBounds(Rectangle bounds)
          Change the bounds of the decoration, relative to the decorated component.
protected  void setPainterBounds(int x, int y, int w, int h)
           
 void setToolTipText(String text)
          Set the text to be displayed when the mouse is over the decoration.
 void setVisible(boolean visible)
          Use this to change the visibility of the decoration.
protected  void synch()
          Ensure the size of the decorator matches the current decoration bounds with appropriate clipping to viewports.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_BOUNDS

public static final Rectangle DEFAULT_BOUNDS

TOP

public static final int TOP
See Also:
Constant Field Values
Constructor Detail

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:
JLayeredPane
Method Detail

setToolTipText

public void setToolTipText(String text)
Set the text to be displayed when the mouse is over the decoration.

See Also:
JComponent.setToolTipText(String)

getToolTipText

public String getToolTipText()
Return the currently set default tooltip text.

See Also:
JComponent.setToolTipText(java.lang.String)

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:
JComponent.getToolTipText(MouseEvent)

isShowing

public boolean isShowing()
Indicate whether the decoration is showing. Its painter must be visible and showing (showing depends on window ancestor).


isVisible

public boolean isVisible()
Indicate whether any of 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


Copyright © 2002-2008 Timothy Wall. All Rights Reserved.
Abbot is hosted on

SourceForge