<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Implementing_cursortools</id>
	<title>Implementing cursortools - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://ojwiki.soldin.de/index.php?action=history&amp;feed=atom&amp;title=Implementing_cursortools"/>
	<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Implementing_cursortools&amp;action=history"/>
	<updated>2026-10-15T09:16:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.5</generator>
	<entry>
		<id>https://ojwiki.soldin.de/index.php?title=Implementing_cursortools&amp;diff=327&amp;oldid=prev</id>
		<title>Mentaer: Created page with &#039;To implement a new cursortool, the best way is to study and subclass existant cursortools with a similar behaviour: * for example cursortool #DragTool  if your tool needs a mouse…&#039;</title>
		<link rel="alternate" type="text/html" href="https://ojwiki.soldin.de/index.php?title=Implementing_cursortools&amp;diff=327&amp;oldid=prev"/>
		<updated>2009-10-18T21:55:06Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;To implement a new cursortool, the best way is to study and subclass existant cursortools with a similar behaviour: * for example cursortool #DragTool  if your tool needs a mouse…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;To implement a new cursortool, the best way is to study and subclass existant cursortools with a similar behaviour:&lt;br /&gt;
* for example cursortool #DragTool  if your tool needs a mouse drag;&lt;br /&gt;
* or cursortool#NClickTool if your tool uses several clicks&lt;br /&gt;
&lt;br /&gt;
(see Jump Developer&amp;#039;s Guide chapter 6. for more informations on cursortool classes)&lt;br /&gt;
&lt;br /&gt;
Let&amp;#039;s create a simple cursortool that displays cursor coordinates in a java console, each time we click once in the layerViewPanel (not a very useful tool...):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class CoordinateCursorTool extends AbstractCursorTool{&lt;br /&gt;
     private Coordinate actualCoord = new Coordinate(); &lt;br /&gt;
     public RasterQueryCursorTool() //constructor does nothing special here&lt;br /&gt;
     &lt;br /&gt;
&lt;br /&gt;
     public Icon getIcon() {&lt;br /&gt;
     return IconLoader.icon(&amp;quot;My_toolbar_Icon.gif&amp;quot;);&lt;br /&gt;
     //specify here the toolbar icon file (button image) to use%&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
     public Cursor getCursor() {&lt;br /&gt;
     return createCursor(IconLoader.icon(&amp;quot;My_Cursor.gif&amp;quot;)&lt;br /&gt;
            .getImage()); //specify here the cursor image file to use&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
    public void deactivate() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public boolean isRightMouseButtonUsed() {&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    public void mouseClicked(MouseEvent e) {&lt;br /&gt;
        try {//add here the code to    execute when the mouse is clicked%&lt;br /&gt;
            actualCoord = getPanel().getViewport().toModelCoordinate(&lt;br /&gt;
                    e.getPoint());&lt;br /&gt;
	system.out.println(actualCoord); //Display coordinates as a string&lt;br /&gt;
        } catch (NoninvertibleTransformException e1) {&lt;br /&gt;
                  e1.printStackTrace();&lt;br /&gt;
        }&lt;br /&gt;
	fireGestureFinished();  //Notify that mouse gesture is finished &lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
     public boolean isGestureInProgress() {&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public void cancelGesture() {&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public String getName() {&lt;br /&gt;
        return &amp;quot;CoordinateTool&amp;quot;;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    protected Shape getShape() throws Exception {&lt;br /&gt;
        return null; //because nothing should be drawn here&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    protected void gestureFinished() throws Exception {&lt;br /&gt;
        reportNothingToUndoYet();&lt;br /&gt;
&lt;br /&gt;
        }}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then we add our cursortool to the workbench toolbar. This can be done in the initialize() method of a new plugin:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
     public void initialize(PlugInContext context){&lt;br /&gt;
      WorkbenchFrame frame = context.getWorkbenchContext()&lt;br /&gt;
      .getWorkbench().getFrame();&lt;br /&gt;
&lt;br /&gt;
         frame.getToolBar().addCursorTool(new CoordinateCursorTool());&lt;br /&gt;
&lt;br /&gt;
      //etc...&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the workbench, you have now a new button. Press it and the CoordinateCursortool becomes active (the #activate method is called). Have fun!&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Thanks to Paul Plouy for writing up the tutorial above. Note that there are some subclasses of AbstractCursorTool that you can subclass to get additional power for free; for example: MultiClickTool, SpecifyFeaturesTool, etc. For examples of their use, see the classes in com.vividsolutions.jump.workbench.ui.cursortool [Jon Aquino 2005-09-22]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;hr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
There are several good examples of CursorTools in the OpenJUMP source code. Check out the cursortools folder. [Jon Aquino 2005-11-04]&lt;/div&gt;</summary>
		<author><name>Mentaer</name></author>
	</entry>
</feed>