Package ptolemy.domains.gr.lib
Class FigureInteractor
- java.lang.Object
-
- diva.canvas.interactor.AbstractInteractor
-
- ptolemy.domains.gr.lib.FigureInteractor
-
- All Implemented Interfaces:
LayerListener,LayerMotionListener,Interactor,java.awt.event.KeyListener,java.util.EventListener
public class FigureInteractor extends AbstractInteractor implements java.awt.event.KeyListener
Listen for and handle events on a Diva figure. Because Diva figures are not derived from Java's component class, implementing a key listener directly would be problematic. Instead, this class must be made aware of the ViewScreen2D object that contains the figure, as the ViewScreen2D object will forward all keyboard events that occur on a selected figure to this listener. When initially adding a figure to the view screen, the view screen must call the setViewScreen() method of the figure with a reference to itself as the parameter.- Since:
- Ptolemy II 4.0
- Version:
- $Id$
- Author:
- Ismael M. Sarmiento
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Yellow (ismael)
-
-
Constructor Summary
Constructors Constructor Description FigureInteractor(AbstractFigure figure)Construct a FigureInteractor for the given figure.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanisSelected()Return whether or not a figure has been selected in the viewscreen.voidkeyPressed(java.awt.event.KeyEvent e)Translate a selected figure according to which arrow key is pressed.voidkeyReleased(java.awt.event.KeyEvent e)Included to comply with the KeyListener interface requirement.voidkeyTyped(java.awt.event.KeyEvent e)Included to comply with the KeyListener interface requirement.voidmouseClicked(LayerEvent layerEvent)Included to comply with the AbstractListener implementation requirement.voidmouseDragged(LayerEvent layerEvent)Translate the figure to wherever the mouse is dragged.voidmouseEntered(LayerEvent layerEvent)Included to comply with the AbstractListener implementation requirement.voidmouseExited(LayerEvent layerEvent)Included to comply with the AbstractListener implementation requirement.voidmouseMoved(LayerEvent layerEvent)Included to comply with the AbstractListener implementation requirement.voidmousePressed(LayerEvent layerEvent)Update the state of this listener to reflect where on the figure the mouse button was pressed, and change the mouse cursor to show that the figure can now be dragged.voidmouseReleased(LayerEvent layerEvent)Included to comply with the AbstractListener implementation requirement.voidsetSelected(boolean selected)Set whether the figure being listened to is selected or not selected.voidsetViewScreen(ViewScreen2D viewScreen)Notify this object of the view screen which contains the figure this object is listening to.-
Methods inherited from class diva.canvas.interactor.AbstractInteractor
accept, getMouseFilter, isConsuming, isEnabled, isMotionEnabled, setConsuming, setEnabled, setMotionEnabled, setMouseFilter
-
-
-
-
Constructor Detail
-
FigureInteractor
public FigureInteractor(AbstractFigure figure)
Construct a FigureInteractor for the given figure.- Parameters:
figure- The figure this interactor is to listen and respond to.
-
-
Method Detail
-
isSelected
public boolean isSelected()
Return whether or not a figure has been selected in the viewscreen. A figure is selected by a single mouse click on the figure, and deselected by a single mouse click anywhere outside the figure.- Returns:
- A boolean true if the figure is selected, and false otherwise.
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent e)
Translate a selected figure according to which arrow key is pressed. This will respond only to the arrow keys outside of the number pad.- Specified by:
keyPressedin interfacejava.awt.event.KeyListener- Parameters:
e- The KeyEvent received.
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent e)
Included to comply with the KeyListener interface requirement. This method does nothing in its current implementation.- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener- Parameters:
e- The KeyEvent received.
-
keyTyped
public void keyTyped(java.awt.event.KeyEvent e)
Included to comply with the KeyListener interface requirement. This method does nothing in its current implementation.- Specified by:
keyTypedin interfacejava.awt.event.KeyListener- Parameters:
e- The KeyEvent received.
-
mouseClicked
public void mouseClicked(LayerEvent layerEvent)
Included to comply with the AbstractListener implementation requirement. This method does nothing in its current implementation.- Specified by:
mouseClickedin interfaceLayerListener- Overrides:
mouseClickedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mouseDragged
public void mouseDragged(LayerEvent layerEvent)
Translate the figure to wherever the mouse is dragged.- Specified by:
mouseDraggedin interfaceLayerListener- Overrides:
mouseDraggedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mouseEntered
public void mouseEntered(LayerEvent layerEvent)
Included to comply with the AbstractListener implementation requirement. This method does nothing in its current implementation.- Specified by:
mouseEnteredin interfaceLayerMotionListener- Overrides:
mouseEnteredin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mouseExited
public void mouseExited(LayerEvent layerEvent)
Included to comply with the AbstractListener implementation requirement. This method does nothing in its current implementation.- Specified by:
mouseExitedin interfaceLayerMotionListener- Overrides:
mouseExitedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mouseMoved
public void mouseMoved(LayerEvent layerEvent)
Included to comply with the AbstractListener implementation requirement. This method does nothing in its current implementation.- Specified by:
mouseMovedin interfaceLayerMotionListener- Overrides:
mouseMovedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mousePressed
public void mousePressed(LayerEvent layerEvent)
Update the state of this listener to reflect where on the figure the mouse button was pressed, and change the mouse cursor to show that the figure can now be dragged.- Specified by:
mousePressedin interfaceLayerListener- Overrides:
mousePressedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
mouseReleased
public void mouseReleased(LayerEvent layerEvent)
Included to comply with the AbstractListener implementation requirement. This method does nothing in its current implementation.- Specified by:
mouseReleasedin interfaceLayerListener- Overrides:
mouseReleasedin classAbstractInteractor- Parameters:
layerEvent- The LayerEvent received.
-
setSelected
public void setSelected(boolean selected)
Set whether the figure being listened to is selected or not selected.- Parameters:
selected- true if the figure being listened to is selected, false otherwise.
-
setViewScreen
public void setViewScreen(ViewScreen2D viewScreen)
Notify this object of the view screen which contains the figure this object is listening to.- Parameters:
viewScreen- The viewScreen containing the figure this interactor is listening to.
-
-