com.rolemodelsoft.drawlet.awt
Class ImageButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--com.rolemodelsoft.drawlet.awt.ImageButton

public class ImageButton
extends java.awt.Component
implements java.awt.event.MouseListener

A button which uses an image instead of a label.

See Also:
Serialized Form

Field Summary
protected  java.awt.event.ActionListener actionListener
          The actionListener member variable, for dispatching events.
protected  java.lang.String command
          The label (not visible) for this button.
protected  java.awt.Image image
          The image for this button.
protected  boolean isHighlighted
          Flag that is set when the button should be highlighted.
protected  boolean isInside
          Flag that is set when the mouse is inside
protected  boolean isPressed
          Flag that is set when the mouse is pressed inside.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
ImageButton()
          Create a new, default ImageButton.
ImageButton(java.awt.Image image)
          Create a new ImageButton and initalize it with the given Image.
ImageButton(java.lang.String command)
          Create a new ImageButton and initalize it with the given command.
ImageButton(java.lang.String command, java.awt.Image image)
          Create a new ImageButton and initalize it with the given command and Image.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Add the given ActionListener to my set of listeners.
 java.lang.String getCommand()
          Answer the command associated with this receiver.
protected  java.lang.String getDefaultCommand()
          Answers the default command for the receiver (intended for initialization).
