Control Key + Move Selection


#1

I have a class that extends JGoView and we want to select the objects using a mouse and a control key and move them to a new location. How can we do this?
Thanks in advance.


#2

You can override JGoView.onKeyEvent to look for the particular keystrokes that you want to interpret as commands. Most of the example applications do this, if they define a subclass of JGoView. The ones that don’t define a subclass of JGoView just define a keyPressed event handler for the JGoView.
Take a look at ProcessView.java in the Processor example. It looks for arrow keys and moves the selection by calling JGoView.doMoveSelection. Or you can implement this more generally by calling JGoView.moveSelection inside a transaction.


#3

If I marquee select and use the KeyStrokes(up/down/left/right arrow keys), I am able to move the selected objects. Having a problem in two instances

  1. Marquee selecting the objects and dragging using a mouse
  2. Select multiple objects using a Control key + Mouse and then Drag …
    I did try overriding the onMouseDown/onMouseUp events … but not able to select multiple objects using a ctrl key and mouse

    I am new to JGo API so it would be really helpful if you can send across some sample code or throw some insight into the methods that have to be overridden
    Thanks
    Gautami

#4
  1. This is the default behavior, so you shouldn’t need to do anything to get this, and perhaps your overrides of onMouseDown/onMouseUp broke it.
  2. This too is default behavior. I suggest you comment out the onMouseDown/onMouseUp overrides and related functionality.
    To get the selected object movement you want using keyboard events, you just need to implement a keyPressed event handler for the JGoView, or equivalently, an override of JGoView.onKeyEvent.