Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## jpicedt.graphic.toolkit
Class MouseTool

    java.lang.Object
      java.awt.event.KeyAdapter
          jpicedt.graphic.toolkit.MouseTool

All Implemented Interfaces:
  EventListener, KeyListener, PEMouseInputListener

Direct Known Subclasses:
  DrawToolFactory.AbstractCurveDrawTool, DrawToolFactory.GenericDrawTool, DrawToolFactory.TextDrawTool, MoveTool, RotateTool, ScaleTool, SelectionTool, ZoomTool

public abstract class MouseTool
extends 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 call `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.

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
`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 Summary
`MouseTool()`

Method Summary
`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(KeyEvent ke)` Triggers a fake "mouseMoved" event when a key is pressed.
`void` | `keyReleased(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(Graphics2D g, Rectangle2D allocation, double scale)` Allow the tool to paint shapes that are specific to this tool.
`protected void` | `processKeyEvent(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.

Methods inherited from class java.awt.event.KeyAdapter
`keyTyped`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

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

Constructor Detail

### MouseTool

    public MouseTool()

Method Detail

### mousePressed

    public void mousePressed(PEMouseEvent e)

  this default implementation simply stores the given mouse-event in lastMouseEvent field

  Specified by:
    `mousePressed` in interface `PEMouseInputListener`

### mouseReleased

    public void mouseReleased(PEMouseEvent e)

  this default implementation simply stores the given mouse-event in lastMouseEvent field

  Specified by:
    `mouseReleased` in interface `PEMouseInputListener`

### mouseClicked

    public void mouseClicked(PEMouseEvent e)

  this default implementation simply stores the given mouse-event in lastMouseEvent field

  Specified by:
    `mouseClicked` in interface `PEMouseInputListener`

### mouseMoved

    public void mouseMoved(PEMouseEvent e)

  this default implementation simply stores the given mouse-event in lastMouseEvent field

  Specified by:
    `mouseMoved` in interface `PEMouseInputListener`

### mouseDragged

    public void mouseDragged(PEMouseEvent e)

  this default implementation simply stores the given mouse-event in lastMouseEvent field

  Specified by:
    `mouseDragged` in interface `PEMouseInputListener`

### 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:
    `mouseEntered` in interface `PEMouseInputListener`

### mouseExited

    public void mouseExited(PEMouseEvent e)

  Sets the mouseOutside flag to false, and stores the given mouse-event in lastMouseEvent field.

  Specified by:
    `mouseExited` in interface `PEMouseInputListener`

### paint

    public void paint(Graphics2D g,
                      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(KeyEvent ke)

  Triggers a fake "mouseMoved" event when a key is pressed. Current implementation merely calls `processKeyEvent`.

  Specified by:
    `keyPressed` in interface `KeyListener`

### keyReleased

    public void keyReleased(KeyEvent ke)

  Triggers a fake "mouseMoved" event when a key is released. Current implementation merely calls `processKeyEvent`.

  Specified by:
    `keyReleased` in interface `KeyListener`

### processKeyEvent

    protected void processKeyEvent(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

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| http://www.jpicedt.org
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Submit a bug : syd@jpicedt.org