Class AbstractCursorTool

java.lang.Object
com.vividsolutions.jump.workbench.ui.cursortool.AbstractCursorTool
All Implemented Interfaces:
CursorTool, MouseListener, MouseMotionListener, EventListener
Direct Known Subclasses:
ConstrainedDragTool, ConstrainedMultiClickTool, DragTool, MultiClickTool, SnapIndicatorTool

public abstract class AbstractCursorTool extends Object implements CursorTool
A tool that draws an XOR visual indicator. Subclasses need not keep track of the XOR state of the indicator -- that logic is all handled by this class. Even if the LayerViewPanel is repainted while the XOR indicator is on-screen. You can use a java.awt.Shape for a simple visual indicator such as a Rectangle or Ellipse for example. For more complex indicators you can use a java.awt.Image. Here you can build complex geometric stuff with filling, transparency and so on. Real photos are possible too. For the use of an image as a visual indicator you have to override the getImage(), getImagePosition() methods for generating the image to be draw. Instead to call redrawShape(), you have to use the redrawImage() method.
  • Field Details

    • isLinuxOS

      protected boolean isLinuxOS
    • panel

      protected LayerViewPanel panel
  • Constructor Details

  • Method Details

    • getWorkbenchContext

      protected WorkbenchContext getWorkbenchContext()
    • allowSnapping

      public void allowSnapping()
      Makes this CursorTool obey the snapping settings in the Options dialog.
    • prohibitSnapping

      public void prohibitSnapping()
    • supportsSnapping

      public boolean supportsSnapping()
    • setShiftPressed

      protected void setShiftPressed(boolean onoff)
    • wasShiftPressed

      protected boolean wasShiftPressed()
    • setControlPressed

      protected void setControlPressed(boolean onoff)
    • wasControlPressed

      protected boolean wasControlPressed()
    • createCursor

      public static Cursor createCursor(Image image)
      The cursor will look best if the image is a 32 x 32 transparent GIF. TODO: rework to provide hires cursors 64x64 and up
      Parameters:
      image - the cursor image
      Returns:
      a Cursor
    • createCursor

      public static Cursor createCursor(Image image, Point hotSpot)
    • createCursor

      public static Cursor createCursor(Image image, Point hotSpot, String name)
    • getCursor

      public Cursor getCursor()
      Specified by:
      getCursor in interface CursorTool
    • isGestureInProgress

      public boolean isGestureInProgress()
      Used by OrCompositeTool to determine whether a CursorTool is busy interacting with the user.
      Specified by:
      isGestureInProgress in interface CursorTool
    • isRightMouseButtonUsed

      public boolean isRightMouseButtonUsed()
      Specified by:
      isRightMouseButtonUsed in interface CursorTool
      Returns:
      true if this CursorTool uses the right mouse button; false to allow the panel to show a popup-menu on right-clicks
    • isShapeOnScreen

      public boolean isShapeOnScreen()
      Important for XOR drawing. Even if #getShape returns null, this method will return true between calls of #redrawShape and #clearShape.
      Returns:
      true if the cursor shape is on screen (even if not visible)
    • activate

      public void activate(LayerViewPanel new_panel)
      Specified by:
      activate in interface CursorTool
    • createStandardSnappingPolicies

      protected List<SnapPolicy> createStandardSnappingPolicies(Blackboard blackboard)
    • isRollingBackInvalidEdits

      protected boolean isRollingBackInvalidEdits()
    • deactivate

      public void deactivate()
      Specified by:
      deactivate in interface CursorTool
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • setColor

      public void setColor(Color color)
    • setFilling

      protected void setFilling(boolean filling)
    • getStroke

      protected Stroke getStroke()
      **
    • setStroke

      protected void setStroke(Stroke stroke)
    • setup

      protected void setup(Graphics2D graphics)
    • getShape

      protected abstract Shape getShape() throws Exception
      Returns:
      null if nothing should be drawn
      Throws:
      Exception - if an Exception occurs during Shape construction
    • getImage

      protected Image getImage()
      This method have to return an Image as a visual indicator. Usually this method should to be abstract. But if we do this here, many other derived classes have to implement this method. Thereby we would break the compatibility for many other classes in OJ and 3rd party plugins.
      Returns:
      a Image or null if nothing should be drawn.
    • getImagePosition

      protected Point getImagePosition()
      This method have to return the position for the Image. The position is the top left corner of the image for the Graphics2D.drawImage() method. This method is called after the getImage() method. For the abstract problematic please see getImage().
      Returns:
      the position for the Image
    • cleanup

      protected void cleanup(Graphics2D graphics)
    • clearShape

      protected void clearShape()
    • clearImage

      protected void clearImage()
      Clears an previously painted image from screen.
    • cancelGesture

      public void cancelGesture()
      Description copied from interface: CursorTool
      Notifies the CursorTool that a party is requesting that the gesture currently in progress be aborted.
      Specified by:
      cancelGesture in interface CursorTool
    • drawShapeXOR

      protected void drawShapeXOR(Graphics2D g) throws Exception
      Throws:
      Exception
    • drawImageXOR

      protected void drawImageXOR(Graphics2D g)
      Draw the image in XOR mode at the specified position on screen. The position and the image is remembered for a later clear.
      Parameters:
      g - the graphics context
    • drawShapeXOR

      protected void drawShapeXOR(Shape shape, Graphics2D graphics)
    • drawImageXOR

      protected void drawImageXOR(Image image, Point position, Graphics2D graphics)
      Draw an image in XOR mode on screen.
      Parameters:
      image - the image to be draw
      position - the position
      graphics - the Graphics2D
    • redrawShape

      protected void redrawShape() throws Exception
      Throws:
      Exception
    • redrawImage

      protected void redrawImage() throws Exception
      Redraws the image on screen.
      Throws:
      Exception - if an Exception occurs during drawing
    • snap

      protected org.locationtech.jts.geom.Coordinate snap(Point2D viewPoint) throws NoninvertibleTransformException
      Throws:
      NoninvertibleTransformException
    • snap

      protected org.locationtech.jts.geom.Coordinate snap(org.locationtech.jts.geom.Coordinate modelCoordinate)
    • getTaskFrame

      protected TaskFrame getTaskFrame()
      Returns:
      null if the LayerViewPanel is not inside a TaskFrame
    • getWorkbench

      public JUMPWorkbench getWorkbench()
    • gestureFinished

      protected abstract void gestureFinished() throws Exception
      Throws:
      Exception
    • fireGestureFinished

      protected void fireGestureFinished() throws Exception
      Throws:
      Exception
    • add

      public void add(AbstractCursorTool.Listener listener)
    • execute

      protected void execute(UndoableCommand command)
      Optional means of execution, with undoability.
      Parameters:
      command - undoable command to execute
    • execute

      protected void execute(UndoableCommand command, boolean ignoreNull)
      Optional means of execution, with undoability. Allows to ignore when command is null in case the calling code already warns user accordingly.
      Parameters:
      command -
      ignoreNull -
    • reportNothingToUndoYet

      protected void reportNothingToUndoYet()
      Notifies the UndoManager that this PlugIn did not modify any model states, and therefore the undo history should remain unchanged. Call this method inside #execute(PlugInContext).
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getName

      public String getName()
      Description copied from interface: CursorTool
      Returns a very brief description of this CursorTool.
      Specified by:
      getName in interface CursorTool
      Returns:
      the name of this CursorTool
    • getPanel

      public static LayerViewPanel getPanel(CursorTool ct)
    • getPanel

      public final LayerViewPanel getPanel()
    • setPanel

      protected void setPanel(LayerViewPanel panel)
    • name

      public static String name(CursorTool tool)
    • check

      protected boolean check(EnableCheck check)
    • getSnapManager

      public SnapManager getSnapManager()
    • getColor

      public Color getColor()
    • componentWithFocusIsHandledByCursorTools

      public static boolean componentWithFocusIsHandledByCursorTools()
      utility method to be used by cursor tools to determine if the ui component with focus falls into it's purview
      Returns:
      boolean