org.tbee.swing
Class ImageButton

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 org.tbee.swing.JLabel
                      extended by org.tbee.swing.ImageButton
All Implemented Interfaces:
DragGestureListener, DragSourceListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, SwingConstants
Direct Known Subclasses:
AnimatedImageButton, JpaEntitySearchButton

public class ImageButton
extends JLabel
implements MouseListener

This class was deprecated and one should use IconButton with an ImageIcon. However, Nimbus has such a big inner margin that small icons are not possible, so ImageButton is revived. Further more, this component has gotten DnD through the JLabel

Version:
$Revision: 1.34 $
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 String iActionCommand
           
protected  int iState
           
static String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
static int STATE_DISABLED
           
static int STATE_HOVER
           
static int STATE_NORMAL
           
static int STATE_PRESSED
           
static int STATE_UNKNOWN
           
 
Fields inherited from class org.tbee.swing.JLabel
PROPERTY_TEXT, PROPERTY_VISIBLE
 
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
ImageButton()
           
ImageButton(Image normal)
           
ImageButton(ImageIcon normal)
           
ImageButton(ImageIcon normal, ImageIcon pressed)
           
ImageButton(ImageIcon normal, ImageIcon pressed, ImageIcon hover)
           
ImageButton(ImageIcon normal, ImageIcon pressed, ImageIcon hover, ImageIcon disabled)
           
ImageButton(Image normal, Image pressed)
           
ImageButton(Image normal, Image hover, Image pressed)
           
ImageButton(Image normal, Image hover, Image pressed, String action, String tooltip)
           
ImageButton(Image normal, Image pressed, String action, String tooltip)
           
ImageButton(Image normal, String action, String tooltip)
           
 
Method Summary
 void addActionListener(ActionListener al)
          Adds an action listener to this ImageButton
protected  int determineState()
          what should our state be, based on the mouse flags
 void dragDropEnd(DragSourceDropEvent evt)
          Called when the user finishes or cancels the drag operation.
protected  void fireActionEvent()
          fire a new ActionEvent and process it, if some listeners are listening
 Action getAction()
          Action
 String getActionCommand()
           
 ImageIcon getDisabledImageIcon()
           
 ImageIcon getHoverImageIcon()
           
 Icon getIcon()
          the icon to be painted
protected  ImageIcon getIconForState(int state)
          Get the image that belongs to the specified state
 ImageIcon getNormalImageIcon()
           
 ImageIcon getPressedImageIcon()
           
 int getState()
           
 void mouseClicked(MouseEvent e)
           
 void mouseEntered(MouseEvent e)
           
 void mouseExited(MouseEvent e)
           
 void mousePressed(MouseEvent e)
           
 void mouseReleased(MouseEvent e)
           
 void paintComponent(Graphics graphics)
          paint the component
 void removeActionListener(ActionListener al)
          Removes an action listener to this ImageButton
 void setAction(Action value)
           
 void setActionCommand(String command)
           
 void setDisabledImage(Image value)
           
 void setDisabledImageIcon(ImageIcon value)
           
 void setEnabled(boolean value)
          The ImageButton uses JLabel to draw the image.
 void setHoverImage(Image value)
           
 void setHoverImageIcon(ImageIcon value)
           
 void setIcon(Icon value)
           
 void setImage(Image value)
           
 void setImageIcon(ImageIcon value)
           
 void setNormalImage(Image value)
           
 void setNormalImageIcon(ImageIcon value)
           
 void setPressedImage(Image value)
           
 void setPressedImageIcon(ImageIcon value)
           
 void setState(int state)
          set the current state but does NOT repaint
 void updateIcon()
          update the icon based on the current state
 
Methods inherited from class org.tbee.swing.JLabel
dragEnter, dragExit, dragGestureRecognized, dragOver, dropActionChanged, getDNDAction, getTransferable, isDragEnabled, setDragEnabled, setText, setVisible, withFont, withText, withVisible
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIconTextGap, setLabelFor, 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, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, 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
 

Field Detail

SOURCECODE_VERSION

public static final String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values

STATE_UNKNOWN

