com.sas.visuals
Class ToggleButton

com.sas.visuals.ToggleButton
All Implemented Interfaces:
ActionSource, CompositeInterface, ContainerInterface, com.sas.awt.print.PrintableInterface, VisualInterface, com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.DesignTimeDropTargetInterface, com.sas.lang.StringDataInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, com.sas.PublicClonable, ValidatorInterface, com.sas.ViewInterface, Alignment, MultipleValueEventSourceInterface, ResizeToFitInterface, SelectableInterface, java.awt.event.ActionListener, java.awt.event.FocusListener, java.awt.event.ItemListener, java.awt.image.ImageObserver, java.awt.ItemSelectable, java.awt.MenuContainer, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.lang.Cloneable, java.util.EventListener
Direct Known Subclasses:
GraphicalCheckBox, RadioButton, TabButton

public class ToggleButton
implements SelectableInterface

ToggleButton is a subclass of BaseButton that creates a button where images and text, or both can be displayed. The button can be selected and then pressed and deselected. When the button is pressed both an ActionEvent and an ItemEvent are sent to any listeners. The text and images can be aligned horizontally and vertically.

Notes:

See Also:
BaseButton, Serialized Form

Field Summary
protected  java.awt.Point contentShift
          Point value that specifies the amount the ToggleButton shifts when pressed.
protected  LabelView label
          A LabelView object used in the ToggleButton to display the text.
static java.lang.String RB_KEY
           
protected  java.awt.Rectangle textBounds
          Rectangle object that represents the outer bounds of the text to be displayed on the ToggleButton.
 
Fields inherited from class com.sas.visuals.BaseButton
actionCommand, actionListenerList, borderPainted, BOTTOM, buttonListener, buttonModel, currentInsets, defaultIcon, disabledIcon, displayTransform, focusGap, focusPainted, gap, hasFocus, horizontalAlignment, horizontalTextAlignment, item, itemListenerList, LEFT, pressedIcon, resizeToFit, RIGHT, rolloverIcon, selectedIcon, text, textPosition, TOP, updateItem, updateText, verticalAlignment, verticalTextAlignment
 
Fields inherited from interface com.sas.visuals.Alignment
BEGIN, CENTER, END
 
Constructor Summary
ToggleButton()
          Default constructor.
ToggleButton(com.sas.visuals.IconInterface defaultImg)
          Constructor that sets the default image to be displayed.
ToggleButton(java.lang.String txt)
          Constructor that sets the text to be displayed.
ToggleButton(java.lang.String txt, com.sas.visuals.IconInterface defaultImg)
          Constructor that sets both the default image and the text to be displayed.
ToggleButton(java.lang.String txt, com.sas.visuals.IconInterface defaultImg, boolean selected)
          Constructor that sets the default image, the text to be displayed, and the selected state of the ToggleButton.
 
Method Summary
protected  void buttonModelArmed(ButtonModelInterface btnModel)
          Handles change in buttonModel armed property.
protected  void buttonModelPressed(ButtonModelInterface btnModel)
          Handles change in buttonModel pressed property.
protected  void buttonModelSelected(ButtonModelInterface btnModel)
          Handles change in buttonModel selected property.
 java.lang.Object clone()
          Create a clone of the ToggleButton.
protected  java.awt.Point contentShift()
          Returns the amount to shift the contents based on the state of the button model and the icons that have been set.
 java.awt.Point getContentShift()
          Gets the amount the content is shifted when the button is pressed or selected.
static int getDefaultHeight()
          Gets the default height of the ToggleButton
static int getDefaultWidth()
          Gets the default width of the ToggleButton
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
          Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this ToggleButton.
 java.awt.Dimension getMinimumSize()
          Get the minimum size of the ToggleButton.
 SelectionGroupInterface getSelectionGroup()
          Gets the selectionGroup to control the behavior of the ToggleButton.
 java.lang.String getSource()
          Gets the source of the image displayed as the default image.
protected  java.awt.Rectangle getTextBounds()
          Gets the bounds of the text.
 void paint(java.awt.Graphics g)
          Paint the ToggleButton in its current state based on the buttonModel.
protected  void paintBackground(java.awt.Graphics g)
          Paints the background on the ToggleButton.
protected  void paintFocus(java.awt.Graphics g)
          Paints the focus Rectangle on the ToggleButton.
 void setContentShift(java.awt.Point pt)
          Sets the amount the content is shifted when the button is pressed or selected.
static void setDefaultHeight(int newHeight)
          Sets the default height of the ToggleButton
