Class AnimatedLabel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- com.jgoodies.animation.swing.components.AnimatedLabel
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible
public final class AnimatedLabel extends javax.swing.JPanelAn 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 classAnimatedLabel.AntiAliasedLabelprivate classAnimatedLabel.BlendOverAnimationAn 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
-
-
Field Summary
Fields Modifier and Type Field Description private booleananimatedprivate Animationanimationprivate Animatoranimatorprivate intbackgroundprivate java.awt.ColorbaseColorstatic intCENTERprivate static intDEFAULT_ANIMATION_FPSstatic java.awt.ColorDEFAULT_BASE_COLORprivate static intDEFAULT_DURATIONstatic intDEFAULT_FONT_EXTRA_SIZEprivate longdurationprivate intforegroundprivate intfpsprivate javax.swing.JLabel[]labelsstatic intLEFTprivate intorientationstatic java.lang.StringPROPERTY_ANIMATEDstatic java.lang.StringPROPERTY_DURATIONstatic java.lang.StringPROPERTY_FOREGROUNDstatic java.lang.StringPROPERTY_TEXTstatic intRIGHT-
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
-
-
Constructor Summary
Constructors Constructor Description AnimatedLabel()Constructs anAnimatedLabelwith default base color, default font extra size, and an empty text.AnimatedLabel(java.awt.Color baseColor, int fontExtraSize, java.lang.String text)Constructs anAnimatedLabelwith the given initial text using a left oriented label.AnimatedLabel(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation)Constructs anAnimatedLabelwith the given initial text and orientation.AnimatedLabel(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation, int duration, int framesPerSecond)Constructs anAnimatedLabelwith the given properties.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private intanchor()private Animationanimation()Lazily creates and returns the blend over animation.private voidbuild()private static javax.swing.JLabelcreateBoldLabel(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.longgetDuration()Returns the duration of the blend over animation.java.awt.ColorgetForeground()Returns the label's foreground base color.java.lang.StringgetText()Returns the text of the foreground label.private java.awt.ColorgetTranslucentColor(int alpha)Creates and returns a translucent color with the label's base color.private voidinitComponents(int fontExtraSize)Creates and configures the UI components.booleanisAnimated()Answers whether the animation is currently enabled.private voidsetAlpha(int foregroundAlpha, int backgroundAlpha)Sets the foreground and background colors in the event dispatch thread.private voidsetAlpha0(int foregroundAlpha, int backgroundAlpha)Sets the foreground and background colors using the given alpha values.voidsetAnimated(boolean animated)Enables or disables the blend over effect.voidsetDuration(long newDuration)Sets the animation's duration and invalidates the animation cache.voidsetForeground(java.awt.Color newForeground)Sets a new foreground base color.voidsetText(java.lang.String newText)Sets a new text.voidsetTextImmediately(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
-
-
-
-
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
-
PROPERTY_TEXT
public static final java.lang.String PROPERTY_TEXT
- See Also:
- Constant Field Values
-
RIGHT
public static final int RIGHT
- See Also:
- Constant Field Values
-
CENTER
public static final int CENTER
- See Also:
- Constant Field Values
-
LEFT
public static final int LEFT
- 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
-
DEFAULT_DURATION
private static final int DEFAULT_DURATION
- See Also:
- Constant Field Values
-
DEFAULT_ANIMATION_FPS
private static final int DEFAULT_ANIMATION_FPS
- 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
-
animation
private Animation animation
-
animator
private Animator animator
-
-
Constructor Detail
-
AnimatedLabel
public AnimatedLabel()
Constructs anAnimatedLabelwith 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 anAnimatedLabelwith the given initial text using a left oriented label.- Parameters:
baseColor- the color used as a basis for the text colorfontExtraSize- pixels that are added to the dialog font sizetext- the initial text to be displayed
-
AnimatedLabel
public AnimatedLabel(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation)Constructs anAnimatedLabelwith the given initial text and orientation.- Parameters:
baseColor- the color used as a basis for the text colorfontExtraSize- pixels that are added to the dialog font sizetext- the initial text to be displayedorientation- the label's orientation
-
AnimatedLabel
public AnimatedLabel(java.awt.Color baseColor, int fontExtraSize, java.lang.String text, int orientation, int duration, int framesPerSecond)Constructs anAnimatedLabelwith the given properties.- Parameters:
baseColor- the color used as a basis for the text colorfontExtraSize- pixels that are added to the dialog font sizetext- the initial text to be displayedorientation- the label's orientationduration- the duration of the blend over animationframesPerSecond- 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:
getForegroundin classjava.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:
setForegroundin classjavax.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 anfontExtraSizethat 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 sizeaForeground- 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 labelbackgroundAlpha- 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 labelbackgroundAlpha- alpha value for the background label
-
-