com.lizardtech.djvubean.toolbar
Class ToggleButton

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by com.lizardtech.djvubean.toolbar.ToggleButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.io.Serializable

public class ToggleButton
extends java.awt.Container
implements java.awt.ItemSelectable

This class is intended as an AWT replacement of JButton and JToggleButton.

Version:
$Revision: 1.3 $
Author:
Bill C. Riemers
See Also:
Serialized Form

Nested Class Summary
 
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
static int NOBORDER
          Constant to incidate no border should be painted.
static boolean OLD_JAVA
          query java version.
static int RAISED_BORDER
          Constant to incidate a raised border should be painted.
static int SIMPLE_BORDER
          Constant to incidate a simple border should be painted.
 
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
ToggleButton(java.lang.String tip, java.lang.String text, java.lang.Object imageArg, java.awt.Dimension defaultSize)
          Creates a new ToggleButton object equivalent to JButton.
ToggleButton(java.lang.String tip, java.lang.String text, java.lang.Object imageArg, java.awt.Dimension defaultSize, boolean isSelected)
          Creates a new ToggleButton object equivalent to JToggleButton.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener listener)
          Add a new ActionListener.
 void addItemListener(java.awt.event.ItemListener listener)
          Add a new ItemListener.
 void drawIcon(java.awt.Graphics g)
          Called to draw this this button.
 void drawImage(java.awt.Graphics g, java.awt.Image image, int xOffset)
          Called to draw the image at the specified offset.
 java.lang.String getActionCommand()
          Query the action command.
 java.awt.event.ActionListener[] getActionListeners()
          Query currently registered ActionListener objects.
 int getBorderType()
          Query the border type.
 int getBorderX()
          Get the border along the X axis.
 int getBorderY()
          Get the border along the Y axis.
protected  java.awt.Image getImage(java.lang.Object imageArg)
          Called to load an image.
protected  int getImageHeight()
          Query the height of the image.
protected  int getImageHeightScaled()
          Query the scaled height of the image.
protected  int getImageWidth()
          Query the width of the image.
protected  int getImageWidthScaled()
          Query the scaled width of the image.
 java.awt.event.ItemListener[] getItemListeners()
          Query currently registered ItemListener objects.
 java.lang.String getLabel()
          Query the text label for this button.
 java.awt.Dimension getMaximumSize()
          Query the maximum image size allowed.
 java.awt.Dimension getMinimumSize()
          Query the minimum image size allowed.
 java.awt.Dimension getPreferredSize()
          Query the preferred image size allowed.
 double getScaleFactor()
          Query the scale resizing factor used for the image.
 java.lang.Object[] getSelectedObjects()
          Return an array of this item if selected, otherwise an empty array is returned.
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
          Callback called to indicate the icon image has been updated.
 boolean isSelected()
          Query if selected.
 void paint(java.awt.Graphics g)
          Called to draw the button.
 void paintAll(java.awt.Graphics g)
          Called to paint the component.
protected  void processActionEvent(java.awt.event.ActionEvent event)
          Called to process an ActionEvent.
protected  void processEvent(java.awt.AWTEvent event)
          Called to process an event.
protected  void processItemEvent(java.awt.event.ItemEvent event)
          Called to process an item event.
protected  void processMouseEvent(java.awt.event.MouseEvent event)
          Called when the mouse has updated.
 void removeActionListener(java.awt.event.ActionListener listener)
          Remove an ActionListener.
 void removeItemListener(java.awt.event.ItemListener listener)
          Remove an ItemListener.
 void repaintWait(long timeout)
          Called to invoke a repaint, and wait upto the specified timeout value in milliseconds for the update() method to be invoked.
 void setActionCommand(java.lang.String actionCommand)
          Set the action command.
 void setBorderType(int borderType)
          Sets the border type.
 void setEnabled(boolean enabled)
          Set the enabled property of this Component.
protected  void setImageHeight(int height)
          Set the height of the image.
