Right you need to ensure you send the event from the display thread (just like 
a mouse click).  

We have some helper methods in PlatformGIS to help … here is the internals of 
them:

To find the current display:

Display display = Display.getCurrent();
        if (display == null) {
            display = Display.getDefault();
        }


And then send it a runnable:

display.asyncExec(runnable);

Our helper method is:

PlatformGIS.asyncInDisplayThread( runnable, true )

Good luck; working with the display thread is an annoying pat of using SWT (or 
any user interface toolkit)
--  
Jody Garnett


On Tuesday, 7 February 2012 at 8:56 PM, Alberto Debiasi wrote:

> Thanks for the response,
> I tried to follow your suggestion:  
>        
>  PointTool pointTool =.....
>         IMapDisplay mapDisplay=map.getRenderManager().getMapDisplay();
> //I create a mouse event
>         MapMouseEvent mouseEvent = new MapMouseEvent(mapDisplay,10,10,0,1,1); 
>         
>         pt.mousePressed(mouseEvent);
>  
> But I have an exception:
>  
> Exception in thread "AWT-EventQueue-0" org.eclipse.swt.SWTException: Invalid 
> thread access
>     at org.eclipse.swt.SWT.error(SWT.java:3563)
>     at org.eclipse.swt.SWT.error(SWT.java:3481)
>     at org.eclipse.swt.SWT.error(SWT.java:3452)
>     at 
> net.refractions.udig.tools.edit.MouseTracker.checkAccess(MouseTracker.java:96)
>     at 
> net.refractions.udig.tools.edit.MouseTracker.updateState(MouseTracker.java:56)
>     at 
> net.refractions.udig.tools.edit.EditToolHandler.handleEvent(EditToolHandler.java:227)
>     at 
> net.refractions.udig.tools.edit.AbstractEditTool.onMousePressed(AbstractEditTool.java:235)
>     at 
> net.refractions.udig.project.ui.tool.SimpleTool.mousePressed(SimpleTool.java:142)
>  
> In particular in the method checkAccess() in the class MouseTracker:
>  
>  private void checkAccess() {
>         if( Display.getCurrent()==null )
>             SWT.error(SWT.ERROR_THREAD_INVALID_ACCESS);
>     }
>  
>  
> Alberto.
>  
> 2012/2/6 Jody Garnett <[email protected] (mailto:[email protected])>
> > Mouse events are sent to the current tool. Tour can hunt down this
> > tool (use applicationgis to find the tool manager) and then send it
> > mouse event objects. You may wish to do so from the display thread.
> >  
> > To simulate mouse and keyboard interaction more generally for test
> > cases use SWTBot
> >  
> > --
> > Jody Garnett
> >  
> > On 07/02/2012, at 12:31 AM, Alberto Debiasi <[email protected] 
> > (mailto:[email protected])> wrote:
> >  
> > > Hello everybody,
> > >
> > > How can I "emulate" the click of the mouse on the map?
> > >
> > > For example with a command like this:
> > >
> > > .clickOnTheMap(currentMap,coordinates);
> > >
> > > Thanks.
> > > Alberto
> > > _______________________________________________
> > > User-friendly Desktop Internet GIS (uDig)
> > > http://udig.refractions.net
> > > http://lists.refractions.net/mailman/listinfo/udig-devel
> > _______________________________________________
> > udig-users mailing list
> > [email protected] (mailto:[email protected])
> > http://lists.refractions.net/mailman/listinfo/udig-users
>  

_______________________________________________
User-friendly Desktop Internet GIS (uDig)
http://udig.refractions.net
http://lists.refractions.net/mailman/listinfo/udig-devel

Reply via email to