Class Clickable

java.lang.Object
org.eclipse.draw2d.Figure
org.eclipse.draw2d.Clickable
All Implemented Interfaces:
IFigure
Direct Known Subclasses:
Button, Toggle

public class Clickable extends Figure
A Clickable responds to mouse clicks in some way (determined by a ClickBehavior) and fires action events. No visual appearance of feedback is offered. Depends on a model holder and an event handler which understands the model and updates the model accordingly. ButtonModel is used by default. Any figure can be set as contents to a Clickable. Clickable->EventHandler->Model->ModelObserver->Listeners of actions.
  • Field Details

    • MAX_FLAG

      protected static int MAX_FLAG
      The highest reserved flag used by this class
    • STYLE_BUTTON

      public static final int STYLE_BUTTON
      Style constant that defines a push button. The button will be pressed when the mouse is pressed on top of it. The button will be released when the mouse is released or is move off of the button.
    • STYLE_TOGGLE

      public static final int STYLE_TOGGLE
      Style constant that defines a toggle button. The button will toggle between 2 states when the mouse is clicked on the button.
    • DEFAULT_FIRING

      public static final int DEFAULT_FIRING
      An action is performed every time the mouse is released.
      See Also:
    • REPEAT_FIRING

      public static final int REPEAT_FIRING
      Firing starts as soon as the mouse is pressed on this Clickable, and keeps firing at prefixed intervals until the mouse is released.
      See Also:
  • Constructor Details

    • Clickable

      public Clickable()
      Constructs a Clickable with no contents.
    • Clickable

      public Clickable(IFigure contents)
      Constructs a Clickable whose contents are provided as input. The content figure occupies the entire region of the Clickable.
      Parameters:
      contents - The content figure
    • Clickable

      public Clickable(IFigure contents, int style)
      Constructs a Clickable whose contents are provided as input. The content figure occupies the entire region of the Clickable. Sets the style to the given style (either STYLE_BUTTON or STYLE_TOGGLE ).
      Parameters:
      contents - The content figure
      style - The button style
  • Method Details

    • addActionListener

      public void addActionListener(ActionListener listener)
      Adds the given listener to the list of action listeners of this Figure. Listener is called whenever an action is performed.
      Parameters:
      listener - The ActionListener to be added
      Since:
      2.0
    • addChangeListener

      public void addChangeListener(ChangeListener listener)
      Adds the given listener to the list of state change listeners of this figure. A ChangeListener is informed if there is any state change in the model requiring action by the listener.
      Parameters:
      listener - The ChangeListener to be added
      Since:
      2.0
    • createDefaultModel

      protected ButtonModel createDefaultModel()
      Returns a newly created ButtonModel as the default model to be used by this Clickable based on the button style.
      Returns:
      The model to be used by default
      Since:
      2.0
    • createEventHandler

      protected org.eclipse.draw2d.ClickableEventHandler createEventHandler()
      Returns a newly created event handler for this Clickable and its model.
      Returns:
      The event handler
      Since:
      2.0
    • createModelObserver

      protected org.eclipse.draw2d.Clickable.ModelObserver createModelObserver()
      Returns a newly created model observer which listens to the model, and fires any action or state changes. A ModelObserver holds both an action listener and a state change listener.
      Returns:
      The newly created model observer
      Since:
      2.0
    • doClick

      public void doClick()
      Fires an action performed event.
      Since:
      2.0
    • fireActionPerformed

      protected void fireActionPerformed()
      Called when there has been an action performed by this Clickable, which is determined by the model. Notifies all ActionListener type listeners of an action performed.
      Since:
      2.0
    • fireStateChanged

      protected void fireStateChanged(ChangeEvent modelChange)
      Called when there has been a change of state in the model of this clickable. Notifies all ChangeListener type listeners of the state change.
      Parameters:
      modelChange - The ChangeEvent
      Since:
      2.0
    • getModel

      public ButtonModel getModel()
      Returns the behavior model used by this Clickable.
      Returns:
      The model used by this Clickable
      Since:
      2.0
    • hookEventHandler

      protected void hookEventHandler(org.eclipse.draw2d.ClickableEventHandler handler)
      Adds the given ClickableEventHandler to this clickable. A ClickableEventHandler should be a MouseListener, MouseMotionListener, ChangeListener, KeyListener, and FocusListener.
      Parameters:
      handler - The new event handler
      Since:
      2.0
    • init

      protected void init()
      Initializes this Clickable by setting a default model and adding a clickable event handler for that model.
      Since:
      2.0
    • isRolloverEnabled

      public boolean isRolloverEnabled()
      Returns true if rollover feedback is enabled.
      Returns:
      true rollover feedback is enabled
      Since:
      2.0
    • isSelected

      public boolean isSelected()
      Returns true if this Clickable is in a selected state. The model is the one which holds all this state based information.
      Returns:
      true if this Clickable is in a selected state
      Since:
      2.0
    • isStyle

      public boolean isStyle(int style)
      Returns true if this Clickable's style is the same as the passed style.
      Parameters:
      style - The style to be checked
      Returns:
      true if this Clickable's style is the same as the passed style
      Since:
      2.0
    • paintBorder

      protected void paintBorder(Graphics graphics)
      If this Clickable has focus, this method paints a focus rectangle.
      Overrides:
      paintBorder in class Figure
      Parameters:
      graphics - Graphics handle for painting
      See Also:
    • paintClientArea

      protected void paintClientArea(Graphics graphics)
      Paints the area of this figure excluded by the borders. Induces a (1,1) pixel shift in the painting if the mouse is armed, giving it the pressed appearance.
      Overrides:
      paintClientArea in class Figure
      Parameters:
      graphics - Graphics handle for painting
      Since:
      2.0
    • removeActionListener

      public void removeActionListener(ActionListener listener)
      Removes the given listener from the list of ActionListener's of this Clickable.
      Parameters:
      listener - Listener to be removed from this figure
      Since:
      2.0
    • removeChangeListener

      public void removeChangeListener(ChangeListener listener)
      Removes the given listener from the list of ChangeListener's of this clickable.
      Parameters:
      listener - Listener to be removed from this figure
      Since:
      2.0
    • setContents

      protected void setContents(IFigure contents)
      Sets the Figure which is the contents of this Clickable. This Figure occupies the entire clickable region.
      Parameters:
      contents - Contents of the clickable
      Since:
      2.0
    • setEnabled

      public void setEnabled(boolean value)
      Description copied from interface: IFigure
      Sets this IFigure to be enabled.
      Specified by:
      setEnabled in interface IFigure
      Overrides:
      setEnabled in class Figure
      Parameters:
      value - true if this IFigure should be enabled
      See Also:
    • setEventHandler

      public void setEventHandler(org.eclipse.draw2d.ClickableEventHandler h)
      Sets the event handler which interacts with the model to determine the behavior of this Clickable.
      Parameters:
      h - Event handler for this clickable
      Since:
      2.0
    • setFiringMethod

      public void setFiringMethod(int type)
      Determines how this clickable is to fire notifications to its listeners. In the default firing method (DEFAULT_FIRING), an action is performed every time the mouse is released. In the repeat firing method ( REPEAT_FIRING), firing starts as soon as it is pressed on this clickable, and keeps firing at prefixed intervals until the mouse is released.
      Parameters:
      type - Type of firing
      Since:
      2.0
    • setModel

      public void setModel(ButtonModel model)
      Sets the model to be used by this clickable for its state and behavior determination. This clickable removes any observers from the previous model before adding new ones to the new model.
      Parameters:
      model - The new model of this Clickable
      Since:
      2.0
    • setRolloverEnabled

      public void setRolloverEnabled(boolean value)
      Enables or disables rollover feedback of this figure. Generally used in conjunction with the model to determine if feedback is to be shown.
      Parameters:
      value - The rollover state to be set
      Since:
      2.0
    • setSelected

      public void setSelected(boolean value)
      Sets the selected state of this Clickable. Since the model is responsible for all state based information, it is informed of the state change. Extending classes can choose selection information, if they do not represent any selection.
      Parameters:
      value - New selected state of this clickable.
      Since:
      2.0
      See Also:
    • setStyle

      public void setStyle(int style)
      Sets this Clickable's style to the passed value, either STYLE_BUTTON or STYLE_TOGGLE.
      Parameters:
      style - The button style
      Since:
      2.0
    • unhookEventHandler

      protected void unhookEventHandler(org.eclipse.draw2d.ClickableEventHandler handler)
      Removes the given ClickableEventHandler containing listeners from this Clickable.
      Parameters:
      handler - The event handler to be removed
      Since:
      2.0