ice.ri.enhancedawt.iscl
Class SkinnableButton

java.lang.Object
  extended byjava.awt.Component
      extended byice.ri.enhancedawt.iscl.LightweightBase
          extended byice.ri.enhancedawt.iscl.SkinnableButton
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Skinnable

public class SkinnableButton
extends LightweightBase
implements Skinnable

This is a light weight custom component which provides the functionality of a button. The button is a skinnable one, which has up to four images associated with it.

  1. highlighted - for when the button is in the up position and the mouse is hovering over the component.
  2. pressed - for when the user has pressed the mouse button while hovering over the component.
  3. normal - for when the mouse is not over the component
  4. disabled - for when the components is disabled (i.e. not responding to user input).
the default image is the normal one. if this image is null, or an invalid image, then the button will display itself in its default representation with it a label.

NOTE: this is a light weight component. if the parent of the WRButton is not a SkinnablePanel, there might be some flickering

Author:
Ofer Shai
See Also:
Serialized Form

Nested Class Summary
protected  class SkinnableButton.ButtonSkin
           
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String DEFAULT_SKIN
           
protected static int DISABLED
          states of the button
protected static String DISABLED_IMAGE
          the file name for the disabled image - "disabled"
protected static int HIGHLIGHTED
          states of the button
protected static String HIGHLIGHTED_IMAGE
          the file name for the hover image - "highlighted"
protected  Skin m_skin
          The Skin for this button.
protected  SkinManager m_skinManager
           
protected  String m_skinName
           
protected  int m_state
          the current state of the button
protected static int NORMAL
          states of the button
protected static String NORMAL_IMAGE
          the file name for the normal image - "normal"
protected static int OFF_PRESSED
          states of the button
protected static int PRESSED
          states of the button
protected static String PRESSED_IMAGE
          the file name for the pressed image - "pressed"
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
SkinnableButton()
          default constructor.
SkinnableButton(String name, SkinManager skinManager, String skinName)
           
 
Method Summary
 void addActionListener(ActionListener p_newListener)
          adds an ActionListener.
 void drawButton(Graphics g)
          called to draw a button which has no images associated with it.
 void drawLabel(Graphics g)
          called to draw the label on the button.
protected  Dimension figureMySize(Graphics g)
          * Abstract method which must be defined in child classes to determine * their sizes.
 String getActionCommand()
          get the action command that will be sent with ActionEvent, when one is fired
 String getLabel()
          gets the label that appears on the button in its default representation, or when setShowingLabel is set to true
 String getSkin()
          Gets the skin being used by this component.
 SkinManager getSkinManager()
           
 boolean isShowingLabel()
          finds out if the button shows the label even if there are images set
 void paint(Graphics g)
          overriden method from Component
 void processMouseEvent(MouseEvent e)
          this method processes mouse event recieved from the user.
 void removeActionListener(ActionListener p_oldListener)
          removes an ActionListener from listening to this button.
 void setActionCommand(String p_command)
          set the action command that will be sent with ActionEvent, when one is fired
 void setEnabled(boolean enabled)
          enables / disables the button
 void setLabel(String p_label)
          explicitly sets the label that appears on the button in its default representation, or when setShowingLabel is set to true
 void setShowingLabel(boolean p_show)
          tells the button to show the label even if there are images set
 void setSkin(String skinName)
          Sets all the necessary images through a directory structure and predetermined names.
 void setSkinManager(SkinManager skinManager)
           
 void update(Graphics g)
          overriden method from component.
 
Methods inherited from class ice.ri.enhancedawt.iscl.LightweightBase
addNotify, getMinimumSize, getPreferredSize
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, 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, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HIGHLIGHTED_IMAGE

protected static final String HIGHLIGHTED_IMAGE
the file name for the hover image - "highlighted"

See Also:
Constant Field Values

PRESSED_IMAGE

protected static final String PRESSED_IMAGE
the file name for the pressed image - "pressed"

See Also:
Constant Field Values

NORMAL_IMAGE

protected static final String NORMAL_IMAGE
the file name for the normal image - "normal"

See Also:
Constant Field Values

DISABLED_IMAGE

