Class SwingButtonHandler
- java.lang.Object
-
- net.sf.jguiraffe.gui.platform.swing.builder.components.SwingButtonHandler
-
- All Implemented Interfaces:
ItemListener
,EventListener
,net.sf.jguiraffe.gui.forms.ComponentHandler<Boolean>
,SwingEventSource
public class SwingButtonHandler extends Object implements ItemListener
A specific Swing component handler implementation that deals with several kinds of button like components.
This component handler class handles buttons (command and toggle buttons), check boxes and radio buttons. Data type is boolean, i.e. a flag whether the button is selected. All type of event handlers are supported.
- Version:
- $Id: SwingButtonHandler.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description SwingButtonHandler(AbstractButton button)
Creates a new instance ofSwingButtonHandler
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addActionListener(ActionListener l)
Adds an action listener at this component.void
addChangeListener(ChangeListener l)
Adds a change listener at the managed component.void
addFocusListener(FocusListener l)
Registers a focus listener at the managed component.void
addMouseListener(MouseListener l)
Adds the specified mouse listener to the managed component.protected void
fireChangeEvent(Object event)
Fires a change event to the registered change listeners.AbstractButton
getButton()
Returns the managed button.Object
getComponent()
Returns a reference to the managed component.Boolean
getData()
Returns the component's data.JComponent
getJComponent()
Returns a reference to the managed Swing component.Object
getOuterComponent()
Returns the outer most component.Class<?>
getType()
Returns the component's data type.boolean
isEnabled()
Checks whether the managed component is enabled.void
itemStateChanged(ItemEvent event)
Callback for item events.protected void
registerChangeListener()
Registers this object as change listener at the managed button.void
removeActionListener(ActionListener l)
Removes an action listener from this component.void
removeChangeListener(ChangeListener l)
Removes a change listener from this component.void
removeFocusListener(FocusListener l)
Removes the specified focus listener from this component.void
removeMouseListener(MouseListener l)
Removes the specified mouse listener from the managed component.void
setData(Boolean data)
Sets the component's data.void
setEnabled(boolean f)
Sets the enabled flag of the managed component.protected void
unregisterChangeListener()
Unregisters this object as change listener at the managed button.
-
-
-
Constructor Detail
-
SwingButtonHandler
public SwingButtonHandler(AbstractButton button)
Creates a new instance ofSwingButtonHandler
.- Parameters:
button
- the button to handle
-
-
Method Detail
-
getButton
public AbstractButton getButton()
Returns the managed button.- Returns:
- the managed button object
-
getData
public Boolean getData()
Returns the component's data.- Specified by:
getData
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<Boolean>
- Returns:
- the component's data
-
setData
public void setData(Boolean data)
Sets the component's data. This must be an object of type boolean.- Specified by:
setData
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<Boolean>
- Parameters:
data
- the component's data.
-
getType
public Class<?> getType()
Returns the component's data type. This is boolean.- Specified by:
getType
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<Boolean>
- Returns:
- the data type
-
addActionListener
public void addActionListener(ActionListener l)
Adds an action listener at this component.- Specified by:
addActionListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to register
-
removeActionListener
public void removeActionListener(ActionListener l)
Removes an action listener from this component.- Specified by:
removeActionListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to be removed
-
registerChangeListener
protected void registerChangeListener()
Registers this object as change listener at the managed button.
-
unregisterChangeListener
protected void unregisterChangeListener()
Unregisters this object as change listener at the managed button.- See Also:
registerChangeListener()
-
itemStateChanged
public void itemStateChanged(ItemEvent event)
Callback for item events. Occurring events are routed to the registered change listeners.- Specified by:
itemStateChanged
in interfaceItemListener
- Parameters:
event
- the event
-
getJComponent
public JComponent getJComponent()
Returns a reference to the managed Swing component.- Returns:
- the Swing component
-
getComponent
public Object getComponent()
Returns a reference to the managed component.- Specified by:
getComponent
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<T>
- Returns:
- the component
-
getOuterComponent
public Object getOuterComponent()
Returns the outer most component. This implementation returns the same component asComponentHandler.getComponent()
.- Specified by:
getOuterComponent
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<T>
- Returns:
- the outer most component
-
isEnabled
public boolean isEnabled()
Checks whether the managed component is enabled.- Specified by:
isEnabled
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<T>
- Returns:
- a flag whether this component is enabled
-
setEnabled
public void setEnabled(boolean f)
Sets the enabled flag of the managed component.- Specified by:
setEnabled
in interfacenet.sf.jguiraffe.gui.forms.ComponentHandler<T>
- Parameters:
f
- the value of the enabled flag
-
addChangeListener
public void addChangeListener(ChangeListener l)
Adds a change listener at the managed component. This implementation supports only a single change listener (which should not be a limitation becauseFormEventManager
will do the multiplexing). Because there is no generic change listener in SwingregisterChangeListener()
will be invoked for doing the actual registration.- Specified by:
addChangeListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to register
-
removeChangeListener
public void removeChangeListener(ChangeListener l)
Removes a change listener from this component. With this method the change listener that has been registered usingaddChangeListener()
can be removed again. If the passed in listener is different from the registered listener, this operation will have no effect.- Specified by:
removeChangeListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to be removed- See Also:
SwingEventSource.addChangeListener(ChangeListener)
-
addFocusListener
public void addFocusListener(FocusListener l)
Registers a focus listener at the managed component. This implementation is fully functional.- Specified by:
addFocusListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to register
-
removeFocusListener
public void removeFocusListener(FocusListener l)
Removes the specified focus listener from this component.- Specified by:
removeFocusListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to be removed
-
addMouseListener
public void addMouseListener(MouseListener l)
Adds the specified mouse listener to the managed component. This implementation is fully functional.- Specified by:
addMouseListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to be added
-
removeMouseListener
public void removeMouseListener(MouseListener l)
Removes the specified mouse listener from the managed component. This implementation is fully functional.- Specified by:
removeMouseListener
in interfaceSwingEventSource
- Parameters:
l
- the listener to remove
-
fireChangeEvent
protected void fireChangeEvent(Object event)
Fires a change event to the registered change listeners.- Parameters:
event
- the event
-
-