Changing default link creation behavior

JGoBasicNodes have the default functionality of being linkable by clicking on one node and dragging to another node. How can I change this functionality so that JGoLabeledLinks are created instead?

Edit: While on this topic, I need to modify the implementation of this default functionality to use a command interface to support my own custom undo and redo. Is this possible to do without hacking JGo?

Sure, you can do both by overriding JGoView.newLink. Take a look at the definition (and documentation) to see what it normally does.

That was easy. Thanks Walter.

Hi Walter,

Well, it turns out that subclassing JGoView and overriding newLink is reaaally ugly design wise - the sublcass needs to be aware of the editing domain in order to execute editing commands. That’s all a bunch of mumbo jumbo to you, but that’s the point - it means it’s no longer a ‘pure’ widget, in that I can’t drop it into another app without bringing the entire editor framework with it.

Is there another way?

Well, you can delegate the responsibility to another class if you want, but fundamentally it’s the JComponent (control) that needs to respond to mouse actions and decide what to do, including modifying the model.
I suppose you could make that parameterized, so that you can replace the functionality by setting the “factory” for creating links.

Hi Walter,

Link creation works fine, thank you.

I want to do the same thing now with selection moving - i.e. implement it using my command stack. I overrode moveSelection but this creates a new command every mouse update (so hundreds of commands for a simple node drag). Where should I be looking to override?

I’m not sure what you mean, but if you want to run some code after the user has moved the selection, I would not override JGoView.moveSelection but instead implement a JGoViewListener. Look for the JGoViewEvent.SELECTION_MOVED hint.