Project MVC architecture
version 0.1 - 010723

lib.gui
Class ImageButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--lib.gui.ImageCanvas
                    |
                    +--lib.gui.ImageButton
All Implemented Interfaces:
javax.accessibility.Accessible, java.util.EventListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable

public class ImageButton
extends ImageCanvas
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.ItemSelectable

A Button or ToggleButton with a switcheable background out of gif image regions.

Version:
1.0 18/05/2000
Author:
Ivan Wellesz
See Also:
Serialized Form

Inner classes inherited from class java.awt.Canvas
java.awt.Canvas.AccessibleAWTCanvas
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.AWTTreeLock
 
Field Summary
(package private)  java.awt.event.ActionListener actionListener
          Last registered ActionListener.
static int ACTIVATED
          Button activated state.
 java.lang.String alternateLabel
           
static int ARMED
          ToggleButton armed state.
protected  boolean bistable
          Is a toggle button.
private static int CENTER
           
(package private) static java.awt.Font defaultFont
          Class level default Font;
static int DISARMED
          ToggleButton disarmed state.
private  java.awt.FontMetrics fm
           
protected  java.awt.Font font
          Button label Font.
(package private)  java.awt.event.ActionListener helpActionListener
          Last registered help ActionListener.
protected  java.awt.Image image_activated
          Background image in its activated state.
protected  java.awt.Image image_armed
          Background image in its armed state.
 java.lang.String initialLabel
           
(package private)  java.awt.event.ItemListener itemListener
          Last registered ItemListener for a toggleButton.
private  int justification
           
 java.lang.String label
          Button labelString.
private static int LEFT
          Justification;
protected  boolean mouseEntered_state
          Set when mouse entered the button display area.
protected  boolean mousePressed_state
          Set when mouse button pressed in the button display area.
protected  boolean offTransitionEnabled
          Report OFF TO ON TOGGLE BUTTON TRANSITIONS to ItemListener.
private static int RIGHT
           
protected  boolean sensitive
          Wether this button is sensitive or not.
protected  boolean toggleState
          Current toggle button selected state.
private  int triState
          Tristate external control.
 
Fields inherited from class lib.gui.ImageCanvas
image, regionHeight, regionOffsetX, regionOffsetY, regionWidth
 
Fields inherited from class java.awt.Canvas
base, nameCounter, serialVersionUID
 
Fields inherited from class java.awt.Component
accessibleContext, actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, changeSupport, componentListener, componentListenerK, componentOrientation, componentSerializedDataVersion, containerListenerK, cursor, dbg, dropTarget, enabled, eventMask, focusListener, focusListenerK, foreground, graphicsConfig, hasFocus, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, name, nameExplicitlySet, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, privateKey, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowListenerK, x, y
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ImageButton()
           
ImageButton(java.awt.Image image, java.awt.Image image_armed, java.awt.Image image_activated, java.lang.String label, int regionOffsetX, int regionOfsfetY, int regionWidth, int regionHeight)
           
ImageButton(java.awt.Image image, java.awt.Image image_armed, java.awt.Image image_activated, java.lang.String label, java.awt.Rectangle r)
           
ImageButton(java.lang.String label)
           
 
Method Summary
 void addActionListener(java.awt.event.ActionListener l)
          Add the specified action listener to receive action events from this button.
 void addHelpActionListener(java.awt.event.ActionListener l)
          Add the specified help action listener.
 void addItemListener(java.awt.event.ItemListener l)
          Adds the specified item listener to receive item events from this ToggleButton.
private  void call_actionListener_HelpCB(boolean entered)
          Call the helpActionListener.
 void enableOffTransition(boolean state)
          Enable this ImageButton to report OFF TO ON TOGGLE BUTTON TRANSITIONS.
 java.lang.String getLabel()
           
 java.lang.Object[] getSelectedObjects()
           
 boolean getState()
          Whether this ToggleButton is in the on or off state.
 boolean is_bistable()
           
 void justify_CENTER()
           
 void justify_LEFT()
          Set the justification.
 void justify_RIGHT()
           
 void paint(java.awt.Graphics g)
          Draw graphics.
private  void paintLabel(java.awt.Graphics g)
          Display the label String.
