Class 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 Detail

      • SwingButtonHandler

        public SwingButtonHandler​(AbstractButton button)
        Creates a new instance of SwingButtonHandler.
        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 interface net.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 interface net.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 interface net.sf.jguiraffe.gui.forms.ComponentHandler<Boolean>
        Returns:
        the data type
      • 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 interface ItemListener
        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 interface net.sf.jguiraffe.gui.forms.ComponentHandler<T>
        Returns:
        the component
      • getOuterComponent

        public Object getOuterComponent()
        Returns the outer most component. This implementation returns the same component as ComponentHandler.getComponent().
        Specified by:
        getOuterComponent in interface net.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 interface net.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 interface net.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 because FormEventManager will do the multiplexing). Because there is no generic change listener in Swing registerChangeListener() will be invoked for doing the actual registration.
        Specified by:
        addChangeListener in interface SwingEventSource
        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 using addChangeListener() 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 interface SwingEventSource
        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 interface SwingEventSource
        Parameters:
        l - the listener to register
      • removeFocusListener

        public void removeFocusListener​(FocusListener l)
        Removes the specified focus listener from this component.
        Specified by:
        removeFocusListener in interface SwingEventSource
        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 interface SwingEventSource
        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 interface SwingEventSource
        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