public abstract class MouseTool extends java.awt.event.KeyAdapter implements PEMouseInputListener
super.mouseXXX()
before all
in their own implementation of the corresponding methods, or alternately simply add the following line of code :
lastMouseEvent=e
, where e
denotes 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.
Modifier and Type | Field and Description |
---|---|
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
|
protected boolean |
mouseOutside
this flag is set to true/false whenever a mouseExited/Entered event is caught.
|
Constructor and Description |
---|
MouseTool() |
Modifier and Type | Method and Description |
---|---|
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
|
PEMouseEvent |
getLastMouseEvent()
Returns the last mouse-event as produced by the last invokation of a mouseXXX method
|
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.
|
void |
keyPressed(java.awt.event.KeyEvent ke)
Triggers a fake "mouseMoved" event when a key is pressed.
|
void |
keyReleased(java.awt.event.KeyEvent ke)
Triggers a fake "mouseMoved" event when a key is released.
|
void |
mouseClicked(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field
|
void |
mouseDragged(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field
|
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.
|
void |
mouseExited(PEMouseEvent e)
Sets the mouseOutside flag to false, and stores the given mouse-event in lastMouseEvent field.
|
void |
mouseMoved(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field
|
void |
mousePressed(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field
|
void |
mouseReleased(PEMouseEvent e)
this default implementation simply stores the given mouse-event in lastMouseEvent field
|
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.
|
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.
|
protected boolean mouseOutside
protected static PEMouseEvent lastMouseEvent
public void mousePressed(PEMouseEvent e)
mousePressed
in interface PEMouseInputListener
public void mouseReleased(PEMouseEvent e)
mouseReleased
in interface PEMouseInputListener
public void mouseClicked(PEMouseEvent e)
mouseClicked
in interface PEMouseInputListener
public void mouseMoved(PEMouseEvent e)
mouseMoved
in interface PEMouseInputListener
public void mouseDragged(PEMouseEvent e)
mouseDragged
in interface PEMouseInputListener
public PEMouseEvent getLastMouseEvent()
public void mouseEntered(PEMouseEvent e)
mouseEntered
in interface PEMouseInputListener
public void mouseExited(PEMouseEvent e)
mouseExited
in interface PEMouseInputListener
public void paint(java.awt.Graphics2D g, java.awt.geom.Rectangle2D allocation, double scale)
public void init()
public void flush()
public void keyPressed(java.awt.event.KeyEvent ke)
processKeyEvent
.keyPressed
in interface java.awt.event.KeyListener
keyPressed
in class java.awt.event.KeyAdapter
public void keyReleased(java.awt.event.KeyEvent ke)
processKeyEvent
.keyReleased
in interface java.awt.event.KeyListener
keyReleased
in class java.awt.event.KeyAdapter
protected void processKeyEvent(java.awt.event.KeyEvent ke, boolean pressed)
pressed
- if TRUE, process a keyPressed event, else process a keyReleasedSubmit a bug : syd@jpicedt.org