protected  java.lang.String paramString()
          Construct the instance String desctiption.
 void process_mouseEntered(int x, int y, int modifiers)
          Process mouse entered event.
 void process_mouseExited(int x, int y, int modifiers)
          Process mouse leaved event.
 void process_mousePressed(int x, int y, int modifiers)
          Process a mouse pressed event.
 void process_mouseReleased(int x, int y, int modifiers)
          Process a mouse released event.
 void removeActionListener(java.awt.event.ActionListener l)
          Remove the specified action listener so that it no longer receives action events from this button.
 void removeItemListener(java.awt.event.ItemListener l)
          Removes the specified item listener so that the item listener no longer receives item events from this ImageButton.
 void setEnabled(boolean new_state)
          Set / unset the sensitive state of the button.
 void setFont(java.awt.Font font)
          Set the instance Font.
static void setFontDefault(java.awt.Font font)
           
 void setImages(java.awt.Image image, java.awt.Image image_armed, java.awt.Image image_activated)
          Change image.
 void setLabel(java.lang.String label)
           
 void setRegion(java.awt.Rectangle r)
           
 void setSensitive(boolean new_state)
           
 void setState(boolean new_state)
          Sets the state of this ImageButton to the specified state.
 void setText(java.lang.String label)
          Change label string.
 void setTriState(int new_triState)
          Sets the state of this ImageButton to the specified state.
 void toggle()
          Sets the state of this ImageButton to the alternate state.
 void update(java.awt.Graphics g)
          Update graphics.
 
Methods inherited from class lib.gui.ImageCanvas
isDoubleBuffered, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, process_mouseClicked, process_mouseDragged, process_mouseMoved
 
Methods inherited from class java.awt.Canvas
, addNotify, constructComponentName, getAccessibleContext, postsOldMouseEvents
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, areInputMethodsEnabled, bounds, checkGD, checkImage, checkImage, checkWindowClosingException, coalesceEvents, contains, contains, createChildHierarchyEvents, createHierarchyEvents, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, doLayout, enable, enable, enableEvents, enableInputMethods, eventEnabled, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getWindowForObject, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initIDs, inside, invalidate, isDisplayable, isEnabled, isEnabledImpl, isFocusTraversable, isLightweight, isOpaque, isRecursivelyVisible, isShowing, isValid, isVisible, keyDown, keyUp, layout, lightweightPaint, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, numListening, paintAll, paintHeavyweightComponents, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, printHeavyweightComponents, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, readObject, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, resetGC, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate, writeObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 
Methods inherited from interface java.awt.event.MouseListener
mouseClicked, mouseEntered, mouseExited, mousePressed, mouseReleased
 
Methods inherited from interface java.awt.event.MouseMotionListener
mouseDragged, mouseMoved
 

Field Detail

LEFT

private static final int LEFT
Justification;

CENTER

private static final int CENTER

RIGHT

private static final int RIGHT

image_armed

protected java.awt.Image image_armed
Background image in its armed state.

image_activated

protected java.awt.Image image_activated
Background image in its activated state.

mouseEntered_state

protected boolean mouseEntered_state
Set when mouse entered the button display area.

mousePressed_state

protected boolean mousePressed_state
Set when mouse button pressed in the button display area.

bistable

protected boolean bistable
Is a toggle button.

offTransitionEnabled

protected boolean offTransitionEnabled
Report OFF TO ON TOGGLE BUTTON TRANSITIONS to ItemListener.

toggleState

protected boolean toggleState
Current toggle button selected state.

sensitive

protected boolean sensitive
Wether this button is sensitive or not.

label

public java.lang.String label
Button labelString.

alternateLabel

public java.lang.String alternateLabel

initialLabel

public java.lang.String initialLabel

font

protected java.awt.Font font
Button label Font.

fm

private java.awt.FontMetrics fm

justification

private int justification

actionListener

transient java.awt.event.ActionListener actionListener
Last registered ActionListener.

helpActionListener

transient java.awt.event.ActionListener helpActionListener
Last registered help ActionListener.

itemListener

transient java.awt.event.ItemListener itemListener
Last registered ItemListener for a toggleButton.

DISARMED

public static final int DISARMED
ToggleButton disarmed state.

ARMED

public static final int ARMED
ToggleButton armed state.

ACTIVATED

public static final int ACTIVATED
Button activated state.

defaultFont

static java.awt.Font defaultFont
Class level default Font;

triState

private int triState
Tristate external control.
Constructor Detail

ImageButton

public ImageButton()

ImageButton

public ImageButton(java.lang.String label)

ImageButton

public ImageButton(java.awt.Image image,
                   java.awt.Image image_armed,
                   java.awt.Image image_activated,
                   java.lang.String label,
                   java.awt.Rectangle r)
Parameters:
image - image from which to draw a region
image_armed* - Background image in its armed state
image_activated* - Background image in its activated state
label - Label name.
r - region geometry

ImageButton

