Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » BendpointEditPolicy setReferencePoints IndexOutOfBoundsException
BendpointEditPolicy setReferencePoints IndexOutOfBoundsException [message #241092] Tue, 29 January 2008 12:07 Go to next message
J F is currently offline J F
Messages: 242
Registered: July 2009
Senior Member
I have a problem with org.eclipse.gef.editpolicies.BendpointEditPolicy

When I drag around a Bendpoint I very occiasionally get an
IndexOutOfBoundsException:

java.lang.IndexOutOfBoundsException: Index: -1, Size: 3
at org.eclipse.draw2d.geometry.PointList.getPoint(PointList.jav a:189)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.setReferenc ePoints(BendpointEditPolicy.java:288)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.showMoveBen dpointFeedback(BendpointEditPolicy.java:342)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.showSourceF eedback(BendpointEditPolicy.java:375)
at
org.eclipse.gef.editparts.AbstractEditPart.showSourceFeedbac k(AbstractEditPart.java:974)
at
org.eclipse.gef.tools.SimpleDragTracker.showSourceFeedback(S impleDragTracker.java:229)
at
org.eclipse.gef.tools.SimpleDragTracker.handleDragInProgress (SimpleDragTracker.java:137)
at org.eclipse.gef.tools.AbstractTool.mouseDrag(AbstractTool.ja va:983)
at org.eclipse.gef.tools.SelectionTool.mouseDrag(SelectionTool. java:511)
at org.eclipse.gef.EditDomain.mouseDrag(EditDomain.java:226)

Occaisionally the index is the same as size.

I only get it very rarely when I drag a bendpoint from the middle very
rapidly towards one of the endpoints.

In this case it seems that setReferencePoints would tend to return either
the first or last of the getConnection().getPoints();
and this in turn would cause the code

points.getPoint(ref1, bpIndex - 1);


or

points.getPoint(ref1, bpIndex + 1);


to throw the IndexOutOfBoundsException.


Am I doing something wrong? ( I am not using the Manhattan router )?


Its simple enough to fix if it is a bug but I wondered since this code has
been stable for a while whether I was doing something wrong...
Re: BendpointEditPolicy setReferencePoints IndexOutOfBoundsException [message #241097 is a reply to message #241092] Tue, 29 January 2008 13:03 Go to previous messageGo to next message
J F is currently offline J F
Messages: 242
Registered: July 2009
Senior Member
Tried reproducing this with the GEF Logic Diagram example. I got the same
problem, simply creating an Or gate and an XOR gate and joining them with
a Connection. I then grabbed a central bendpoint and Waggled it around (
Mouse pressed )...

java.lang.IndexOutOfBoundsException: Index: 4, Size: 4
at org.eclipse.draw2d.geometry.PointList.getPoint(PointList.jav a:189)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.setReferenc ePoints(BendpointEditPolicy.java:290)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.showMoveBen dpointFeedback(BendpointEditPolicy.java:342)
at
org.eclipse.gef.editpolicies.BendpointEditPolicy.showSourceF eedback(BendpointEditPolicy.java:375)
at
org.eclipse.gef.editparts.AbstractEditPart.showSourceFeedbac k(AbstractEditPart.java:974)
at
org.eclipse.gef.tools.SimpleDragTracker.showSourceFeedback(S impleDragTracker.java:229)
at
org.eclipse.gef.tools.SimpleDragTracker.handleDragInProgress (SimpleDragTracker.java:137)
at org.eclipse.gef.tools.AbstractTool.mouseDrag(AbstractTool.ja va:983)
at org.eclipse.gef.tools.SelectionTool.mouseDrag(SelectionTool. java:511)
at org.eclipse.gef.EditDomain.mouseDrag(EditDomain.java:226)
at
org.eclipse.gef.ui.parts.DomainEventDispatcher.dispatchMouse Moved(DomainEventDispatcher.java:357)
at
org.eclipse.draw2d.LightweightSystem$EventHandler.mouseMove( LightweightSystem.java:533)
at
org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListe ner.java:198)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java :66)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.ja va:3682)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java :3293)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.jav a:2389)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:22 19)
at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
at
org.eclipse.core.databinding.observable.Realm.runWithDefault (Realm.java:289)
at
org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Work bench.java:461)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.j ava:149)
at
org.eclipse.ui.internal.ide.application.IDEApplication.start (IDEApplication.java:106)
at
org.eclipse.equinox.internal.app.EclipseAppHandle.run(Eclips eAppHandle.java:169)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:106)
at
org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:76)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:363)
at
org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:176)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java: 508)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
at org.eclipse.equinox.launcher.Main.run(Main.java:1173)
at org.eclipse.equinox.launcher.Main.main(Main.java:1148)


I'll post the fix once I test it...
Re: BendpointEditPolicy setReferencePoints IndexOutOfBoundsException [message #241102 is a reply to message #241097] Tue, 29 January 2008 13:42 Go to previous message
J F is currently offline J F
Messages: 242
Registered: July 2009
Senior Member
Here is the obvious quick fix;

private void setReferencePoints(BendpointRequest request)
{
PointList points = getConnection().getPoints();
int bpIndex = -1;
List bendPoints = (List) getConnection().getRoutingConstraint();
Point bp = ((Bendpoint)
bendPoints.get(request.getIndex())).getLocation();

int smallestDistance = -1;

for (int i = 0; i < points.size(); i++)
{
if(smallestDistance == -1 || points.getPoint(i).getDistance2(bp) <
smallestDistance)
{
bpIndex = i;
smallestDistance = points.getPoint(i).getDistance2(bp);
if(smallestDistance == 0)
break;
}
}

//BUG FIX BEGIN
if(bpIndex == 0 || bpIndex == (points.size() - 1))
{
points.getPoint(ref1, 0);
getConnection().translateToAbsolute(ref1);
points.getPoint(ref2, (points.size() - 1));
getConnection().translateToAbsolute(ref2);
}
//BUG FIX END
else
{
points.getPoint(ref1, bpIndex - 1);
getConnection().translateToAbsolute(ref1);
points.getPoint(ref2, bpIndex + 1);
getConnection().translateToAbsolute(ref2);
}
}
Previous Topic:splines or bezier curves with Draw2D?
Next Topic:Pinning Palette tools using keyboard plus click
Goto Forum:
  


Current Time: Sat Oct 25 22:52:52 GMT 2014

Powered by FUDForum. Page generated in 0.02146 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software