com.tecnick.jrelaxtimer
Class ImageButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by com.tecnick.jrelaxtimer.ImageButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class ImageButton
extends java.awt.Panel

Title: ImageButton Class

Description: Class to create image buttons with text and behaviour


Copyright (c) 2002-2006 Tecnick.com S.r.l (www.tecnick.com) Via Ugo Foscolo n.19 - 09045 Quartu Sant'Elena (CA) - ITALY - www.tecnick.com - info@tecnick.com
Project homepage: http://jxhtmledit.sourceforge.net
License: http://www.gnu.org/copyleft/gpl.html GPL 2

Version:
1.0.001
Author:
Nicola Asuni [www.tecnick.com].
See Also:
Serialized Form

Nested Class Summary
(package private)  class ImageButton.Mouse
          Inner class for handing mouse events.
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.lang.String actionCommand
          action command to be returned to the listener
protected  java.awt.event.ActionListener actionListener
          the action listener (for events)
private  int bh
          height of background image in pixels
private  boolean button_state
          true if element is a closed node
private  int buttonID
          menu item id to be returned on event as actionCommand
private  int bw
          width of background image in pixels
private  int bx
          horizontal position of background image
private  int by
          vertical position of background image
private  float imageScale
          float parameter to scale the image size
private  java.awt.Image img_bg
          current background button image
private  java.awt.Image img_bg_off
          button background image for normal state
private  java.awt.Image img_bg_on
          button background image for button pressed
private  java.awt.Image img_bg_over
          button background image for mouse over
private  java.awt.Image inactive_img
          inactive image for disabled button
protected  boolean isMouseDown
          Remember mouse up/down status
protected  boolean isMouseInside
          Remember mouse ino/out status
private static long serialVersionUID
          serialVersionUID
 
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
ImageButton()
          Void Constructor
