Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.awt.PanelButton

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--ncsa.horizon.awt.SingleComponentPanel
                          |
                          +--ncsa.horizon.awt.PanelButton

public class PanelButton
extends SingleComponentPanel
implements java.awt.event.MouseListener, java.awt.event.ActionListener
a Button that will encloses a single component.

Though not a subclass of the AWT's Button, it can behave as one. It also can behave like an AWT Choice--either as a simple on/off switch or as a radio button. Its raised border gives it the look of a button, yet the interior can contain any other component such a Label to hold simple text or a canvas with an image painted on it. The preferred size of the button is determined by the preferred size of the component it contains.

By default, a PanelButton operates like a simple button: clicking it causes the button to depress and pop-up again, and an action event is sent to listeners. The action command string associated with the event is set to "on".

The PanelButton can be set to behave as an on/off switch by passing a true value to the setSticky() method. A sticky button will remain pressed in until it is pushed again. When the button is pressed in, the resulting ActionEvent will have an action command string set to "on"; when the button is raised, the command string is equal to "off".

The set of PanelButtons is made to act as radio buttons by passing the same PanelButton.RadioGroup object to each PanelButton. For example,

     PanelButton.RadioGroup rg = new PanelButton.RadioGroup();
     PanelButton pb1 = new PanelButton(4, rg, new Label("Choice 1"));
     PanelButton pb2 = new PanelButton(4, rg, new Label("Choice 2"));
 
When in radio mode, the button is sticky by default. Thus, when you turn one button on, the previous engaged button will turn off. In this case, two ActionEvents are fired: one from the clicked button indicating it has been turned on, and one from the other button indicating it was turned off. In general, the off signal is sent first, but listeners should probably not assume this.

Note that while this button can contain any component, most components that respond to mouse clicks can prevent such events from getting to the enclosing PanelButton. If one overrides the mouse event methods of this class to handle this problem, one should be sure to call the appropriate method of the superclass somewhere in the overriding versions.

See Also:
Serialized Form

Inner Class Summary
static  PanelButton.RadioGroup
          a manager of a group of Panel buttons that ensures that only one of them is pressed at a time.
 
Fields inherited from class ncsa.horizon.awt.SingleComponentPanel
bgap, item, lgap, rgap, tgap
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
PanelButton(int thickness)
          create a clickable button with a given border thickness
PanelButton(int thickness, java.awt.Component c)
          create a clickable button with a given border thickness and containing a given component.
PanelButton(int thickness, PanelButton.RadioGroup rg, java.awt.Component c)
          create a clickable radio button.
 
Method Summary
void actionPerformed(java.awt.event.ActionEvent ev)
           
void addActionListener(java.awt.event.ActionListener l)
          add an action listener that will be notified when the button has been engaged.
java.awt.Component add(java.awt.Component comp)
           
PanelButton.RadioGroup getRadioGroup()
          return the RadioGroup managing this button.
boolean getState()
          return the state of the button.
boolean isSticky()
          return whether the button should be sticky.
static void main(java.lang.String[] args)
           
void mouseClicked(java.awt.event.MouseEvent ev)
           
void mouseDragged(java.awt.event.MouseEvent ev)
           
void mouseEntered(java.awt.event.MouseEvent ev)
           
void mouseExited(java.awt.event.MouseEvent ev)
           
void mousePressed(java.awt.event.MouseEvent ev)
           
void mouseReleased(java.awt.event.MouseEvent ev)
           
void paint(java.awt.Graphics g)
           
void removeActionListener(java.awt.event.ActionListener l)
          remove an action listener
void setState(boolean pressed)
          set the state of the button.
void setSticky(boolean b)
          set whether the button is sticky.
 
Methods inherited from class ncsa.horizon.awt.SingleComponentPanel
add, initLayout, setBounds
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponentAt, getComponentAt, getComponent, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paint, paramString, preferredSize, printComponents, print, processContainerEvent, processEvent, removeAll, remove, remove, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, 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, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Constructor Detail

PanelButton

public PanelButton(int thickness)
create a clickable button with a given border thickness

PanelButton

public PanelButton(int thickness,
                   java.awt.Component c)
create a clickable button with a given border thickness and containing a given component.

PanelButton

public PanelButton(int thickness,
                   PanelButton.RadioGroup rg,
                   java.awt.Component c)
create a clickable radio button. This button will automatically be sticky
Method Detail

add

public java.awt.Component add(java.awt.Component comp)
Overrides:
add in class SingleComponentPanel

getState

public boolean getState()
return the state of the button. True is returned if the button is pushed in.

setState

public void setState(boolean pressed)
set the state of the button. True will push the button in. Listeners of this button will be notified when the button is sticky and the state is changed, or when the button is set to unpressed if the button is not sticky.

isSticky

public boolean isSticky()
return whether the button should be sticky. A sticky button will remain pressed in until it is pushed again.

setSticky

public void setSticky(boolean b)
set whether the button is sticky. A sticky button will remain pressed in until it is pushed again, operating as an on/off switch.

getRadioGroup

public PanelButton.RadioGroup getRadioGroup()
return the RadioGroup managing this button. Null is returned if this button is not part of a RadioGroup.

paint

public void paint(java.awt.Graphics g)
Overrides:
paint in class java.awt.Container

mousePressed

public void mousePressed(java.awt.event.MouseEvent ev)
Description copied from interface:
 
Specified by:
mousePressed(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent ev)
Description copied from interface:
 
Specified by:
mouseReleased(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent ev)
Description copied from interface:
 
Specified by:
mouseExited(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent ev)

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent ev)
Description copied from interface:
 
Specified by:
mouseEntered(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent ev)
Description copied from interface:
 
Specified by:
mouseClicked(java.awt.event.MouseEvent) in interface java.awt.event.MouseListener

addActionListener

public void addActionListener(java.awt.event.ActionListener l)
add an action listener that will be notified when the button has been engaged. If the button is sticky (i.e. isSticky() returns true), actions are fired when the button is pressed and released (with action commands of "on" and "off", respectively); otherwise, an action event (with an action command of "on") is fired only when the button is released.

removeActionListener

public void removeActionListener(java.awt.event.ActionListener l)
remove an action listener

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ev)
Description copied from interface:
 
Specified by:
actionPerformed(java.awt.event.ActionEvent) in interface java.awt.event.ActionListener

main

public static void main(java.lang.String[] args)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD