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 thegetImage(),getImagePosition()methods for generating the image to be draw. Instead to callredrawShape(), you have to use theredrawImage()method.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractCursorTool.Listener
-
Field Summary
Fields Modifier and Type Field Description protected booleanisLinuxOSprotected LayerViewPanelpanel
-
Constructor Summary
Constructors Constructor Description AbstractCursorTool(WorkbenchContext context)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidactivate(LayerViewPanel new_panel)voidadd(AbstractCursorTool.Listener listener)voidallowSnapping()Makes this CursorTool obey the snapping settings in the Options dialog.voidcancelGesture()Notifies the CursorTool that a party is requesting that the gesture currently in progress be aborted.protected booleancheck(EnableCheck check)protected voidcleanup(Graphics2D graphics)protected voidclearImage()Clears an previously painted image from screen.protected voidclearShape()static booleancomponentWithFocusIsHandledByCursorTools()utility method to be used by cursor tools to determine if the ui component with focus falls into it's purviewstatic CursorcreateCursor(Image image)The cursor will look best if the image is a 32 x 32 transparent GIF.static CursorcreateCursor(Image image, Point hotSpot)static CursorcreateCursor(Image image, Point hotSpot, String name)protected List<SnapPolicy>createStandardSnappingPolicies(Blackboard blackboard)voiddeactivate()protected voiddrawImageXOR(Graphics2D g)Draw the image in XOR mode at the specified position on screen.protected voiddrawImageXOR(Image image, Point position, Graphics2D graphics)Draw an image in XOR mode on screen.protected voiddrawShapeXOR(Graphics2D g)protected voiddrawShapeXOR(Shape shape, Graphics2D graphics)protected voidexecute(UndoableCommand command)Optional means of execution, with undoability.protected voidexecute(UndoableCommand command, boolean ignoreNull)Optional means of execution, with undoability.protected voidfireGestureFinished()protected abstract voidgestureFinished()ColorgetColor()CursorgetCursor()protected ImagegetImage()This method have to return an Image as a visual indicator.protected PointgetImagePosition()This method have to return the position for the Image.StringgetName()Returns a very brief description of this CursorTool.LayerViewPanelgetPanel()static LayerViewPanelgetPanel(CursorTool ct)protected abstract ShapegetShape()SnapManagergetSnapManager()protected StrokegetStroke()protected TaskFramegetTaskFrame()JUMPWorkbenchgetWorkbench()protected WorkbenchContextgetWorkbenchContext()booleanisGestureInProgress()Used by OrCompositeTool to determine whether a CursorTool is busy interacting with the user.booleanisRightMouseButtonUsed()protected booleanisRollingBackInvalidEdits()booleanisShapeOnScreen()Important for XOR drawing.voidmouseClicked(MouseEvent e)voidmouseDragged(MouseEvent e)voidmouseEntered(MouseEvent e)voidmouseExited(MouseEvent e)voidmouseMoved(MouseEvent e)voidmousePressed(MouseEvent e)voidmouseReleased(MouseEvent e)static Stringname(CursorTool tool)voidprohibitSnapping()protected voidredrawImage()Redraws the image on screen.protected voidredrawShape()protected voidreportNothingToUndoYet()Notifies the UndoManager that this PlugIn did not modify any model states, and therefore the undo history should remain unchanged.voidsetColor(Color color)protected voidsetControlPressed(boolean onoff)protected voidsetFilling(boolean filling)protected voidsetPanel(LayerViewPanel panel)protected voidsetShiftPressed(boolean onoff)protected voidsetStroke(Stroke stroke)protected voidsetup(Graphics2D graphics)protected org.locationtech.jts.geom.Coordinatesnap(Point2D viewPoint)protected org.locationtech.jts.geom.Coordinatesnap(org.locationtech.jts.geom.Coordinate modelCoordinate)booleansupportsSnapping()StringtoString()protected booleanwasControlPressed()protected booleanwasShiftPressed()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.vividsolutions.jump.workbench.ui.cursortool.CursorTool
getIcon
-
-
-
-
Field Detail
-
isLinuxOS
protected boolean isLinuxOS
-
panel
protected LayerViewPanel panel
-
-
Constructor Detail
-
AbstractCursorTool
public AbstractCursorTool(WorkbenchContext context)
-
-
Method Detail
-
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
-
getCursor
public Cursor getCursor()
- Specified by:
getCursorin interfaceCursorTool
-
isGestureInProgress
public boolean isGestureInProgress()
Used by OrCompositeTool to determine whether a CursorTool is busy interacting with the user.- Specified by:
isGestureInProgressin interfaceCursorTool
-
isRightMouseButtonUsed
public boolean isRightMouseButtonUsed()
- Specified by:
isRightMouseButtonUsedin interfaceCursorTool- 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:
activatein interfaceCursorTool
-
createStandardSnappingPolicies
protected List<SnapPolicy> createStandardSnappingPolicies(Blackboard blackboard)
-
isRollingBackInvalidEdits
protected boolean isRollingBackInvalidEdits()
-
deactivate
public void deactivate()
- Specified by:
deactivatein interfaceCursorTool
-
mouseClicked
public void mouseClicked(MouseEvent e)
- Specified by:
mouseClickedin interfaceMouseListener
-
mouseDragged
public void mouseDragged(MouseEvent e)
- Specified by:
mouseDraggedin interfaceMouseMotionListener
-
mouseEntered
public void mouseEntered(MouseEvent e)
- Specified by:
mouseEnteredin interfaceMouseListener
-
mouseExited
public void mouseExited(MouseEvent e)
- Specified by:
mouseExitedin interfaceMouseListener
-
mouseMoved
public void mouseMoved(MouseEvent e)
- Specified by:
mouseMovedin interfaceMouseMotionListener
-
mousePressed
public void mousePressed(MouseEvent e)
- Specified by:
mousePressedin interfaceMouseListener
-
mouseReleased
public void mouseReleased(MouseEvent e)
- Specified by:
mouseReleasedin interfaceMouseListener
-
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 thegetImage()method. For the abstract problematic please seegetImage().- 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:CursorToolNotifies the CursorTool that a party is requesting that the gesture currently in progress be aborted.- Specified by:
cancelGesturein interfaceCursorTool
-
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 drawposition- the positiongraphics- the Graphics2D
-
redrawImage
protected void redrawImage() throws ExceptionRedraws 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()
-
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).
-
getName
public String getName()
Description copied from interface:CursorToolReturns a very brief description of this CursorTool.- Specified by:
getNamein interfaceCursorTool- 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
-
-