DESY ACOP Beans Home

com.cosylab.gui.components
Class MultiIconLabel

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.MultiIconLabel
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants

public class MultiIconLabel
extends javax.swing.JLabel

This class extends javax.swing.JLabel so that it allows display of multiple icons. It maintains internal list of icons that associates integer values with Icon objects. This index is guaranteed to be valid even if the desired icon could not be found, is not valid or is null. In such cases the corresponding icon will not be displayed.

Icons can be provided by either the calling class via the javax.swing.Icon object or they can be loaded from the projects resource automatically. Two methods are provided to add the icons: addIcon, addIcons The later is preffered when adding multiple icons at the same time.
Use the setIconByIndex method to set which icon should be displayed.
The disabled state icon of the JLabel is not overriden and can be still specified.

Version:
$id$
Author:
Ales Pucelj
See Also:
Serialized Form

Nested Class Summary
 
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
MultiIconLabel()
          Default constructor for MultiIconLabel.
MultiIconLabel(javax.swing.Icon[] icons)
          Constructs a MultiIconLabel and adds the icons to the icon list.
MultiIconLabel(javax.swing.Icon[] icons, int horizontalAlignment)
          Constructs a MultiIconLabel and adds the icons to the icon list.
MultiIconLabel(java.lang.String[] resourceNames)
          Constructs a MultiIconLabel and loads the icons from the specified resource names.
MultiIconLabel(java.lang.String[] resourceNames, int horizontalAlignement)
          Constructs a MultiIconLabel and loads the icons from the specified resource names.
 
Method Summary
 void addIcon(javax.swing.Icon icon)
          Appends the icon to the list of icons.
 void addIcon(java.lang.String resourceName)
          Appends the icon specified by resourceName to the end of internal list of icons.
 void addIcons(javax.swing.Icon[] icons)
          Appends all icons specified by icons parameter to the internal list of icons.
 void addIcons(java.lang.String[] resourceNames)
          Appends all icons specified by resourceNames to the end of internal list of icons.
 javax.swing.Icon getIconByIndex(int index)
          Returns the Icon resource assigned to the specified index.
 int getIconCount()
          Returns number of available icons.
protected  javax.swing.Icon loadFromResource(java.lang.String resourceName)
          Loads the Icon from the projects resource.
 void setIconByIndex(int index)
          Displays the icon specified by index.
 
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, setText, setUI, setVerticalAlignment, setVerticalTextPosition, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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, setForeground, 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, 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

MultiIconLabel

public MultiIconLabel()
Default constructor for MultiIconLabel.


MultiIconLabel

public MultiIconLabel(java.lang.String[] resourceNames)
Constructs a MultiIconLabel and loads the icons from the specified resource names.

Parameters:
resourceNames - String[]

MultiIconLabel

public MultiIconLabel(java.lang.String[] resourceNames,
                      int horizontalAlignement)
Constructs a MultiIconLabel and loads the icons from the specified resource names. Also sets the horizontal alignement of the text.

Parameters:
resourceNames - String[]
horizontalAlignement - int.

MultiIconLabel

public MultiIconLabel(javax.swing.Icon[] icons)
Constructs a MultiIconLabel and adds the icons to the icon list.

Parameters:
icons - Icon[]

MultiIconLabel

public MultiIconLabel(javax.swing.Icon[] icons,
                      int horizontalAlignment)
Constructs a MultiIconLabel and adds the icons to the icon list. Also sets the horizontal alignement of the text.

Parameters:
icons - javax.swing.Icon[]
horizontalAlignment - int
Method Detail

addIcon

public void addIcon(java.lang.String resourceName)
Appends the icon specified by resourceName to the end of internal list of icons. This method calls addIcon(Icon) and loadFromResource(String). If resourceName does not exist in the projects resources, method adds empty icon.

Parameters:
resourceName - java.lang.String

addIcon

public void addIcon(javax.swing.Icon icon)
Appends the icon to the list of icons.

Parameters:
icon - javax.swing.Icon

addIcons

public void addIcons(java.lang.String[] resourceNames)
Appends all icons specified by resourceNames to the end of internal list of icons. For adding multiple icons, this method outperforms individual calls to addIcon method.

After calling this method, the list of icons will grow by the size of the array, regardless of its contentrs. If any of the icons is null or of invalid type, the associated icon will not be displayed.

Parameters:
resourceNames - java.lang.String[]

addIcons

public void addIcons(javax.swing.Icon[] icons)
Appends all icons specified by icons parameter to the internal list of icons. For adding multiple icons, this method outperforms individual calls to addIcon method.

After calling this method, the list of icons will grow by the size of the array, regardless of its contentrs. If any of the icons is null or of invalid type, the associated icon will not be displayed.

Parameters:
icons - javax.swing.Icon[]

getIconByIndex

public javax.swing.Icon getIconByIndex(int index)
Returns the Icon resource assigned to the specified index. If the icon has not been defined, returns null.

Parameters:
index - int
Returns:
javax.swing.Icon

loadFromResource

protected javax.swing.Icon loadFromResource(java.lang.String resourceName)
Loads the Icon from the projects resource. Returns null if the resource does not exist.

Parameters:
resourceName - java.lang.String
Returns:
javax.swing.Icon

setIconByIndex

public void setIconByIndex(int index)
Displays the icon specified by index. If the icon with this index has not been defined, no icon will be displayed.

Parameters:
index - int

getIconCount

public int getIconCount()
Returns number of available icons.

Returns:
Number of available icons.


Copyright © 2010. All Rights Reserved.