org.jvnet.lafwidget.layout
Class TransitionLayout

java.lang.Object
  extended by org.jvnet.lafwidget.layout.TransitionLayout
All Implemented Interfaces:
java.awt.LayoutManager

public class TransitionLayout
extends java.lang.Object
implements java.awt.LayoutManager

Transition layout. The public methods in this class that are not implementing the LayoutManager are for look-and-feel usage. Application code should use the getAlphaComposite(Component) and getAlphaComposite(Component, float) methods only in custom painting code (overriding the JComponent.paintComponent(Graphics) method.

Author:
Kirill Grouchnikov.

Field Summary
static java.lang.String ALPHA
          Client property that specifies the current transition state of a component.
static java.lang.String BOUNDS
          Client property for storing the current bounds of a component.
static FadeKind COMPONENT_BOUNDS
          Fade kind for animating the change in component bounds.
static FadeKind COMPONENT_FADE
          Fade kind for animating the change in component visibility.
protected  java.awt.Container container
          The associated container.
protected  java.awt.LayoutManager delegate
          The original layout manager.
protected  boolean doImmediateRepaint
           
protected  java.util.List eventListeners
           
protected  boolean hasFades
           
protected  boolean hasPendingLayoutRequests
           
static java.lang.String LIMBO
          Client property that marks components in fade-out state.
static java.lang.String ORIGINAL_OPACITY
          Client property to store the original opacity of the component while it is in a transition.
static java.lang.String OWN_ALPHA
          Client property that specifies the transition state of a component in a transition that happens directly on that component.
protected  int pendingAnimationCount
           
static java.lang.String SHOWING
          Client property to store the current visibility of components.
 
Constructor Summary
TransitionLayout(java.awt.Container container, java.awt.LayoutManager delegate, boolean hasFades)
           
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component comp)
           
 void addTransitionLayoutListener(TransitionLayoutListener listener)
           
protected static void clearAlpha(java.awt.Component comp, boolean main)
           
protected  void fireEvent(java.awt.Component child, int id)
           
static java.awt.Composite getAlphaComposite(java.awt.Component c)
          Returns the composite to use for painting the specified component.
static java.awt.Composite getAlphaComposite(java.awt.Component c, float translucency)
           
static java.awt.Composite getAlphaComposite(java.awt.Component c, float translucency, java.awt.Graphics g)
          Returns the composite to use for painting the specified component.
static java.awt.Composite getAlphaComposite(java.awt.Component c, java.awt.Graphics g)
          Returns the composite to use for painting the specified component.
protected  float getCompositeAlpha(java.awt.Component c)
          Returns the composite alpha for the specified component.
 java.awt.LayoutManager getDelegate()
           
 boolean isAnimating()
           
static boolean isOpaque(java.awt.Component c)
          Returns indication whether the specified component is opaque.
 void layoutContainer(java.awt.Container parent)
           
static void makeNonOpaque(java.awt.Component comp, java.util.Map opaquenessSnapshot)
          Makes the specified component and all its descendants non-opaque.
 java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
           
 java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
           
 void removeLayoutComponent(java.awt.Component comp)
           
 void removeTransitionLayoutListener(TransitionLayoutListener listener)
           
protected  void repaint(java.awt.Component comp)
           
static void restoreOpaque(java.awt.Component comp, java.util.Map opaquenessSnapshot)
          Restores the opacity of the specified component and all its descendants.
static void setAlpha(java.awt.Component comp, java.lang.Float alpha, java.lang.Float ownAlpha, boolean main)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

delegate

protected java.awt.LayoutManager delegate
The original layout manager. Handles the layout-related tasks.


eventListeners

protected java.util.List eventListeners

ALPHA

public static final java.lang.String ALPHA
Client property that specifies the current transition state of a component. The value is a correct multiplication of all transitions that a component participates in.

See Also:
OWN_ALPHA, getCompositeAlpha(Component), getAlphaComposite(Component), getAlphaComposite(Component, float), Constant Field Values

OWN_ALPHA

public static final java.lang.String OWN_ALPHA
Client property that specifies the transition state of a component in a transition that happens directly on that component.

See Also:
ALPHA, getCompositeAlpha(Component), getAlphaComposite(Component), getAlphaComposite(Component, float), Constant Field Values

ORIGINAL_OPACITY

public static final java.lang.String ORIGINAL_OPACITY
Client property to store the original opacity of the component while it is in a transition. The isOpaque(Component) uses this property to correctly report the "real" component opacity to the painting code.

See Also:
Constant Field Values

SHOWING

public static final java.lang.String SHOWING
Client property to store the current visibility of components. Since we are playing with calls to Component.setVisible(boolean), this property tracks the "real" visibility.

See Also:
Constant Field Values

LIMBO

public static final java.lang.String LIMBO
Client property that marks components in fade-out state. Such components are hidden before layout out the container and reshown afterwards.

See Also:
Constant Field Values

BOUNDS

public static final java.lang.String BOUNDS
Client property for storing the current bounds of a component. This is used to perform animations on components that stay visible but change location.