static void setDefaultWidth(int newWidth)
          Sets the default width of the ToggleButton in pixels
 void setFont(java.awt.Font f)
          Set the font of the text on the ToggleButton.
 void setHorizontalTextAlignment(int hAlign)
          Set the horizontal alignment of the text of the ToggleButton.
 void setSelected(boolean s)
          Set the selected state of the ToggleButton.
 void setSelectionGroup(SelectionGroupInterface sGroup)
          Sets the selectionGroup to control the behavior of the ToggleButton.
 void setSource(java.lang.String src)
          Set the source of the image displayed as the default image.
 void setText(java.lang.String txt)
          Sets the text to be displayed on the ToggleButton.
 void setVerticalTextAlignment(int vAlign)
          Sets the vertical alignment of the text displayed on the button.
 
Methods inherited from class com.sas.visuals.BaseButton
actionPerformed, addActionListener, addItemListener, addNotify, buttonModelDisabled, buttonModelRollover, computePreferredSize, detachModel, focusGained, focusLost, getActionCommand, getButtonListener, getButtonModel, getContentSize, getDefaultIcon, getDisabledIcon, getDisplayTransform, getFocusGap, getHorizontalAlignment, getHorizontalTextAlignment, getIconTextGap, getInsets, getItem, getKeyAccelerator, getPressedIcon, getRequiredInterfaces, getRolloverIcon, getSelectedIcon, getSelectedObjects, getText, getTextPosition, getVerticalAlignment, getVerticalTextAlignment, isBorderPainted, isFocusPainted, isFocusTraversable, isResizeToFit, isSelected, itemStateChanged, processActionEvent, processEvent, processItemEvent, propertyChange, refresh, refreshItem, removeActionListener, removeItemListener, resizeToFit, setActionCommand, setBorderPainted, setBounds, setButtonListener, setButtonModel, setDefaultIcon, setDefaultValues, setDisabledIcon, setDisplayTransform, setEnabled, setFocusGap, setFocusPainted, setHorizontalAlignment, setIconTextGap, setInsets, setItem, setKeyAccelerator, setPressedIcon, setResizeToFit, setRolloverIcon, setSelectedIcon, setTextPosition, setVerticalAlignment
 
Methods inherited from class com.sas.awt.ContainerContainerComponent
dragEnter, dragLeave, dragOver, drop, getContainerInterfaceSupportInfo, getErrorHandler, getValidator, isIDEDnDDropBarrier, isIDEDnDDropTarget, isValid, removeNotify, setContainerInterfaceSupportInfo, setErrorHandler, setIDEDnDDropBarrier, setIDEDnDDropTarget, setInsets, setValidator, superAddNotify, superGetInsets, superRemoveNotify, superSetDefaultValues
 
Methods inherited from class com.sas.awt.ContainerVisualComponent
addLink, addPropertyChangeListener, addVetoableChangeListener, anyPropertyChangeListeners, attachModel, attachView, detachView, dumpComponent, firePropertyChange, firePropertyChange, fireVetoableChange, getBackgroundColor, getBorder, getComponentDescription, getComponentSupportInfo, getEventMethod, getEventValues, getFont, getForegroundColor, getHeight, getHorizontalPosition, getLinkInfo, getModelInterface, getPageBounds, getPreferredSize, getPrePainter, getPrintOptionsPanel, getVerticalPosition, getViewInterfaceSupportInfo, getVisualInterfaceSupportInfo, getWidth, initialize, initializeComponent, isDesignTime, isEnabled, isFocus, isLinked, isTransparent, isVisible, pageExists, print, printFinalize, printInitialize, queryLinks, queryLinks, removeAllLinks, removeInterfaceTraps, removeLink, removePropertyChangeListener, removeVetoableChangeListener, setBackgroundColor, setBorder, setComponentDescription, setComponentSupportInfo, setFocus, setForegroundColor, setHeight, setHorizontalPosition, setLinkInfo, setModelInterface, setPreferredSize, setPrePainter, setRequiredInterfaces, setTransparent, setVerticalPosition, setViewInterfaceSupportInfo, setVisible, setVisualInterfaceSupportInfo, setWidth, superGetFont, superGetMinimumSize, superGetPreferredSize, superIsEnabled, superIsVisible, superPaint, superSetBounds, superSetEnabled, superSetFont, superSetVisible, superUpdate, supportsListenerInterface, supportsRequiredInterfaces, trapInterfaceEvents, update, validateObject
 
Methods inherited from interface com.sas.visuals.SelectableInterface
getButtonModel, getDisplayTransform, getItem, setDisplayTransform, setItem
 
Methods inherited from interface com.sas.awt.ContainerInterface
getComponents, getLayout, invalidate, setLayout, validate
 
