dog.gui
Class DButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--dog.gui.DComponent
              |
              +--dog.gui.DCheckbox
                    |
                    +--dog.gui.DButton
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, Referential, java.io.Serializable

public class DButton
extends DCheckbox

A multiline button with an optional icon.

The button can be in one of two states: up or down. Normally it is only down while the user is pressing the button. This generates an action event when the button is released. By setting the button to sticky you change the behaviour of the button to that of a checkbox: the button stays down when the user releases the mouse, and will only be released when the user presses the button again. The latter behaviour generates item events (a state change of 1 indicates that the button is down, and 0 indicates that is it up).

The behaviour of buttons in sticky mode is controlled by setting a DCheckboxGroup manager. This handles the dependencies between a set of buttons and checkboxes.

You can specify a label and/or an icon for the button. If a label is specified without an icon, or an icon without a label, it is centred on the button. If both an icon and label are specified, the icon is drawn to the left, and the label is left-aligned against the right-hand edge of the icon. The icon is scaled to fit in the button if it is too large.

See Also:
Serialized Form

Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
protected  boolean bold
          Whether to use a bold font for the button label.
protected  java.awt.Image icon
          The button icon.
static int LEFT
          The left alignment.
static int RIGHT
          The right alignment.
protected  boolean sticky
          The button stickiness.
 
Fields inherited from class dog.gui.DCheckbox
align, command, down, focus, group, label, value
 
Fields inherited from class dog.gui.DComponent
CENTER, CENTER_TILE, changes, EAST, INTEGER_TILE, MAXIMIZE, MAXIMIZE_ASPECT, MAXIMIZE_HORIZONTAL, MAXIMIZE_VERTICAL, NORTH, NORTHEAST, NORTHWEST, reference, SOUTH, SOUTHEAST, SOUTHWEST, TILE, tooltip, WEST
 
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
DButton()
          Constructs a button with no label or icon.
DButton(java.awt.Image icon)
          Constructs a button with the specified icon and no label.