See Also:
Constant Field Values

container

protected java.awt.Container container
The associated container.


doImmediateRepaint

protected boolean doImmediateRepaint

COMPONENT_BOUNDS

public static final FadeKind COMPONENT_BOUNDS
Fade kind for animating the change in component bounds.


COMPONENT_FADE

public static final FadeKind COMPONENT_FADE
Fade kind for animating the change in component visibility.


hasFades

protected boolean hasFades

hasPendingLayoutRequests

protected boolean hasPendingLayoutRequests

pendingAnimationCount

protected int pendingAnimationCount
Constructor Detail

TransitionLayout

public TransitionLayout(java.awt.Container container,
                        java.awt.LayoutManager delegate,
                        boolean hasFades)
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component comp)
Specified by:
addLayoutComponent in interface java.awt.LayoutManager

layoutContainer

public void layoutContainer(java.awt.Container parent)
Specified by:
layoutContainer in interface java.awt.LayoutManager

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container parent)
Specified by:
minimumLayoutSize in interface java.awt.LayoutManager

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container parent)
Specified by:
preferredLayoutSize in interface java.awt.LayoutManager

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component comp)
Specified by:
removeLayoutComponent in interface java.awt.LayoutManager

makeNonOpaque

public static void makeNonOpaque(java.awt.Component comp,
                                 java.util.Map opaquenessSnapshot)
Makes the specified component and all its descendants non-opaque.

Parameters:
comp - Component.
opaquenessSnapshot - The "snapshot" map that will contain the original opacity status of the specified component and all its descendants.

restoreOpaque

public static void restoreOpaque(java.awt.Component comp,
                                 java.util.Map opaquenessSnapshot)
Restores the opacity of the specified component and all its descendants.

Parameters:
comp - Component.
opaquenessSnapshot - The "snapshot" map that contains the original opacity status of the specified component and all its descendants.

setAlpha

public static void setAlpha(java.awt.Component comp,
                            java.lang.Float alpha,
                            java.lang.Float ownAlpha,
                            boolean main)

clearAlpha

protected static void clearAlpha(java.awt.Component comp,
                                 boolean main)

getDelegate

public java.awt.LayoutManager getDelegate()

getAlphaComposite

public static java.awt.Composite getAlphaComposite(java.awt.Component c,
                                                   float translucency,
                                                   java.awt.Graphics g)
Returns the composite to use for painting the specified component. The result should be set on the Graphics2D before any custom rendering is done. This method can be used by application painting code and by look-and-feel delegates.

Parameters:
c - Component.
translucency - The translucency of the original painting (when the component is not under any transition fade effect).
g - The original graphics context.
Returns:
The composite to use for painting the specified component.

getAlphaComposite

public static java.awt.Composite getAlphaComposite(java.awt.Component c,
                                                   float translucency)

getAlphaComposite

public static java.awt.Composite getAlphaComposite(java.awt.Component c,
                                                   java.awt.Graphics g)
Returns the composite to use for painting the specified component. The result should be set on the Graphics2D before any custom rendering is done. This method can be used by application painting code and by look-and-feel delegates.

Parameters:
c - Component.
Returns:
The composite to use for painting the specified component.

getAlphaComposite

public static java.awt.Composite getAlphaComposite(java.awt.Component c)
Returns the composite to use for painting the specified component. The result should be set on the Graphics2D before any custom rendering is done. This method can be used by application painting code and by look-and-feel delegates.

Parameters:
c - Component.
Returns:
The composite to use for painting the specified component.

isOpaque

public static boolean isOpaque(java.awt.Component c)
Returns indication whether the specified component is opaque. This method can be used by look-and-feel delegates to decide whether the component background should be filled. Use in conjunction with getAlphaComposite(Component) or getAlphaComposite(Component, float) to correctly fill the component background during the transition fade animations. Note that during the transition fades, the components are marked as non-opaque so that Swing will handle them correctly. This means that calling Component.isOpaque() will return false, incorrectly signifying to the painting code that the background fill should be omitted.

Parameters:
c - Component.
Returns:
true if the specified component is opaque, false otherwise.

repaint

protected void repaint(java.awt.Component comp)

getCompositeAlpha

protected float getCompositeAlpha(java.awt.Component c)
Returns the composite alpha for the specified component. The same component can participate in several transitions - a button may be being hidden while the panel that contains the button is being hidden (switched out to another tab in a tabbed pane). In this case, the resulting alpha for the button is multiplication of the alpha of the button fade and the alpha of the panel fade. This method returns the multiplication of all the alpha fades of the specified component and its ancestors.

Parameters:
c - Component.
Returns:
Composite alpha for the specified component - the multiplication of all the alpha fades of the specified component and its ancestors

isAnimating

public boolean isAnimating()

addTransitionLayoutListener

public void addTransitionLayoutListener(TransitionLayoutListener listener)

removeTransitionLayoutListener

public void removeTransitionLayoutListener(TransitionLayoutListener listener)

fireEvent

protected void fireEvent(java.awt.Component child,
                         int id)