Package jpicedt.graphic.toolkit
Class MouseTool
- java.lang.Object
-
- java.awt.event.KeyAdapter
-
- jpicedt.graphic.toolkit.MouseTool
-
- All Implemented Interfaces:
java.awt.event.KeyListener,java.util.EventListener,PEMouseInputListener
- Direct Known Subclasses:
DrawToolFactory.AbstractCurveDrawTool,DrawToolFactory.GenericDrawTool,DrawToolFactory.TextDrawTool,MoveTool,RotateTool,ScaleTool,SelectionTool,ZoomTool
public abstract class MouseTool extends java.awt.event.KeyAdapter implements PEMouseInputListener
An implementation of PEMouseInputListener that factors common behaviour for EditorKit's mouse tools, and implements KeyListener so that mouse-tools can also listen to key events (e.g. to update cursor,...)
This implementation offers a convenient mechanism for generating MouseMoved events as a result of a KeyPressed/KeyReleased event. If this behaviour is to be preserved, subclassers should either callsuper.mouseXXX()before all in their own implementation of the corresponding methods, or alternately simply add the following line of code :lastMouseEvent=e, whereedenotes the mouse-event parameter.Besides, this class provide a "paint" method which, like Element's, allows the tool to draw shapes (on the associated PECanvas) that are specific to this tool.
- Since:
- jPicEdt 1.3.2
- Version:
- $Id: MouseTool.java,v 1.10.2.1 2007/09/02 11:56:28 reynal Exp $
- Author:
- Sylvain Reynal
-
-
Field Summary
Fields Modifier and Type Field Description protected static PEMouseEventlastMouseEventthis field remembers the last mouse-event produced by a call to one of the mouseXXX methods ; shared by every MouseToolprotected booleanmouseOutsidethis flag is set to true/false whenever a mouseExited/Entered event is caught.
-
Constructor Summary
Constructors Constructor Description MouseTool()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidflush()called when this tool is being replaced by another mouse-tool in the hosting editor kit ; this is mainly for mousetools using more than one sequence, for it gives them a chance to clean themselves up for the next timePEMouseEventgetLastMouseEvent()Returns the last mouse-event as produced by the last invokation of a mouseXXX methodvoidinit()called when this tool is being activated in the hosting editor kit ; this is mainly for mousetools that need to do some initialization work before any mouse-event occurs.voidkeyPressed(java.awt.event.KeyEvent ke)Triggers a fake "mouseMoved" event when a key is pressed.voidkeyReleased(java.awt.event.KeyEvent ke)Triggers a fake "mouseMoved" event when a key is released.voidmouseClicked(PEMouseEvent e)this default implementation simply stores the given mouse-event in lastMouseEvent fieldvoidmouseDragged(PEMouseEvent e)this default implementation simply stores the given mouse-event in lastMouseEvent fieldvoidmouseEntered(PEMouseEvent e)Sets the mouseOutside flag to true, stores the given mouse-event in lastMouseEvent field, and request focus on the PECanvas that dispatched this mouse event.voidmouseExited(PEMouseEvent e)Sets the mouseOutside flag to false, and stores the given mouse-event in lastMouseEvent field.voidmouseMoved(PEMouseEvent e)this default implementation simply stores the given mouse-event in lastMouseEvent fieldvoidmousePressed(PEMouseEvent e)this default implementation simply stores the given mouse-event in lastMouseEvent fieldvoidmouseReleased(PEMouseEvent e)this default implementation simply stores the given mouse-event in lastMouseEvent fieldvoidpaint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Allow the tool to paint shapes that are specific to this tool.protected voidprocessKeyEvent(java.awt.event.KeyEvent ke, boolean pressed)Triggers a fake "mouseMoved" event if a key is pressed or released, with the adequate key modifiers ; this is a "lazy" handling of key-events which delegates to the mouse-handler.
-
-
-
Field Detail
-
mouseOutside
protected boolean mouseOutside
this flag is set to true/false whenever a mouseExited/Entered event is caught.
For instance, it may be used by subclasses to trigger an autoscrolling operation.
-
lastMouseEvent
protected static PEMouseEvent lastMouseEvent
this field remembers the last mouse-event produced by a call to one of the mouseXXX methods ; shared by every MouseTool
-
-
Method Detail
-
mousePressed
public void mousePressed(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field- Specified by:
mousePressedin interfacePEMouseInputListener
-
mouseReleased
public void mouseReleased(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field- Specified by:
mouseReleasedin interfacePEMouseInputListener
-
mouseClicked
public void mouseClicked(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field- Specified by:
mouseClickedin interfacePEMouseInputListener
-
mouseMoved
public void mouseMoved(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field- Specified by:
mouseMovedin interfacePEMouseInputListener
-
mouseDragged
public void mouseDragged(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field- Specified by:
mouseDraggedin interfacePEMouseInputListener
-
getLastMouseEvent
public PEMouseEvent getLastMouseEvent()
Returns the last mouse-event as produced by the last invokation of a mouseXXX method
-
mouseEntered
public void mouseEntered(PEMouseEvent e)
Sets the mouseOutside flag to true, stores the given mouse-event in lastMouseEvent field, and request focus on the PECanvas that dispatched this mouse event.- Specified by:
mouseEnteredin interfacePEMouseInputListener
-
mouseExited
public void mouseExited(PEMouseEvent e)
Sets the mouseOutside flag to false, and stores the given mouse-event in lastMouseEvent field.- Specified by:
mouseExitedin interfacePEMouseInputListener
-
paint
public void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)Allow the tool to paint shapes that are specific to this tool. This method is called by the hosting EditorKit.
For instance, this method may paint selection areas, markers, ... Current implementation does nothing.
-
init
public void init()
called when this tool is being activated in the hosting editor kit ; this is mainly for mousetools that need to do some initialization work before any mouse-event occurs.
-
flush
public void flush()
called when this tool is being replaced by another mouse-tool in the hosting editor kit ; this is mainly for mousetools using more than one sequence, for it gives them a chance to clean themselves up for the next time
-
keyPressed
public void keyPressed(java.awt.event.KeyEvent ke)
Triggers a fake "mouseMoved" event when a key is pressed. Current implementation merely callsprocessKeyEvent(java.awt.event.KeyEvent,boolean).- Specified by:
keyPressedin interfacejava.awt.event.KeyListener- Overrides:
keyPressedin classjava.awt.event.KeyAdapter
-
keyReleased
public void keyReleased(java.awt.event.KeyEvent ke)
Triggers a fake "mouseMoved" event when a key is released. Current implementation merely callsprocessKeyEvent(java.awt.event.KeyEvent,boolean).- Specified by:
keyReleasedin interfacejava.awt.event.KeyListener- Overrides:
keyReleasedin classjava.awt.event.KeyAdapter
-
processKeyEvent
protected void processKeyEvent(java.awt.event.KeyEvent ke, boolean pressed)Triggers a fake "mouseMoved" event if a key is pressed or released, with the adequate key modifiers ; this is a "lazy" handling of key-events which delegates to the mouse-handler. The goal is e.g. to allow the receiver to update things as cursor's shape/help-message/... when a key is pressed.- Parameters:
pressed- if TRUE, process a keyPressed event, else process a keyReleased
-
-