com.rolemodelsoft.drawlet.awt
Class ColorButton

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

public class ColorButton
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.awt.Color color
          The image for this button.
protected  java.lang.String command
          The label (not visible) for this button.
protected  boolean isHighlighted
          Flag indicating the current value of highlighting.
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
ColorButton()
          Create a new, default ColorButton
ColorButton(java.awt.Color color)
          Create a new ColorButton initialized with the given color.
ColorButton(java.lang.String command)
          Create a new ColorButton initialized with the given command.
ColorButton(java.lang.String command, java.awt.Color color)
          Create a new ColorButton initialized with the given command and color.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Add the given ActionListener to my set of listeners.
 java.awt.Color getColor()
          Answers the Color this button represents and displays.
 java.lang.String getCommand()
          Answer the command associated with this receiver.
protected  java.awt.Color getDefaultColor()
          Answers the default color for the receiver (intended for initialization).
protected  java.lang.String getDefaultCommand()
          Answers the default command for the receiver (intended for initialization).
 java.awt.Dimension getMinimumSize()
          Answer the size this color button must be displayed at.
 java.awt.Dimension getPreferredSize()
          Answer the size this color button prefers to be displayed at.
 boolean isHighlighted()
          Answer whether or not the receiver is to be drawn highlighted.
 void mouseClicked(java.awt.event.MouseEvent e)
          Mouse 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 paintLabel(java.awt.Graphics g, int moveBy)
          Paint the label form, offsetting it by the given amount.
 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 setColor(java.awt.Color color)
          Set the Color this button is associated with.
 void setCommand(java.lang.String command)
          Set the command associated with this receiver.
 void setHighlighted(boolean highlighted)
          Set whether or not the receiver is to be drawn highlighted.
 
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.

color

protected java.awt.Color color
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 indicating the current value of highlighting.
Constructor Detail

ColorButton

public ColorButton()
Create a new, default ColorButton

ColorButton

public ColorButton(java.awt.Color color)
Create a new ColorButton initialized with the given color.
Parameters:
color - the color to be used.

ColorButton

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

ColorButton

public ColorButton(java.lang.String command,
                   java.awt.Color color)
Create a new ColorButton initialized with the given command and color.
Parameters:
command - the command that will be passed in action events.
color - the color 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 ActionListener to add.

getColor

public java.awt.Color getColor()
Answers the Color this button represents and displays.
Returns:
the Color this button holds.

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.

getDefaultColor

protected java.awt.Color getDefaultColor()
Answers the default color for the receiver (intended for initialization).
Returns:
the default Color for this button to use

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.

getMinimumSize

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

getPreferredSize

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

isHighlighted

public boolean isHighlighted()
Answer whether or not the receiver is to be drawn highlighted.
Returns:
a boolean value of true if the receiver is to be drawn highlighted; or false otherwise.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Mouse 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.

paintLabel

public void paintLabel(java.awt.Graphics g,
                       int moveBy)
Paint the label form, offsetting it by the given amount.
Parameters:
g - the graphics object to use in painting.
moveBy - an integer representing the amount to offset the label by.

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:
listener - the ActionListener to remove.

setColor

public void setColor(java.awt.Color color)
Set the Color this button is associated with.
Parameters:
color - the color this button should use.

setCommand

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

setHighlighted

public void setHighlighted(boolean highlighted)
Set whether or not the receiver is to be drawn highlighted.
Parameters:
highlighted - true if the button should be drawn highlighted; false otherwise.