Methods inherited from interface com.sas.awt.VisualInterface
getBackgroundColor, getBorder, getFont, getForegroundColor, getHeight, getHorizontalPosition, getPreferredSize, getPrePainter, getVerticalPosition, getVisualInterfaceSupportInfo, getWidth, isEnabled, isFocus, isTransparent, isVisible, setBackgroundColor, setBorder, setFocus, setForegroundColor, setHeight, setHorizontalPosition, setPreferredSize, setPrePainter, setTransparent, setVerticalPosition, setVisible, setVisualInterfaceSupportInfo, setWidth, superGetFont, superGetMinimumSize, superGetPreferredSize, superIsEnabled, superIsVisible, superPaint, superSetBounds, superSetEnabled, superSetFont, superSetVisible, superUpdate
 

Field Detail

label

protected LabelView label
A LabelView object used in the ToggleButton to display the text.


textBounds

protected transient java.awt.Rectangle textBounds
Rectangle object that represents the outer bounds of the text to be displayed on the ToggleButton.


contentShift

protected java.awt.Point contentShift
Point value that specifies the amount the ToggleButton shifts when pressed.


RB_KEY

public static java.lang.String RB_KEY
Constructor Detail

ToggleButton

public ToggleButton()
Default constructor.


ToggleButton

public ToggleButton(java.lang.String txt)
Constructor that sets the text to be displayed.

Parameters:
txt - the text to display on the ToggleButton

ToggleButton

public ToggleButton(com.sas.visuals.IconInterface defaultImg)
Constructor that sets the default image to be displayed.

Parameters:
defaultImg - the default image to display on the ToggleButton

ToggleButton

public ToggleButton(java.lang.String txt,
                    com.sas.visuals.IconInterface defaultImg)
Constructor that sets both the default image and the text to be displayed.

Parameters:
txt - the text to display on the ToggleButton
defaultImg - the default image to display on the ToggleButton

ToggleButton

public ToggleButton(java.lang.String txt,
                    com.sas.visuals.IconInterface defaultImg,
                    boolean selected)
Constructor that sets the default image, the text to be displayed, and the selected state of the ToggleButton.

Parameters:
txt - the text to display on the ToggleButton
defaultImg - the default image to display on the ToggleButton
selected - the selected state of the ToggleButton
Method Detail

getDefaultHeight

public static int getDefaultHeight()
Gets the default height of the ToggleButton

Returns:
the default height in pixels
See Also:
setDefaultHeight(int)

getDefaultWidth

public static int getDefaultWidth()
Gets the default width of the ToggleButton

Returns:
the default width in pixels
See Also:
setDefaultWidth(int)

setDefaultHeight

public static void setDefaultHeight(int newHeight)
Sets the default height of the ToggleButton

Parameters:
newHeight - the desired default height in pixels
See Also:
getDefaultHeight()

setDefaultWidth

public static void setDefaultWidth(int newWidth)
Sets the default width of the ToggleButton in pixels

Parameters:
newWidth - the desired default width in pixels
See Also:
getDefaultWidth()

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
Returns information used by the com.sas.beans.Introspector to augment the automatically introspected information about this ToggleButton.

Returns:
the ExtendedBeanInfo for this class

buttonModelArmed

protected void buttonModelArmed(ButtonModelInterface btnModel)
Handles change in buttonModel armed property. Changes the light source of the border based on the buttonModel. Repaint the button if buttonModel is not disabled. Override to change the behavior when the model armed property changes.

Overrides:
buttonModelArmed in class BaseButton
Parameters:
btnModel - the buttonModel that changed.

buttonModelPressed

protected void buttonModelPressed(ButtonModelInterface btnModel)
Handles change in buttonModel pressed property. Changes the light source of the border based on the buttonModel. Repaint the button if buttonModel is not disabled. Override to change the behavior when the model pressed property changes.

Overrides:
buttonModelPressed in class BaseButton
Parameters:
btnModel - the buttonModel that changed.

buttonModelSelected

protected void buttonModelSelected(ButtonModelInterface btnModel)
Handles change in buttonModel selected property. Changes the light source of the border based on the buttonModel. Repaint the button if buttonModel is not disabled. Override to change the behavior when the model selected property changes.

Overrides:
buttonModelSelected in class BaseButton
Parameters:
btnModel - the Button Model that changed.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Create a clone of the ToggleButton.

Specified by:
clone in interface com.sas.PublicClonable
Overrides:
clone in class BaseButton
Returns:
clone of ToggleButton
Throws:
java.lang.CloneNotSupportedException - if clone creation fails

contentShift

protected java.awt.Point contentShift()
Returns the amount to shift the contents based on the state of the button model and the icons that have been set. Called by paint.