public ImageButton(java.awt.Image image,
                   java.awt.Image image_armed,
                   java.awt.Image image_activated,
                   java.lang.String label,
                   int regionOffsetX,
                   int regionOfsfetY,
                   int regionWidth,
                   int regionHeight)
Parameters:
image - image from which to draw a region
image_armed* - Background image in its armed state
image_activated* - Background image in its activated state
label - Label name.
regionOffsetX - region origin left offset
regionOffsetY - region origin top offset
regionWidth - region width
regionHeight - region height
Method Detail

setFontDefault

public static void setFontDefault(java.awt.Font font)

setFont

public void setFont(java.awt.Font font)
Set the instance Font.
Overrides:
setFont in class java.awt.Component

justify_LEFT

public void justify_LEFT()
Set the justification.

justify_CENTER

public void justify_CENTER()

justify_RIGHT

public void justify_RIGHT()

setText

public void setText(java.lang.String label)
Change label string.

setLabel

public void setLabel(java.lang.String label)

setImages

public void setImages(java.awt.Image image,
                      java.awt.Image image_armed,
                      java.awt.Image image_activated)
Change image.
Parameters:
image - image from which to draw a region

setRegion

public void setRegion(java.awt.Rectangle r)

enableOffTransition

public void enableOffTransition(boolean state)
Enable this ImageButton to report OFF TO ON TOGGLE BUTTON TRANSITIONS.

getLabel

public java.lang.String getLabel()

is_bistable

public boolean is_bistable()

update

public void update(java.awt.Graphics g)
Update graphics. Do not clear the display area when updating.
Overrides:
update in class ImageCanvas
Parameters:
g - the graphics to use for painting

paint

public void paint(java.awt.Graphics g)
Draw graphics.
Overrides:
paint in class ImageCanvas
Parameters:
g - the graphics to use for painting

paintLabel

private void paintLabel(java.awt.Graphics g)
Display the label String.

setEnabled

public void setEnabled(boolean new_state)
Set / unset the sensitive state of the button.
Overrides:
setEnabled in class java.awt.Component

setSensitive

public void setSensitive(boolean new_state)

process_mouseEntered

public void process_mouseEntered(int x,
                                 int y,
                                 int modifiers)
Process mouse entered event.
Overrides:
process_mouseEntered in class ImageCanvas

process_mouseExited

public void process_mouseExited(int x,
                                int y,
                                int modifiers)
Process mouse leaved event.
Overrides:
process_mouseExited in class ImageCanvas

call_actionListener_HelpCB

private void call_actionListener_HelpCB(boolean entered)
Call the helpActionListener.
Sends an ActionEvent.Event.META_MASK to the help actionListener.

process_mousePressed

public void process_mousePressed(int x,
                                 int y,
                                 int modifiers)
Process a mouse pressed event.
Overrides:
process_mousePressed in class ImageCanvas
Parameters:
x - mouse pointer x
y - mouse pointer y
modifiers - event modifiers

process_mouseReleased

public void process_mouseReleased(int x,
                                  int y,
                                  int modifiers)
Process a mouse released event.
Overrides:
process_mouseReleased in class ImageCanvas
Parameters:
x - mouse pointer x
y - mouse pointer y
modifiers - event modifiers

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
Add 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)
Remove the specified action listener so that it no longer receives action events from this button.
Parameters:
l - the action listener.

addHelpActionListener

public void addHelpActionListener(java.awt.event.ActionListener l)
Add the specified help action listener.
Parameters:
l - the action listener.

addItemListener

public void addItemListener(java.awt.event.ItemListener l)
Adds the specified item listener to receive item events from this ToggleButton.
Specified by:
addItemListener in interface java.awt.ItemSelectable
Parameters:
l - the item listener.

removeItemListener

public void removeItemListener(java.awt.event.ItemListener l)
Removes the specified item listener so that the item listener no longer receives item events from this ImageButton.
Specified by:
removeItemListener in interface java.awt.ItemSelectable
Parameters:
l - the item listener.

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Specified by:
getSelectedObjects in interface java.awt.ItemSelectable

getState

public boolean getState()
Whether this ToggleButton is in the on or off state.

setState

public void setState(boolean new_state)
Sets the state of this ImageButton to the specified state.

toggle

public void toggle()
Sets the state of this ImageButton to the alternate state.

setTriState

public void setTriState(int new_triState)
Sets the state of this ImageButton to the specified state.

paramString

protected java.lang.String paramString()
Construct the instance String desctiption.
Overrides:
paramString in class java.awt.Component

MVC architecture

Document Tech Infos - Ivan Wellesz