Class 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 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

      Fields 
      Modifier and Type Field 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 Summary

      Constructors 
      Constructor Description
      MouseTool()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method 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.
      • 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

      • 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​(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 calls processKeyEvent(java.awt.event.KeyEvent,boolean).
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
        Overrides:
        keyPressed in class java.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 calls processKeyEvent(java.awt.event.KeyEvent,boolean).
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
        Overrides:
        keyReleased in class java.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