Returns:
the Point value by which to shift the content of the button

getMinimumSize

public java.awt.Dimension getMinimumSize()
Get the minimum size of the ToggleButton.

Specified by:
getMinimumSize in interface VisualInterface
Overrides:
getMinimumSize in class ContainerVisualComponent
Returns:
the minimum size based on the size of the content in this ToggleButton
See Also:
VisualInterface.getMinimumSize()

paint

public void paint(java.awt.Graphics g)
Paint the ToggleButton in its current state based on the buttonModel.

Overrides:
paint in class ContainerVisualComponent
Parameters:
g - the Graphics context.
See Also:
VisualInterfaceSupport.paint(com.sas.ComponentInterface, com.sas.awt.VisualInterface, java.awt.Component, java.awt.Graphics)

setFont

public void setFont(java.awt.Font f)
Set the font of the text on the ToggleButton.

Specified by:
setFont in interface VisualInterface
Overrides:
setFont in class BaseButton
Parameters:
f - the font of the ToggleButton text
See Also:
VisualInterface.setFont(java.awt.Font)

setHorizontalTextAlignment

public void setHorizontalTextAlignment(int hAlign)
Set the horizontal alignment of the text of the ToggleButton. The alignment can be set to: LEFT, CENTER, or RIGHT

Overrides:
setHorizontalTextAlignment in class BaseButton
Parameters:
hAlign - protected int value derived from com.sas.geometry.Orientaions
See Also:
BaseButton.setHorizontalTextAlignment(int), Orientations

getSelectionGroup

public SelectionGroupInterface getSelectionGroup()
Gets the selectionGroup to control the behavior of the ToggleButton.

Specified by:
getSelectionGroup in interface SelectableInterface
Returns:
the selectionGroup the ToggleButton is a member of.
See Also:
SelectionGroup

getTextBounds

protected java.awt.Rectangle getTextBounds()
Gets the bounds of the text.

Returns:
the size and location of where the text is displayed

paintBackground

protected void paintBackground(java.awt.Graphics g)
Paints the background on the ToggleButton.

Parameters:
g - the Graphics context

paintFocus

protected void paintFocus(java.awt.Graphics g)
Paints the focus Rectangle on the ToggleButton.

Parameters:
g - the Graphics context

setSelectionGroup

public void setSelectionGroup(SelectionGroupInterface sGroup)
Sets the selectionGroup to control the behavior of the ToggleButton.

Specified by:
setSelectionGroup in interface SelectableInterface
Parameters:
sGroup - the selectionGroup to add the ToggleButton to.
See Also:
SelectionGroup

getContentShift

public java.awt.Point getContentShift()
Gets the amount the content is shifted when the button is pressed or selected.

Returns:
the point to translate the contents postion by when the button is pressed or selected.
See Also:
setContentShift(java.awt.Point)

setContentShift

public void setContentShift(java.awt.Point pt)
Sets the amount the content is shifted when the button is pressed or selected. The default value is (1,1). This is not used if either the pressedIcon or the selectedIcon have been set.

Parameters:
pt - the point to translate the contents postion by when the button is pressed or selected.
See Also:
getContentShift()

setSelected

public void setSelected(boolean s)
Set the selected state of the ToggleButton.

Overrides:
setSelected in class BaseButton
Parameters:
s - the selected state of the ToggleButton.
See Also:
BaseButton.isSelected()

getSource

public java.lang.String getSource()
Gets the source of the image displayed as the default image.

Returns:
valid source path only if the defaultIcon is an ImageView
See Also:
setSource(java.lang.String)

setSource

public void setSource(java.lang.String src)
Set the source of the image displayed as the default image. This method creates an ImageView and sets it as the defaultIcon if the defaultIcon is null. If the defaultIcon is an ImageView this method sets the source of the ImageView to the specified path.

Parameters:
src - the default image file name and path
See Also:
getSource(), ImageView

setText

public void setText(java.lang.String txt)
Sets the text to be displayed on the ToggleButton.

Specified by:
setText in interface com.sas.lang.StringDataInterface
Overrides:
setText in class BaseButton
Parameters:
txt - the text displayed
See Also:
BaseButton.getText()

setVerticalTextAlignment

public void setVerticalTextAlignment(int vAlign)
Sets the vertical alignment of the text displayed on the button. The alignment can be TOP, CENTER, or BOTTOM

Overrides:
setVerticalTextAlignment in class BaseButton
Parameters:
vAlign - protected int value derived from com.sas.geometry.Orientaions
See Also:
BaseButton.setVerticalTextAlignment(int), Orientations



Copyright © 2009 SAS Institute Inc. All Rights Reserved.