Class AnimatedLabel

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public final class AnimatedLabel
    extends javax.swing.JPanel
    An anti-aliased text label that can animate text changes using a blend over effect.

    Note: This is preview code that is not supported. It is more raw than other classes that you have downloaded from JGoodies.com in the past and contains known bugs.

    Version:
    $Revision: 1.8 $
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  AnimatedLabel.AntiAliasedLabel  
      private class  AnimatedLabel.BlendOverAnimation
      An animation that changes the colors of overlapping labels to implement a blend over effect.
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      AnimatedLabel()
      Constructs an AnimatedLabel with default base color, default font extra size, and an empty text.
      AnimatedLabel​(java.awt.Color baseColor, int fontExtraSize, java.lang.String text)
      Constructs an AnimatedLabel with the given initial text using a left oriented label.
      AnimatedLabel​(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation)
      Constructs an AnimatedLabel with the given initial text and orientation.
      AnimatedLabel​(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation, int duration, int framesPerSecond)
      Constructs an AnimatedLabel with the given properties.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int anchor()  
      private Animation animation()
      Lazily creates and returns the blend over animation.
      private void build()  
      private static javax.swing.JLabel createBoldLabel​(int sizeIncrement, java.awt.Color aForeground)
      Creates and returns an anti-aliased label with a bold font for the specified size increment and foreground color.
      long getDuration()
      Returns the duration of the blend over animation.
      java.awt.Color getForeground()
      Returns the label's foreground base color.
      java.lang.String getText()
      Returns the text of the foreground label.
      private java.awt.Color getTranslucentColor​(int alpha)
      Creates and returns a translucent color with the label's base color.
      private void initComponents​(int fontExtraSize)
      Creates and configures the UI components.
      boolean isAnimated()
      Answers whether the animation is currently enabled.
      private void setAlpha​(int foregroundAlpha, int backgroundAlpha)
      Sets the foreground and background colors in the event dispatch thread.
      private void setAlpha0​(int foregroundAlpha, int backgroundAlpha)
      Sets the foreground and background colors using the given alpha values.
      void setAnimated​(boolean animated)
      Enables or disables the blend over effect.
      void setDuration​(long newDuration)
      Sets the animation's duration and invalidates the animation cache.
      void setForeground​(java.awt.Color newForeground)
      Sets a new foreground base color.
      void setText​(java.lang.String newText)
      Sets a new text.
      void setTextImmediately​(java.lang.String newText)
      Sets a new text without using the blend over animation.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • PROPERTY_ANIMATED

        public static final java.lang.String PROPERTY_ANIMATED
        See Also:
        Constant Field Values
      • PROPERTY_DURATION

        public static final java.lang.String PROPERTY_DURATION
        See Also:
        Constant Field Values
      • PROPERTY_FOREGROUND

        public static final java.lang.String PROPERTY_FOREGROUND
        See Also:
        Constant Field Values
      • DEFAULT_BASE_COLOR

        public static final java.awt.Color DEFAULT_BASE_COLOR
      • DEFAULT_FONT_EXTRA_SIZE

        public static final int DEFAULT_FONT_EXTRA_SIZE
        See Also:
        Constant Field Values
      • labels

        private javax.swing.JLabel[] labels
      • foreground

        private int foreground
      • background

        private int background
      • baseColor

        private java.awt.Color baseColor
      • animated

        private boolean animated
      • orientation

        private final int orientation
      • duration

        private long duration
      • fps

        private final int fps
    • Constructor Detail

      • AnimatedLabel

        public AnimatedLabel()
        Constructs an AnimatedLabel with default base color, default font extra size, and an empty text.
      • AnimatedLabel

        public AnimatedLabel​(java.awt.Color baseColor,
                             int fontExtraSize,
                             java.lang.String text)
        Constructs an AnimatedLabel with the given initial text using a left oriented label.
        Parameters:
        baseColor - the color used as a basis for the text color
        fontExtraSize - pixels that are added to the dialog font size
        text - the initial text to be displayed
      • AnimatedLabel

        public AnimatedLabel​(java.awt.Color baseColor,
                             int fontExtraSize,
                             java.lang.String text,
                             int orientation)
        Constructs an AnimatedLabel with the given initial text and orientation.
        Parameters:
        baseColor - the color used as a basis for the text color
        fontExtraSize - pixels that are added to the dialog font size
        text - the initial text to be displayed
        orientation - the label's orientation
      • AnimatedLabel

        public AnimatedLabel​(java.awt.Color baseColor,
                             int fontExtraSize,
                             java.lang.String text,
                             int orientation,
                             int duration,
                             int framesPerSecond)
        Constructs an AnimatedLabel with the given properties.
        Parameters:
        baseColor - the color used as a basis for the text color
        fontExtraSize - pixels that are added to the dialog font size
        text - the initial text to be displayed
        orientation - the label's orientation
        duration - the duration of the blend over animation
        framesPerSecond - the blend over animation's frame rate
    • Method Detail

      • isAnimated

        public boolean isAnimated()
        Answers whether the animation is currently enabled.
        Returns:
        true if the animation is enabled, false if disabled
      • getDuration

        public long getDuration()
        Returns the duration of the blend over animation.
        Returns:
        the duration of the blend over animaton
      • getForeground

        public java.awt.Color getForeground()
        Returns the label's foreground base color.
        Overrides:
        getForeground in class java.awt.Component
        Returns:
        this label's foreground base color
      • getText

        public java.lang.String getText()
        Returns the text of the foreground label.
        Returns:
        the text of the foreground label
      • setAnimated

        public void setAnimated​(boolean animated)
        Enables or disables the blend over effect. This can be useful in environments with a poor rendering performance or if the user disables all kinds of animations. You can still use this class but enable and disable the animations.
        Parameters:
        animated - true to enable the blend over effect, false to disable it
      • setDuration

        public void setDuration​(long newDuration)
        Sets the animation's duration and invalidates the animation cache.
        Parameters:
        newDuration - the duration to be set
      • setForeground

        public void setForeground​(java.awt.Color newForeground)
        Sets a new foreground base color.
        Overrides:
        setForeground in class javax.swing.JComponent
        Parameters:
        newForeground - the color to be set as new foreground base color
      • setText

        public void setText​(java.lang.String newText)
        Sets a new text. If the animation is disabled the text will be set immediately otherwise a blend over animation is used.
        Parameters:
        newText - the new text to be displayed
      • setTextImmediately

        public void setTextImmediately​(java.lang.String newText)
        Sets a new text without using the blend over animation.
        Parameters:
        newText - the text to be set
      • animation

        private Animation animation()
        Lazily creates and returns the blend over animation.
        Returns:
        the lazily created blend over animation
      • initComponents

        private void initComponents​(int fontExtraSize)
        Creates and configures the UI components. The label's size is specified using an fontExtraSize that is a delta in pixel to the dialog font size.
        Parameters:
        fontExtraSize - the pixel size delta for the label sizes
      • build

        private void build()
      • anchor

        private int anchor()
      • createBoldLabel

        private static javax.swing.JLabel createBoldLabel​(int sizeIncrement,
                                                          java.awt.Color aForeground)
        Creates and returns an anti-aliased label with a bold font for the specified size increment and foreground color.
        Parameters:
        sizeIncrement - a size delta in pixels relative to the dialog font size
        aForeground - the label's foreground base color
        Returns:
        a bold anti aliased label
      • getTranslucentColor

        private java.awt.Color getTranslucentColor​(int alpha)
        Creates and returns a translucent color with the label's base color.
        Parameters:
        alpha - the current alpha value
        Returns:
        a translucent color with the given alpha based on this label's foreground base color.
      • setAlpha0

        private void setAlpha0​(int foregroundAlpha,
                               int backgroundAlpha)
        Sets the foreground and background colors using the given alpha values.
        Parameters:
        foregroundAlpha - alpha value for the foreground label
        backgroundAlpha - alpha value for the background label
      • setAlpha

        private void setAlpha​(int foregroundAlpha,
                              int backgroundAlpha)
        Sets the foreground and background colors in the event dispatch thread.
        Parameters:
        foregroundAlpha - alpha value for the foreground label
        backgroundAlpha - alpha value for the background label