protected  void setImageWidth(int width)
          Set the width of the image.
 void setLabel(java.lang.String text)
          Set the text label for this button.
 void setScaleFactor(double value)
          Set the scale resizing factor used for the image.
 void setSelected(boolean value)
          Set the selected value.
 void update(java.awt.Graphics g)
          Called to draw the button.
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, 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, getAccessibleContext, 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, 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, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, 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, 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

OLD_JAVA

public static final boolean OLD_JAVA
query java version.


NOBORDER

public static final int NOBORDER
Constant to incidate no border should be painted.

See Also:
Constant Field Values

RAISED_BORDER

public static final int RAISED_BORDER
Constant to incidate a raised border should be painted.

See Also:
Constant Field Values

SIMPLE_BORDER

public static final int SIMPLE_BORDER
Constant to incidate a simple border should be painted.

See Also:
Constant Field Values
Constructor Detail

ToggleButton

public ToggleButton(java.lang.String tip,
                    java.lang.String text,
                    java.lang.Object imageArg,
                    java.awt.Dimension defaultSize)
Creates a new ToggleButton object equivalent to JButton.

Parameters:
tip - Tool tip to display. (For future use.)
text - Text to display.
imageArg - Image to display.
defaultSize - default button size.

ToggleButton

public ToggleButton(java.lang.String tip,
                    java.lang.String text,
                    java.lang.Object imageArg,
                    java.awt.Dimension defaultSize,
                    boolean isSelected)
Creates a new ToggleButton object equivalent to JToggleButton.

Parameters:
tip - Tool tip to display. (For future use.)
text - Text to display.
imageArg - Image to display.
defaultSize - default button size.
isSelected - Initial selection value.
Method Detail

setActionCommand

public void setActionCommand(java.lang.String actionCommand)
Set the action command.

Parameters:
actionCommand - string to set.

getActionCommand

public java.lang.String getActionCommand()
Query the action command.

Returns:
actionCommand string.

getActionListeners

public java.awt.event.ActionListener[] getActionListeners()
Query currently registered ActionListener objects.

Returns:
array of ActionListener objects.

setBorderType

public void setBorderType(int borderType)
Sets the border type.

Parameters:
borderType - how to draw the border.

getBorderType

public int getBorderType()
Query the border type.

Returns:
the border type.

getBorderX

public int getBorderX()
Get the border along the X axis.

Returns:
border along the X axis.

getBorderY

public int getBorderY()
Get the border along the Y axis.

Returns:
border along the Y axis.

setEnabled

public void setEnabled(boolean enabled)
Set the enabled property of this Component.

Overrides:
setEnabled in class java.awt.Component
Parameters:
enabled - true if enabled.

getItemListeners

public java.awt.event.ItemListener[] getItemListeners()
Query currently registered ItemListener objects.

Returns:
array of ItemListener objects.

setLabel

public void setLabel(java.lang.String text)
Set the text label for this button.

Parameters:
text - label for this button.

getLabel

public java.lang.String getLabel()
Query the text label for this button.

Returns:
text label for this button.

getMaximumSize

public java.awt.Dimension getMaximumSize()
Query the maximum image size allowed.

Overrides:
getMaximumSize in class java.awt.Container
Returns:
the maximum image size allowed.

getMinimumSize

public java.awt.Dimension getMinimumSize()
Query the minimum image size allowed.

Overrides:
getMinimumSize in class java.awt.Container
Returns:
the minimum image size allowed.

getPreferredSize

public java.awt.Dimension getPreferredSize()
Query the preferred image size allowed.

Overrides:
getPreferredSize in class java.awt.Container
Returns:
the preferred image size allowed.

setScaleFactor

public void setScaleFactor(double value)
Set the scale resizing factor used for the image.

Parameters:
value - scale factor used for resizing the image.

getScaleFactor

public double getScaleFactor()
Query the scale resizing factor used for the image.

Returns:
scale factor used for resizing the image.

setSelected

