Relink, snap back to original link


When I select a link in order to relink it by means of the 'relink handle' and I don't complete the mouse gesture by dragging the point to another valid port the link is removed. I want it to snap back to the original position. How can I achieve this?
Thanks in advance.
PS: I'm running JGo 4.1

Hmmm, this isn’t trivial because at some point internally, a relinking operation is indistinguishable from a linking operation. However, a relinking operation takes place within a transaction and therefore is undoable, so one possibility is to detect the case where a relinking operation has resulted in the deletion of the link, and perform an undo operation.

Relinking starts with the JGoView.startReLink method and ends with the JGoView.reLink method. if a link is deleted between these 2 methods, try performing the undo operation.

It’s easiest to override JGoView.noReLink to just call JGoView.doCancelMouse().

I have tried calling doCancelMouse() within noReLink() yesterday while waiting for a reply, it does indeed restore the link between the two original ports (as it is in fact the ‘cancel’ operation which is executed), but it recalculates the stroke and all the points on it. I want the link to be exactly the same - including all the original stroke points and positioning.

I'm going to try the undo suggestion in reply no1 and also play with storing of the original stroke points and so forth. Is storing of the stroke and reapplying it a feasible thing to do?

Currently my application does not support undo/redo. I tried the undo suggestion, but I was too lazy to override all the copyOldValueForUndo, copyNewValueForRedo and changeValue for all of my custom JGoObjects. Alternatively I override JGoView.startReLink() so that it stores the link’s strokepoints and then within JGoView.noReLink() I call doCancelMouse(), which ends the transaction and restores the link’s orginal ports after which I restore the link’s stroke points with the JGoStroke.setPoints(Vector) method. So far this is working nicely for me Smile