protected static final String DISABLED_IMAGE
the file name for the disabled image - "disabled"

See Also:
Constant Field Values

m_skin

protected Skin m_skin
The Skin for this button.


DEFAULT_SKIN

public static final String DEFAULT_SKIN
See Also:
Constant Field Values

m_skinName

protected String m_skinName

HIGHLIGHTED

protected static final int HIGHLIGHTED
states of the button

See Also:
Constant Field Values

PRESSED

protected static final int PRESSED
states of the button

See Also:
Constant Field Values

NORMAL

protected static final int NORMAL
states of the button

See Also:
Constant Field Values

DISABLED

protected static final int DISABLED
states of the button

See Also:
Constant Field Values

OFF_PRESSED

protected static final int OFF_PRESSED
states of the button

See Also:
Constant Field Values

m_state

protected int m_state
the current state of the button


m_skinManager

protected SkinManager m_skinManager
Constructor Detail

SkinnableButton

public SkinnableButton()
default constructor. no picture is set.


SkinnableButton

public SkinnableButton(String name,
                       SkinManager skinManager,
                       String skinName)
Method Detail

setSkinManager

public void setSkinManager(SkinManager skinManager)

getSkinManager

public SkinManager getSkinManager()

setSkin

public void setSkin(String skinName)
Sets all the necessary images through a directory structure and predetermined names. This method will look up the images through the string "/images///.gif". the image names can be looked up in under the protected fields. The images themselves are loaded using PublicClassLoader.

Specified by:
setSkin in interface Skinnable
Parameters:
skinName - provides the directory structure in which to look for the images.

figureMySize

protected Dimension figureMySize(Graphics g)
Description copied from class: LightweightBase
* Abstract method which must be defined in child classes to determine * their sizes. * * @see dph.awt.lightweight.Checkbox.figureMySize * @see dph.awt.lightweight.FlatButton.figureMySize * @see dph.awt.lightweight.RoundButton.figureMySize * @see dph.awt.lightweight.Spinner.figureMySize * @see getPreferredSize * * @param g Graphics context of this component

Specified by:
figureMySize in class LightweightBase

getSkin

public String getSkin()
Gets the skin being used by this component.

Specified by:
getSkin in interface Skinnable
Returns:
the current skin.

getActionCommand

public String getActionCommand()
get the action command that will be sent with ActionEvent, when one is fired

Returns:
the action command of this button.

setActionCommand

public void setActionCommand(String p_command)
set the action command that will be sent with ActionEvent, when one is fired

Parameters:
p_command - the action command of this button.

setLabel

public void setLabel(String p_label)
explicitly sets the label that appears on the button in its default representation, or when setShowingLabel is set to true


getLabel

public String getLabel()
gets the label that appears on the button in its default representation, or when setShowingLabel is set to true

Returns:
the label

setShowingLabel

public void setShowingLabel(boolean p_show)
tells the button to show the label even if there are images set

Parameters:
p_show - true to show the label, false not to show the label

isShowingLabel

public boolean isShowingLabel()
finds out if the button shows the label even if there are images set

Returns:
true if the button shows the label even if there are images set, false otherwise

addActionListener

public void addActionListener(ActionListener p_newListener)
adds an ActionListener.

Parameters:
p_newListener - a listener that is interested in getting ActionEvents from this button

removeActionListener

public void removeActionListener(ActionListener p_oldListener)
removes an ActionListener from listening to this button.

Parameters:
p_oldListener - the listener to be removed.

setEnabled

public void setEnabled(boolean enabled)
enables / disables the button

Overrides:
setEnabled in class LightweightBase
Parameters:
enabled - the state of the button: true - enabled, false - disabled.

processMouseEvent

public void processMouseEvent(MouseEvent e)
this method processes mouse event recieved from the user. the button needs to repaint itself based on the mouse clicks and movements, as well as fire ActionEvents when the user clicks on the button


update

public void update(Graphics g)
overriden method from component.

Overrides:
update in class LightweightBase

paint

public void paint(Graphics g)
overriden method from Component


drawLabel

public void drawLabel(Graphics g)
called to draw the label on the button.


drawButton

public void drawButton(Graphics g)
called to draw a button which has no images associated with it.