protected  java.awt.Image getDefaultImage()
          Answers the default image for the receiver (intended for initialization.
 java.awt.Image getImage()
          Answers the current image this button is associated with.
 java.awt.Dimension getMinimumSize()
          Answer the size this ImageButton must be displayed at.
 java.awt.Dimension getPreferredSize()
          Answer the size this ImageButton prefers to be displayed at.
 boolean isHighlighted()
          Returns whether this button is highlighted (down) or not.
 void mouseClicked(java.awt.event.MouseEvent e)
          Mouse 'action' events are handled in MousePressed and MouseReleased.
 void mouseEntered(java.awt.event.MouseEvent e)
          If the mouse moves inside of the button, set the isInside flag.
 void mouseExited(java.awt.event.MouseEvent e)
          If the mouse moves outside of the button, reset the isInside flag.
 void mousePressed(java.awt.event.MouseEvent e)
          If the mouse is pressed inside of the button, set the isPressed flag.
 void mouseReleased(java.awt.event.MouseEvent e)
          If the mouse is released, check to see if it is inside of the button, and if it was originally pressed inside of the button.
 void paint(java.awt.Graphics g)
          Paint the button.
 void paintHighlight(java.awt.Graphics g, java.awt.Color firstColor, java.awt.Color secondColor)
          Paint the button highlight.
 void paintHighlighted(java.awt.Graphics g)
          Paint the button highlighted (down).
 void paintUnhighlighted(java.awt.Graphics g)
          Paint the button unhighlighted (not down).
 void processActionEvent()
          Create an ActionEvent and pass it to everyone listening for it.
 void removeActionListener(java.awt.event.ActionListener listener)
          Remove the given ActionListener from my set of listeners.
 void setCommand(java.lang.String command)
          Set the command associated with the receiver.
 void setHighlight(boolean isHighlighted)
          Set whether this button is highlighted (down) or not.
 void setImage(java.awt.Image image)
          Set the Image this button is associated with.
protected static void waitForImage(java.awt.Component component, java.awt.Image image)
          Wait for the image to be available.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

command

protected java.lang.String command
The label (not visible) for this button.

image

protected java.awt.Image image
The image for this button.

actionListener

protected java.awt.event.ActionListener actionListener
The actionListener member variable, for dispatching events.

isPressed

protected boolean isPressed
Flag that is set when the mouse is pressed inside.

isInside

protected boolean isInside
Flag that is set when the mouse is inside

isHighlighted

protected boolean isHighlighted
Flag that is set when the button should be highlighted.
Constructor Detail

ImageButton

public ImageButton()
Create a new, default ImageButton.

ImageButton

public ImageButton(java.awt.Image image)
Create a new ImageButton and initalize it with the given Image.
Parameters:
image - the image to be used.

ImageButton

public ImageButton(java.lang.String command)
Create a new ImageButton and initalize it with the given command.
Parameters:
command - the command that will be passed in action events.

ImageButton

public ImageButton(java.lang.String command,
                   java.awt.Image image)
Create a new ImageButton and initalize it with the given command and Image.
Parameters:
command - the command that will be passed in action events.
image - the image to be used.
Method Detail

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Add the given ActionListener to my set of listeners.
Parameters:
listener - the action listener to add.

getCommand

public java.lang.String getCommand()
Answer the command associated with this receiver.
Returns:
a String representing the command passed in action events generated by this button.

getDefaultCommand

protected java.lang.String getDefaultCommand()
Answers the default command for the receiver (intended for initialization).
Returns:
a String representing the default command to use.

getDefaultImage

protected java.awt.Image getDefaultImage()
Answers the default image for the receiver (intended for initialization. If this is changed to something other than null, it will also need to wait for the image.
Returns:
the default Image for this button to use

getImage

public java.awt.Image getImage()
Answers the current image this button is associated with.
Returns:
the Image this button is using.

getMinimumSize

public java.awt.Dimension getMinimumSize()
Answer the size this ImageButton must be displayed at.
Overrides:
getMinimumSize in class java.awt.Component
Returns:
an integer representing the minimum size for this image button

getPreferredSize

public java.awt.Dimension getPreferredSize()
Answer the size this ImageButton prefers to be displayed at.
Overrides:
getPreferredSize in class java.awt.Component
Returns:
an integer representing the preferred size for this ImageButton.

isHighlighted

public boolean isHighlighted()
Returns whether this button is highlighted (down) or not.
Returns:
a boolean representing the button's current highlight state.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Mouse 'action' events are handled in MousePressed and MouseReleased.
Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
e - the event.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
If the mouse moves inside of the button, set the isInside flag.
Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
e - the event.

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
If the mouse moves outside of the button, reset the isInside flag.
Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
e - the event.

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
If the mouse is pressed inside of the button, set the isPressed flag.
Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
e - the event.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
If the mouse is released, check to see if it is inside of the button, and if it was originally pressed inside of the button. If it was, it was an action event, so call processActionEvent(). Then reset the isPressed flag.
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
e - the event.

paint

public void paint(java.awt.Graphics g)
Paint the button.
Overrides:
paint in class java.awt.Component
Parameters:
g - the graphics object to use in painting.

paintHighlight

public void paintHighlight(java.awt.Graphics g,
                           java.awt.Color firstColor,
                           java.awt.Color secondColor)
Paint the button highlight.
Parameters:
g - the graphics object to use in painting.
firstColor - the Color to paint the top and left-hand sides.
secondColor - the Color to paint the bottom and right-hand sides.

paintHighlighted

public void paintHighlighted(java.awt.Graphics g)
Paint the button highlighted (down).
Parameters:
g - the graphics object to use in painting.

paintUnhighlighted

public void paintUnhighlighted(java.awt.Graphics g)
Paint the button unhighlighted (not down).
Parameters:
g - the graphics object to use in painting.

processActionEvent

public void processActionEvent()
Create an ActionEvent and pass it to everyone listening for it.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Remove the given ActionListener from my set of listeners.
Parameters:
l - ActionListener

setCommand

public void setCommand(java.lang.String command)
Set the command associated with the receiver.
Parameters:
command - the command to be passed in action events generated. by this button.

setHighlight

public void setHighlight(boolean isHighlighted)
Set whether this button is highlighted (down) or not.
Parameters:
isHighlighted - a boolean representing the button's new highlight state.

setImage

public void setImage(java.awt.Image image)
Set the Image this button is associated with.
Parameters:
image - the image this button should use.

waitForImage

protected static void waitForImage(java.awt.Component component,
                                   java.awt.Image image)
Wait for the image to be available.
Parameters:
component - the component the image is associated with.
image - the image to wait for.