Draw2D v2.0

org.eclipse.draw2d
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

Clickable - that which 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.


Inner classes inherited from class org.eclipse.draw2d.Figure
Figure.FigureIterator
 
Inner classes inherited from class org.eclipse.draw2d.IFigure
IFigure.NoInsets
 
Field Summary
static int DEFAULT_FIRING
           
static int REPEAT_FIRING
           
static int STYLE_BUTTON
           
static int STYLE_TOGGLE
           
 
Fields inherited from class org.eclipse.draw2d.Figure
bgColor, border, bounds, fgColor, flags, font, MAX_FLAG, maxSize, minSize, NO_MANAGER, prefSize, toolTip
 
Fields inherited from interface org.eclipse.draw2d.IFigure
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS
 
Constructor Summary
Clickable()
          Constructs a Clickable with no contents.
Clickable(IFigure contents)
          Constructs a Clickable whose contents are provided as input.
Clickable(IFigure contents, int style)
          Constructs a Clickable whose contents are provided as input.
 
Method Summary
 void addActionListener(ActionListener listener)
          Adds the given listener to the list of action listeners of this Figure.
 void addChangeListener(ChangeListener listener)
          Adds the given listener to the list of state change listeners of this figure.
protected  ButtonModel createDefaultModel()
          Returns a newly created ButtonModel as the default model to be used by this Clickable.
protected  org.eclipse.draw2d.ClickableEventHandler createEventHandler()
          Returns a newly created event handler for this Clickable and its model.
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.
 void doClick()
          Fires an action performed event.
protected  void fireActionPerformed()
          Called when there has been an action performed by this Clickable, which is determined by the model.
protected  void fireStateChanged(ChangeEvent modelChange)
          Called when there has been a change of state in the model of this clickable.
 ButtonModel getModel()
          Returns the behavior model used by this Clickable.
protected  void hookEventHandler(org.eclipse.draw2d.ClickableEventHandler handler)
          Adds the given clickable event handler to this clickable.
protected  void hookModel(ButtonModel model)
          Sets model to be used by this Clickable.
protected  void init()
          Initializes this Clickable by setting a default model and adding a clickable event handler for that model.
 boolean isRolloverEnabled()
          Returns whether rollover feedback is enabled or not.
 boolean isSelected()
          Returns whether this Clickable is in a selected state or not.
 boolean isStyle(int style)
          Returns true if this Clickable's style is the same as the passed style.
protected  void paintBorder(Graphics graphics)
          Paints the border associated with this figure, if one exists.
protected  void paintClientArea(Graphics g)
          Paints the area of this figure excluded by the borders.
 void removeActionListener(ActionListener listener)
          Removes the given listener from the list of ActionListener's of this Clickable.
 void removeChangeListener(ChangeListener listener)
          Removes the given listener from the list of ChangeListener's of this clickable.
protected  void setContents(IFigure contents)
          Sets the Figure which is the contents of this Clickable.
 void setEnabled(boolean value)
          Sets this figure to be enabled.
 void setEventHandler(org.eclipse.draw2d.ClickableEventHandler h)
          Sets the event handler which interacts with the model to determine the behavior of this Clickable.
 void setFiringMethod(int type)
          Determines how this clickable is to fire notifications to its listeners.
 void setModel(ButtonModel model)
          Sets the model to be used by this clickable for its state and behavior determination.
 void setRolloverEnabled(boolean value)
          Enables or disables roll over feedback of this figure, repainting it.
 void setSelected(boolean value)
          Sets the selected state of this Clickable.
 void setStyle(int style)
          Sets this Clickable's style to the passed value.
protected  void unhookEventHandler(org.eclipse.draw2d.ClickableEventHandler handler)
          Removes the given event handler containing listeners from this Clickable.
 
Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addFigureListener, addFocusListener, addKeyListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getClientArea, getClientArea, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getLocation, getMaximumSize, getMinimumSize, getParent, getPreferredSize, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidate, isEnabled, isFocusTraversable, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isValid, isValidationRoot, isVisible, layout, paint, paintChildren, paintFigure, primTranslate, remove, removeAll, removeAncestorListener, removeFigureListener, removeFocusListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setBounds, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setConstraint, setCursor, setFlag, setFocusTraversable, setFont, setForegroundColor, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setUpdateManager, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, useLocalCoordinates, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STYLE_BUTTON

public static int STYLE_BUTTON

STYLE_TOGGLE

public static int STYLE_TOGGLE

DEFAULT_FIRING

public static final int DEFAULT_FIRING

REPEAT_FIRING

public static final int REPEAT_FIRING
Constructor Detail

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.

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.
Parameters:
style - Integer constants STYLE_BUTTON or STYLE_TOGGLE.
Method Detail

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 - Action listener to be added.
Since:
2.0
See Also:
removeActionListener(ActionListener)

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 - Change listener to be added.
Since:
2.0
See Also:
removeChangeListener(ChangeListener)

createDefaultModel

protected ButtonModel createDefaultModel()
Returns a newly created ButtonModel as the default model to be used by this Clickable.
Returns:
Model to be used by default.
Since:
2.0
See Also:
ButtonModel

createEventHandler

protected org.eclipse.draw2d.ClickableEventHandler createEventHandler()
Returns a newly created event handler for this Clickable and its model.
Returns:
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:
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.
Since:
2.0

getModel

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

hookEventHandler

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

hookModel

protected void hookModel(ButtonModel model)
Sets model to be used by this Clickable.
Parameters:
model - Model to be used.
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 whether rollover feedback is enabled or not.
Returns:
Rollover enabled on this clickable or not.
Since:
2.0
See Also:
setRolloverEnabled(boolean)

isSelected

public boolean isSelected()
Returns whether this Clickable is in a selected state or not. The model is the one which holds all this state based information.
Returns:
Selected state of this clickable.
Since:
2.0
See Also:
setSelected(boolean)

isStyle

public boolean isStyle(int style)
Returns true if this Clickable's style is the same as the passed style.
Since:
2.0

paintBorder

protected void paintBorder(Graphics graphics)
Description copied from class: Figure
Paints the border associated with this figure, if one exists.
Overrides:
paintBorder in class Figure
Following copied from class: org.eclipse.draw2d.Figure
See Also:
Border.paint(IFigure, Graphics, Insets)

paintClientArea

protected void paintClientArea(Graphics g)
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:
g - 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
See Also:
addActionListener(ActionListener)

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
See Also:
addChangeListener(ChangeListener)

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 figure to be enabled.
Overrides:
setEnabled in class Figure

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, an action is performed every time the mouse is released. In the repeat firing method, firing starts as soon as it is pressed on this clickable, and keeps firing at prefixed intervals till the mouse is released.
Parameters:
type - Type of firing. Can be any of the firing behavior values defined in the model.
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 - New model of this Clickable.
Since:
2.0

setRolloverEnabled

public void setRolloverEnabled(boolean value)
Enables or disables roll over feedback of this figure, repainting it. Generally used in conjunction with the model to determine if feedback is to be shown.
Parameters:
value - Rollover state to be set.
Since:
2.0
See Also:
isRolloverEnabled()

setSelected

public void setSelected(boolean value)
Sets the selected state of this Clickable. Since the model is reposnsible 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:
isSelected()

setStyle

public void setStyle(int style)
Sets this Clickable's style to the passed value.
Parameters:
style - Integer constants STYLE_BUTTON or STYLE_TOGGLE.
Since:
2.0

unhookEventHandler

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

Draw2D v2.0