ImageButton(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
          Constructor
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          Adds the specified action listener to receive action events from this button.
 void addNotify()
          Creates the Panel's peer.
protected  void fireActionEvent(int actiontype)
          Fire an action event to the listeners.
 java.lang.String getActionCommand()
          Returns the command name of the action event fired by this button.
 int getButtonID()
          Get the buttonID (unique numeric identifier for current component)
 boolean getButtonStatus()
          Get the current node status.
protected  void ImageButton_MouseEntered(java.awt.event.MouseEvent event)
          Gets called when the mouse crosses into the connector area.
protected  void ImageButton_MouseExited(java.awt.event.MouseEvent event)
          Gets called when the mouse crosses out of the connector area.
protected  void ImageButton_MousePressed(java.awt.event.MouseEvent event)
          Gets called when the mouse button is pressed.
protected  void ImageButton_MouseReleased(java.awt.event.MouseEvent event)
          Gets called when the mouse button is released on this connector.
 void paint(java.awt.Graphics g)
          Draw button elements (border, image and label) at calculated positions
 void removeActionListener(java.awt.event.ActionListener l)
          Removes the specified action listener so it no longer receives action events from this button.
protected  void repaintButton()
          Redraw the button object
protected  void repaintImages()
          Redraw the button images
 void resize()
          Resize the size of button and components.
 void setActionCommand(java.lang.String command)
          Sets the command name of the action event fired by this button.
 void setBgImage(java.awt.Image i)
          Set the current background image to be shown.
 void setButtonID(int id)
          Set buttonID (unique numeric identifier for current component)
 void setButtonStatus(boolean status)
          Set the current node status (open/closed)
 void setEnable(boolean a)
          Enables or disables this component, depending on the value of the parameter b.
 void setImageScale(double f)
          Scale the image to the given value (1.0 = 100%).
 void setImageScale(float pct)
          Scale the image to the given value (1.0 = 100%).
 void setStateBgImages(java.awt.Image imgoff, java.awt.Image imgon, java.awt.Image imgover)
          Set the background state images (one image for each button/mouse state)
 
Methods inherited from class java.awt.Panel
getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

serialVersionUID

private static final long serialVersionUID
serialVersionUID

See Also:
Constant Field Values

actionCommand

protected java.lang.String actionCommand
action command to be returned to the listener


actionListener

protected java.awt.event.ActionListener actionListener
the action listener (for events)


isMouseDown

protected boolean isMouseDown
Remember mouse up/down status


isMouseInside

protected boolean isMouseInside
Remember mouse ino/out status


buttonID

private int buttonID
menu item id to be returned on event as actionCommand


img_bg

private java.awt.Image img_bg
current background button image


img_bg_off

private java.awt.Image img_bg_off
button background image for normal state


img_bg_on

private java.awt.Image img_bg_on
button background image for button pressed


img_bg_over

private java.awt.Image img_bg_over
button background image for mouse over


inactive_img

private java.awt.Image inactive_img
inactive image for disabled button


imageScale

private float imageScale
float parameter to scale the image size


bx

private int bx
horizontal position of background image


by

private int by
vertical position of background image


bw

private int bw
width of background image in pixels


bh

private int bh
height of background image in pixels


button_state

private boolean button_state
true if element is a closed node

Constructor Detail

ImageButton

public ImageButton()
Void Constructor


ImageButton

public ImageButton(java.awt.Image imgoff,
                   java.awt.Image imgon,
                   java.awt.Image imgover)
Constructor

Parameters:
imgoff - button image for mouse off state
imgon - button image for mouse clicked state
imgover - button image for mouse over state
Method Detail

addNotify

public void addNotify()
Creates the Panel's peer. The peer allows you to modify the appearance of the panel without changing its functionality.

Overrides:
addNotify in class java.awt.Panel

setButtonID

public void setButtonID(int id)
Set buttonID (unique numeric identifier for current component)

Parameters:
id - button ID

getButtonID

public int getButtonID()
Get the buttonID (unique numeric identifier for current component)

Returns:
buttonID

setStateBgImages

public void setStateBgImages(java.awt.Image imgoff,
                             java.awt.Image imgon,
                             java.awt.Image imgover)
Set the background state images (one image for each button/mouse state)

Parameters:
imgoff - button background image when mouse is off
imgon - button background image when button is pressed
imgover - button background image when mouse is off

setBgImage

public void setBgImage(java.awt.Image i)
Set the current background image to be shown.

Parameters:
i - Button Background Image

setImageScale

public void setImageScale(double f)
Scale the image to the given value (1.0 = 100%).

Parameters:
f - float

setImageScale

public void setImageScale(float pct)
Scale the image to the given value (1.0 = 100%).

Parameters:
pct - float

setEnable

public void setEnable(boolean a)
Enables or disables this component, depending on the value of the parameter b. An enabled component can respond to user input and generate events. Components are enabled initially by default.

Parameters:
a - If true, this component is enabled; otherwise this component is disabled

resize

public void resize()
Resize the size of button and components.


repaintButton

protected void repaintButton()
Redraw the button object


repaintImages

protected void repaintImages()
Redraw the button images


paint

public void paint(java.awt.Graphics g)
Draw button elements (border, image and label) at calculated positions

Overrides:
paint in class java.awt.Container
Parameters:
g - the graphic area when diplay button elements

getButtonStatus

public boolean getButtonStatus()
Get the current node status.

Returns:
status Current Status (true = closed; false = opened)

setButtonStatus

public void setButtonStatus(boolean status)
Set the current node status (open/closed)

Parameters:
status - New status (true = closed; false = opened).

setActionCommand

public void setActionCommand(java.lang.String command)
Sets the command name of the action event fired by this button.

Parameters:
command - The name of the action event command fired by this button

getActionCommand

public java.lang.String getActionCommand()
Returns the command name of the action event fired by this button.

Returns:
the action command name

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Adds the specified action listener to receive action events from this button.

Parameters:
l - the action listener

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
Removes the specified action listener so it no longer receives action events from this button.

Parameters:
l - the action listener

fireActionEvent

protected void fireActionEvent(int actiontype)
Fire an action event to the listeners.

Parameters:
actiontype - ActionEvent.ACTION_PERFORMED,

ImageButton_MousePressed

protected void ImageButton_MousePressed(java.awt.event.MouseEvent event)
Gets called when the mouse button is pressed. Repaint images.

Parameters:
event - Mouse Event

ImageButton_MouseReleased

protected void ImageButton_MouseReleased(java.awt.event.MouseEvent event)
Gets called when the mouse button is released on this connector. Repaint images.

Parameters:
event - Mouse Event

ImageButton_MouseEntered

protected void ImageButton_MouseEntered(java.awt.event.MouseEvent event)
Gets called when the mouse crosses into the connector area. Repaint images.

Parameters:
event - Mouse Event

ImageButton_MouseExited

protected void ImageButton_MouseExited(java.awt.event.MouseEvent event)
Gets called when the mouse crosses out of the connector area. Repaint images.

Parameters:
event - Mouse Event