public static int STATE_UNKNOWN

STATE_DISABLED

public static int STATE_DISABLED

STATE_NORMAL

public static int STATE_NORMAL

STATE_HOVER

public static int STATE_HOVER

STATE_PRESSED

public static int STATE_PRESSED

iState

protected int iState

iActionCommand

public String iActionCommand
Constructor Detail

ImageButton

public ImageButton()

ImageButton

public ImageButton(Image normal,
                   Image hover,
                   Image pressed)

ImageButton

public ImageButton(Image normal,
                   Image hover,
                   Image pressed,
                   String action,
                   String tooltip)

ImageButton

public ImageButton(Image normal)

ImageButton

public ImageButton(ImageIcon normal)

ImageButton

public ImageButton(ImageIcon normal,
                   ImageIcon pressed)

ImageButton

public ImageButton(ImageIcon normal,
                   ImageIcon pressed,
                   ImageIcon hover)

ImageButton

public ImageButton(ImageIcon normal,
                   ImageIcon pressed,
                   ImageIcon hover,
                   ImageIcon disabled)

ImageButton

public ImageButton(Image normal,
                   String action,
                   String tooltip)

ImageButton

public ImageButton(Image normal,
                   Image pressed)

ImageButton

public ImageButton(Image normal,
                   Image pressed,
                   String action,
                   String tooltip)
Method Detail

setImage

public void setImage(Image value)

setImageIcon

public void setImageIcon(ImageIcon value)

setNormalImageIcon

public void setNormalImageIcon(ImageIcon value)

getNormalImageIcon

public ImageIcon getNormalImageIcon()

setNormalImage

public void setNormalImage(Image value)

setHoverImageIcon

public void setHoverImageIcon(ImageIcon value)

getHoverImageIcon

public ImageIcon getHoverImageIcon()

setHoverImage

public void setHoverImage(Image value)

setPressedImageIcon

public void setPressedImageIcon(ImageIcon value)

getPressedImageIcon

public ImageIcon getPressedImageIcon()

setPressedImage

public void setPressedImage(Image value)

setDisabledImageIcon

public void setDisabledImageIcon(ImageIcon value)

getDisabledImageIcon

public ImageIcon getDisabledImageIcon()

setDisabledImage

public void setDisabledImage(Image value)

getAction

public Action getAction()
Action


setAction

public void setAction(Action value)

setEnabled

public void setEnabled(boolean value)
The ImageButton uses JLabel to draw the image. If JLabel is actually disabled, it will always draw a greyed image instead of the custom one.

Overrides:
setEnabled in class JComponent

setState

public void setState(int state)
set the current state but does NOT repaint


getState

public int getState()

determineState

protected int determineState()
what should our state be, based on the mouse flags


updateIcon

public void updateIcon()
update the icon based on the current state


getIconForState

protected ImageIcon getIconForState(int state)
Get the image that belongs to the specified state

Parameters:
state -
Returns:

mouseClicked

public void mouseClicked(MouseEvent e)
Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Specified by:
mouseReleased in interface MouseListener

dragDropEnd

public void dragDropEnd(DragSourceDropEvent evt)
Called when the user finishes or cancels the drag operation.

Specified by:
dragDropEnd in interface DragSourceListener
Overrides:
dragDropEnd in class JLabel

setActionCommand

public void setActionCommand(String command)

getActionCommand

public String getActionCommand()

addActionListener

public void addActionListener(ActionListener al)
Adds an action listener to this ImageButton

Parameters:
al - The ActionListener

removeActionListener

public void removeActionListener(ActionListener al)
Removes an action listener to this ImageButton

Parameters:
al - The ActionListener

fireActionEvent

protected void fireActionEvent()
fire a new ActionEvent and process it, if some listeners are listening


getIcon

public Icon getIcon()
the icon to be painted

Overrides:
getIcon in class JLabel

setIcon

public void setIcon(Icon value)
Overrides:
setIcon in class JLabel

paintComponent

public void paintComponent(Graphics graphics)
paint the component

Overrides:
paintComponent in class JComponent


Copyright © 2012 KnowledgePlaza. All Rights Reserved.