DESY ACOP Beans Home

com.cosylab.gui.components
Class GradientLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by com.cosylab.gui.components.ResizableTextLabel
                      extended by com.cosylab.gui.components.GradientLabel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants
Direct Known Subclasses:
SimpleButton

public class GradientLabel
extends ResizableTextLabel

A label that paints a gradient as a background. User can specify gradient colors (one of them is the default label background) and direction (the default is from the upper left to the upper right corner) relative to the label's proportions.

Version:
$id$
Author:
Miha Kadunc
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.cosylab.gui.components.ResizableTextLabel
ResizableTextLabel.ResizableAdapter
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
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
 
Field Summary
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GradientLabel()
          Constructs an empty GradientLabel
GradientLabel(javax.swing.Icon image)
          Constructs a GradientLabel with the specified icon.
GradientLabel(javax.swing.Icon image, int horizontalAlignment)
          Constructor for GradientLabel.
GradientLabel(java.lang.String text)
          Constructs a GradientLabel with the specified text.
GradientLabel(java.lang.String text, javax.swing.Icon icon, int horizontalAlignment)
          Constructor for GradientLabel.
GradientLabel(java.lang.String text, int horizontalAlignment)
          Constructor for GradientLabel.
 
Method Summary
 java.awt.Color getBackgroundStart()
          Returns the backgroundStart, this is the color that is used for the start of label's gradient.
 boolean isGradientEnabled()
          Returns whether the gradient background is enabled.
static void main(java.lang.String[] args)
           
protected  void paintComponent(java.awt.Graphics g)
          This method hes been overriden to implement the feature of enhanced anti-aliasing paint of the label.
 void setBackground(java.awt.Color c)
          Sets the background color.
 void setBackgroundStart(java.awt.Color newBackgroundStart)
          Sets the backgroundStart color.
 void setGradientEnabled(boolean gradientEnabled)
          Sets the gradientEnabled property.
 void setGradientPoints(double startX, double startY, double endX, double endY)
          Sets the start and end point of the label's gradient, relative to the label's size.
 
Methods inherited from class com.cosylab.gui.components.ResizableTextLabel
addNotify, adjustSizeToFont, getColumns, getMaximumFontSize, getMinimumFontSize, getMinimumSize, getPreferredSize, isEnhanced, isResizable, resize, setColumns, setEnhanced, setMaximumFontSize, setMinimumFontSize, setMinimumSize, setPreferredSize, setResizable, setText
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setNextFocusableComponent, setOpaque, 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, transferFocusBackward, 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, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GradientLabel

public GradientLabel()
Constructs an empty GradientLabel


GradientLabel

public GradientLabel(javax.swing.Icon image)
Constructs a GradientLabel with the specified icon.

Parameters:
image -

GradientLabel

public GradientLabel(javax.swing.Icon image,
                     int horizontalAlignment)
Constructor for GradientLabel.

Parameters:
image -
horizontalAlignment -

GradientLabel

public GradientLabel(java.lang.String text)
Constructs a GradientLabel with the specified text.

Parameters:
text -

GradientLabel

public GradientLabel(java.lang.String text,
                     javax.swing.Icon icon,
                     int horizontalAlignment)
Constructor for GradientLabel.

Parameters:
text -
icon -
horizontalAlignment -

GradientLabel

public GradientLabel(java.lang.String text,
                     int horizontalAlignment)
Constructor for GradientLabel.

Parameters:
text -
horizontalAlignment -
Method Detail

getBackgroundStart

public java.awt.Color getBackgroundStart()
Returns the backgroundStart, this is the color that is used for the start of label's gradient. The end color is that of the label's background.

Returns:
Color

isGradientEnabled

public boolean isGradientEnabled()
Returns whether the gradient background is enabled.

Returns:
boolean

paintComponent

protected void paintComponent(java.awt.Graphics g)
Description copied from class: ResizableTextLabel
This method hes been overriden to implement the feature of enhanced anti-aliasing paint of the label.

Overrides:
paintComponent in class ResizableTextLabel
See Also:
JComponent.paintComponent(java.awt.Graphics)

setBackground

public void setBackground(java.awt.Color c)
Sets the background color. This color is used for the gradient's end point.

Overrides:
setBackground in class javax.swing.JComponent
Parameters:
c - The color to be set
See Also:
Component.setBackground(Color), setBackgroundStart(Color)

setBackgroundStart

public void setBackgroundStart(java.awt.Color newBackgroundStart)
Sets the backgroundStart color.

Parameters:
newBackgroundStart - The backgroundStart to set
See Also:
getBackgroundStart()

setGradientEnabled

public void setGradientEnabled(boolean gradientEnabled)
Sets the gradientEnabled property.

Parameters:
gradientEnabled - The gradientEnabled to set
See Also:
isGradientEnabled()

setGradientPoints

public void setGradientPoints(double startX,
                              double startY,
                              double endX,
                              double endY)
Sets the start and end point of the label's gradient, relative to the label's size. Value 0 is the left/top edge of the label. 1 is the right/bottom edge of the label.

Parameters:
startX - the x coordinate of the start of the gradient
startY - the y coordinate of the start of the gradient
endX - the x coordinate of the end of the gradient
endY - the y coordinate of the end of the gradient

main

public static void main(java.lang.String[] args)


Copyright © 2010. All Rights Reserved.