Package org.eclipse.draw2d
Class Clickable
java.lang.Object
org.eclipse.draw2d.Figure
org.eclipse.draw2d.Clickable
- All Implemented Interfaces:
IFigure
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.-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.draw2d.Figure
Figure.FigureIterator, Figure.IdentitySearch, Figure.ReverseFigureChildrenIterator
Nested classes/interfaces inherited from interface org.eclipse.draw2d.IFigure
IFigure.NoInsets
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
An action is performed every time the mouse is released.protected static int
The highest reserved flag used by this classstatic final int
Firing starts as soon as the mouse is pressed on this Clickable, and keeps firing at prefixed intervals until the mouse is released.static final int
Style constant that defines a push button.static final int
Style constant that defines a toggle button.Fields inherited from class org.eclipse.draw2d.Figure
bgColor, border, bounds, fgColor, flags, font, maxSize, minSize, NO_MANAGER, prefSize, toolTip
Fields inherited from interface org.eclipse.draw2d.IFigure
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
Returns a newly created ButtonModel as the default model to be used by this Clickable based on the button style.protected org.eclipse.draw2d.ClickableEventHandler
Returns a newly created event handler for this Clickable and its model.protected org.eclipse.draw2d.Clickable.ModelObserver
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
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.getModel()
Returns the behavior model used by this Clickable.protected void
hookEventHandler
(org.eclipse.draw2d.ClickableEventHandler handler) Adds the given ClickableEventHandler to this clickable.protected void
init()
Initializes this Clickable by setting a default model and adding a clickable event handler for that model.boolean
Returnstrue
if rollover feedback is enabled.boolean
Returnstrue
if this Clickable is in a selected state.boolean
isStyle
(int style) Returnstrue
if this Clickable's style is the same as the passed style.protected void
paintBorder
(Graphics graphics) If this Clickable has focus, this method paints a focus rectangle.protected void
paintClientArea
(Graphics graphics) 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 IFigure 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 rollover feedback of this figure.void
setSelected
(boolean value) Sets the selected state of this Clickable.void
setStyle
(int style) Sets this Clickable's style to the passed value, eitherSTYLE_BUTTON
orSTYLE_TOGGLE
.protected void
unhookEventHandler
(org.eclipse.draw2d.ClickableEventHandler handler) Removes the given ClickableEventHandler containing listeners from this Clickable.Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, add, addAncestorListener, addCoordinateListener, addFigureListener, addFocusListener, addKeyListener, addLayoutListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireCoordinateSystemChanged, fireFigureMoved, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getChildrenRevIterable, getClientArea, getClientArea, getClippingStrategy, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getListenersIterable, getLocalBackgroundColor, getLocalFont, getLocalForegroundColor, getLocation, getMaximumSize, getMinimumSize, getMinimumSize, getParent, getPreferredSize, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidate, invalidateTree, isCoordinateSystem, isEnabled, isFocusTraversable, isMirrored, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isShowing, isValid, isValidationRoot, isVisible, layout, optimizeClip, paint, paintChildren, paintFigure, primTranslate, remove, removeAll, removeAncestorListener, removeCoordinateListener, removeFigureListener, removeFocusListener, removeKeyListener, removeLayoutListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setBounds, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setClippingStrategy, setConstraint, setCursor, setFlag, setFocusTraversable, setFont, setForegroundColor, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, useLocalCoordinates, validate
-
Field Details
-
MAX_FLAG
protected static int MAX_FLAGThe highest reserved flag used by this class -
STYLE_BUTTON
public static final int STYLE_BUTTONStyle 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_TOGGLEStyle 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_FIRINGAn action is performed every time the mouse is released.- See Also:
-
REPEAT_FIRING
public static final int REPEAT_FIRINGFiring 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
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
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 (eitherSTYLE_BUTTON
orSTYLE_TOGGLE
).- Parameters:
contents
- The content figurestyle
- The button style
-
-
Method Details
-
addActionListener
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
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
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
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
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()Returnstrue
if rollover feedback is enabled.- Returns:
true
rollover feedback is enabled- Since:
- 2.0
-
isSelected
public boolean isSelected()Returnstrue
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) Returnstrue
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
If this Clickable has focus, this method paints a focus rectangle.- Overrides:
paintBorder
in classFigure
- Parameters:
graphics
- Graphics handle for painting- See Also:
-
paintClientArea
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 classFigure
- Parameters:
graphics
- Graphics handle for painting- Since:
- 2.0
-
removeActionListener
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
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
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 interfaceIFigure
- Overrides:
setEnabled
in classFigure
- 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
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, eitherSTYLE_BUTTON
orSTYLE_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
-