public void setSelected(boolean value)
Set the selected value.

Parameters:
value - true if selected.

isSelected

public boolean isSelected()
Query if selected.

Returns:
true if selected.

getSelectedObjects

public java.lang.Object[] getSelectedObjects()
Return an array of this item if selected, otherwise an empty array is returned.

Specified by:
getSelectedObjects in interface java.awt.ItemSelectable
Returns:
array of selected objects.

addActionListener

public void addActionListener(java.awt.event.ActionListener listener)
Add a new ActionListener.

Parameters:
listener - to add.

addItemListener

public void addItemListener(java.awt.event.ItemListener listener)
Add a new ItemListener.

Specified by:
addItemListener in interface java.awt.ItemSelectable
Parameters:
listener - to add.

drawIcon

public void drawIcon(java.awt.Graphics g)
Called to draw this this button.

Parameters:
g - Graphics device to draw to.

drawImage

public void drawImage(java.awt.Graphics g,
                      java.awt.Image image,
                      int xOffset)
Called to draw the image at the specified offset.

Parameters:
g - graphics object to draw.
image - to draw.
xOffset - offset along the X axis.

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
Callback called to indicate the icon image has been updated.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Overrides:
imageUpdate in class java.awt.Component
Parameters:
img - updated image.
infoflags - flags indicating update status.
x - coordinate of the image.
y - coordinate of the image.
width - of the image.
height - height of the image.
Returns:
true if further updates are neccissary.

paint

public void paint(java.awt.Graphics g)
Called to draw the button.

Overrides:
paint in class java.awt.Container
Parameters:
g - Graphics device to draw to.

paintAll

public void paintAll(java.awt.Graphics g)
Called to paint the component.

Overrides:
paintAll in class java.awt.Component
Parameters:
g - graphics object to paint.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener listener)
Remove an ActionListener.

Parameters:
listener - to remove.

removeItemListener

public void removeItemListener(java.awt.event.ItemListener listener)
Remove an ItemListener.

Specified by:
removeItemListener in interface java.awt.ItemSelectable
Parameters:
listener - to remove.

repaintWait

public void repaintWait(long timeout)
Called to invoke a repaint, and wait upto the specified timeout value in milliseconds for the update() method to be invoked.

Parameters:
timeout - maximum time to wait.

update

public void update(java.awt.Graphics g)
Called to draw the button.

Overrides:
update in class java.awt.Container
Parameters:
g - Graphics device to draw to.

getImage

protected java.awt.Image getImage(java.lang.Object imageArg)
Called to load an image.

Parameters:
imageArg - argument indicating the image, URL, or string path of the image to load.
Returns:
the loaded image.

setImageHeight

protected void setImageHeight(int height)
Set the height of the image.

Parameters:
height - of the image.

getImageHeight

protected int getImageHeight()
Query the height of the image.

Returns:
height of the image.

getImageHeightScaled

protected int getImageHeightScaled()
Query the scaled height of the image.

Returns:
scaled height of the image.

setImageWidth

protected void setImageWidth(int width)
Set the width of the image.

Parameters:
width - of the image.

getImageWidth

protected int getImageWidth()
Query the width of the image.

Returns:
width of the image.

getImageWidthScaled

protected int getImageWidthScaled()
Query the scaled width of the image.

Returns:
scaled width of the image.

processActionEvent

protected void processActionEvent(java.awt.event.ActionEvent event)
Called to process an ActionEvent.

Parameters:
event - event to process.

processEvent

protected void processEvent(java.awt.AWTEvent event)
Called to process an event.

Overrides:
processEvent in class java.awt.Container
Parameters:
event - to process.

processItemEvent

protected void processItemEvent(java.awt.event.ItemEvent event)
Called to process an item event.

Parameters:
event - event to process.

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent event)
Called when the mouse has updated. If the mouse is clicked the selected property will be updated.

Overrides:
processMouseEvent in class java.awt.Component
Parameters:
event - describes the mouse update.