DButton(java.awt.Image icon, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified icon, default value and group, and no label.
DButton(java.awt.Image icon, int align)
          Constructs a button with the specified icon and alignment and no label.
DButton(java.awt.Image icon, int align, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified icon, alignment, default value and group, and no label.
DButton(java.lang.String label)
          Constructs a button with the specified label.
DButton(java.lang.String label, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified label, default value and group.
DButton(java.lang.String label, DCheckboxGroup group)
          Constructs a sticky button with the specified label and group.
DButton(java.lang.String label, java.awt.Image icon)
          Constructs a button with the specified label and icon.
DButton(java.lang.String label, java.awt.Image icon, int align)
          Constructs a button with the specified label, icon, and alignment.
DButton(java.lang.String label, java.awt.Image icon, int align, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified label, icon, alignment, default value and group.
DButton(java.lang.String label, int align)
          Constructs a button with the specified label and alignment.
DButton(java.lang.String label, int align, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified label, alignment, default value and group.
DButton(java.lang.String label, java.net.URL icon)
          Constructs a button with the specified label and icon.
DButton(java.lang.String label, java.net.URL icon, int align)
          Constructs a button with the specified label, icon, and alignment.
DButton(java.lang.String label, java.net.URL icon, int align, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified label, icon, alignment, default value and group.
DButton(java.net.URL icon)
          Constructs a button with the specified icon and no label.
DButton(java.net.URL icon, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified icon, default value and group, and no label.
DButton(java.net.URL icon, int align)
          Constructs a button with the specified icon and alignment and no label.
DButton(java.net.URL icon, int align, boolean value, DCheckboxGroup group)
          Constructs a sticky button with the specified icon, alignment, default value and group, and no label.
 
Method Summary
 int getAlign()
          Returns the alignment of the checkbox (LEFT, RIGHT, or CENTER).
 java.awt.Image getIcon()
          Returns the icon.
 java.awt.Dimension getMinimumSize()
          Returns the minimum size for this button.
protected  java.awt.Dimension getPreferredIconSize(java.awt.Rectangle bounds)
          Returns the preferred icon size for the specified bounds.
protected  java.awt.Dimension getPreferredLabelSize(java.awt.FontMetrics fm)
          Returns the preferred label size.
 java.awt.Dimension getPreferredSize()
          Returns the preferred size of this button.
 boolean imageUpdate(java.awt.Image image, int flags, int x, int y, int w, int h)
          The button's icon has arrived...
 boolean isBold()
          Indicates whether the button is to be drawn in a bold font.
 boolean isCancel()
          Indicates whether this button is the cancel button in the gui.
 boolean isDefault()
          Indicates whether this button is the default button in the gui.
 boolean isSticky()
          Indicates the stickiness of the button.
 void paint(java.awt.Graphics g)
          Paints this button.
protected  java.lang.String paramString()
          Returns the parameter string for this button.
protected  void processKeyEvent(java.awt.event.KeyEvent event)
          Processes key events on this button by dispatching them to any registered KeyListeners.
protected  void processMouseEvent(java.awt.event.MouseEvent event)
          Processes mouse events on this button by dispatching them to any registered MouseListeners.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent event)
          Processes mouse motion events on this button by dispatching them to any registered MouseMotionListeners.
 void setAlign(int align)
          Sets the button alignment.
 void setBold(boolean bold)
          Sets the boldness of the button.
 void setCancel(boolean flag)
          Sets this button to be the cancel button in the gui or not.
 void setDefault(boolean flag)
          Sets this button to be the default button in the gui or not.
 void setEnabled(boolean flag)
          Sets whether or not this button is enabled.
 void setIcon(java.awt.Image icon)
          Sets the icon.
 void setIcon(java.lang.String file)
          Sets the icon from a file.
 void setIcon(java.net.URL url)
          Sets the icon from a URL.
 void setSticky(boolean sticky)
          Sets the stickiness of the button.
 
Methods inherited from class dog.gui.DCheckbox
addActionListener, getActionCommand, getGroup, getLabel, getText, getValue, isFocusTraversable, processActionEvent, processEvent, processFocusEvent, removeActionListener, setActionCommand, setGroup, setLabel, setText, setValue, update
 
Methods inherited from class dog.gui.DComponent
addPropertyChangeListener, alignParamString, drawActiveButtonBorder, drawActiveOptionBorder, drawArrow, drawBackgroundImage, drawBorder, drawButtonBorder, drawCheckbox, drawDarkBorder, drawDefaultButtonBorder, drawDisabledBorder, drawDisabledCheckbox, drawDisabledOption, drawExpander, drawFocusBorder, drawImage, drawLabel, drawOption, drawOptionBorder, drawPressedBorder, drawTick, getDefaultToolkit, getImage, getImage, getImage, getReference, getRootPane, getRows, getTooltip, isPreloadImages, parseColor, parseFont, processCancelAction, processDefaultAction, removePropertyChangeListener, setPreloadImages, setReference, setTooltip, toString
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, 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, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, transferFocus, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
The left alignment.

RIGHT

public static final int RIGHT
The right alignment.

sticky

protected boolean sticky
The button stickiness.

bold

protected boolean bold
Whether to use a bold font for the button label.

icon

protected java.awt.Image icon
The button icon.
Constructor Detail

DButton

public DButton()
Constructs a button with no label or icon.

DButton

public DButton(java.lang.String label)
Constructs a button with the specified label.

DButton

public DButton(java.lang.String label,
               int align)
Constructs a button with the specified label and alignment.

DButton

public DButton(java.awt.Image icon)
Constructs a button with the specified icon and no label.

DButton

public DButton(java.awt.Image icon,
               int align)
Constructs a button with the specified icon and alignment and no label.

DButton

public DButton(java.net.URL icon)
Constructs a button with the specified icon and no label.

DButton

public DButton(java.net.URL icon,
               int align)
Constructs a button with the specified icon and alignment and no label.

DButton

public DButton(java.lang.String label,
               java.awt.Image icon)
Constructs a button with the specified label and icon.

DButton

public DButton(java.lang.String label,
               java.net.URL icon)
Constructs a button with the specified label and icon.

DButton

public DButton(java.lang.String label,
               java.awt.Image icon,
               int align)
Constructs a button with the specified label, icon, and alignment.

DButton

public DButton(java.lang.String label,
               java.net.URL icon,
               int align)
Constructs a button with the specified label, icon, and alignment.

DButton

public DButton(java.lang.String label,
               DCheckboxGroup group)
Constructs a sticky button with the specified label and group.

DButton

public DButton(java.lang.String label,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified label, default value and group.

DButton

public DButton(java.lang.String label,
               int align,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified label, alignment, default value and group.

DButton

public DButton(java.awt.Image icon,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified icon, default value and group, and no label.

DButton

public DButton(java.net.URL icon,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified icon, default value and group, and no label.

DButton

public DButton(java.awt.Image icon,
               int align,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified icon, alignment, default value and group, and no label.

DButton

public DButton(java.net.URL icon,
               int align,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified icon, alignment, default value and group, and no label.

DButton

public DButton(java.lang.String label,
               java.awt.Image icon,
               int align,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified label, icon, alignment, default value and group.

DButton

public DButton(java.lang.String label,
               java.net.URL icon,
               int align,
               boolean value,
               DCheckboxGroup group)
Constructs a sticky button with the specified label, icon, alignment, default value and group.
Method Detail

isSticky

public boolean isSticky()
Indicates the stickiness of the button. If a button is sticky, it remains pressed in when the mouse is released. A further click is necessary to release the button.
See Also:
setSticky(boolean)

setSticky

public void setSticky(boolean sticky)
Sets the stickiness of the button.
See Also:
isSticky()

getIcon

public java.awt.Image getIcon()
Returns the icon.

setIcon

public void setIcon(java.awt.Image icon)
Sets the icon.
Parameters:
icon - the icon image.

setIcon

public void setIcon(java.lang.String file)
Sets the icon from a file.
Parameters:
file - the image file.

setIcon

public void setIcon(java.net.URL url)
Sets the icon from a URL.
Parameters:
url - the image URL.

getAlign

public int getAlign()
Returns the alignment of the checkbox (LEFT, RIGHT, or CENTER).
Overrides:
getAlign in class DCheckbox
See Also:
setAlign(int)

setAlign

public void setAlign(int align)
Sets the button alignment.
Overrides:
setAlign in class DCheckbox
Parameters:
align - LEFT, RIGHT, or CENTER.
See Also:
getAlign()

isBold

public boolean isBold()
Indicates whether the button is to be drawn in a bold font.
See Also:
setBold(boolean)

setBold

public void setBold(boolean bold)
Sets the boldness of the button.
See Also:
isBold()

isDefault

public boolean isDefault()
Indicates whether this button is the default button in the gui. The default button is the one that gets activated when text elements or the gui receive a VK_RETURN key press.
See Also:
setDefault(boolean)

setDefault

public void setDefault(boolean flag)
Sets this button to be the default button in the gui or not. The default button is the one that gets activated when text elements or the gui receive a VK_RETURN key press.
See Also:
isDefault()

isCancel

public boolean isCancel()
Indicates whether this button is the cancel button in the gui. The cancel button is the one that gets activated when text elements or the gui receive a VK_CANCEL or VK_ESCAPE key press.
See Also:
setCancel(boolean)

setCancel

public void setCancel(boolean flag)
Sets this button to be the cancel button in the gui or not. The cancel button is the one that gets activated when text elements or the gui receive a VK_CANCEL or VK_ESCAPE key press.
See Also:
isCancel()

setEnabled

public void setEnabled(boolean flag)
Sets whether or not this button is enabled.
Overrides:
setEnabled in class DComponent

imageUpdate

public boolean imageUpdate(java.awt.Image image,
                           int flags,
                           int x,
                           int y,
                           int w,
                           int h)
The button's icon has arrived...
Overrides:
imageUpdate in class java.awt.Component

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size for this button.
Overrides:
getMinimumSize in class DCheckbox

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size of this button.
Overrides:
getPreferredSize in class DCheckbox

getPreferredIconSize

protected java.awt.Dimension getPreferredIconSize(java.awt.Rectangle bounds)
Returns the preferred icon size for the specified bounds.

getPreferredLabelSize

protected java.awt.Dimension getPreferredLabelSize(java.awt.FontMetrics fm)
Returns the preferred label size.

paint

public void paint(java.awt.Graphics g)
Paints this button.
Overrides:
paint in class DCheckbox
Following copied from class: dog.gui.DCheckbox
Parameters:
ds - the control dark shadow colour to use
h - the control highlight colour to use
c - the control colour to use
pc - the primary control colour to use
pcds - the primary control dark shadow colour to use
f - the colour to draw the dot in

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent event)
Processes key events on this button by dispatching them to any registered KeyListeners.
Overrides:
processKeyEvent in class DCheckbox
Parameters:
event - the key event

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent event)
Processes mouse events on this button by dispatching them to any registered MouseListeners.
Overrides:
processMouseEvent in class DCheckbox
Parameters:
event - the mouse event

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent event)
Processes mouse motion events on this button by dispatching them to any registered MouseMotionListeners.
Overrides:
processMouseMotionEvent in class DCheckbox
Parameters:
event - the mouse motion event

paramString

protected java.lang.String paramString()
Returns the parameter string for this button.
Overrides:
paramString in class DCheckbox