josmas / openwonderland

Automatically exported from code.google.com/p/openwonderland
GNU General Public License v2.0
3 stars 5 forks source link

Action binding solution #247

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Binding actions such as key presses and mouse clicks should be easy to do from 
modules, but also all modules should be aware of other bindings in case of 
collisions. This would likely be primarily for client event listeners (versus 
at the cell/component level). The idea is to have a configurable and accessible 
means to control action bindings.

Example Problem:
Module A binds the "c" key to a "cycle camera" routine. Module B wants to bind 
the "c" key to "avatar clap gesture". A module should be able to work around 
this if they like. For example, Module B could unbind (not remove) Module A's 
routine and rebind it later if needed.

Using purely the example of wanting to toggle cameras, One such mock could be:
ActionBindingManager.INSTANCE.addAction("Toggle Cameras", myEventListener);
ActionBindingManager.INSTANCE.bindAction(KEY,"c", "Toggle Cameras");
ActionBindingManager.INSTANCE.bindKey("c", "Toggle Cameras");
ActionBindingManager.INSTANCE.bindAction(MOUSE, "left", "Toggle Cameras");
ActionBindingManager.INSTANCE.bindMouse("left", "Toggle Cameras");

another possible mock [using annotations] could be:

@KeyAction
public class ToggleCameraAction implements KeyActionSPI {
    public String getKeyTrigger() {
        return "c";
    }

    public String getActionName() {
        return "Toggle Cameras";
    }

    public void actionPerformed(ActionEvent event) {
      //toggle cameras somehow
    }

}

or

@Action
public class ToggleCameraAction implements ActionSPI {
   public String getTrigger() {
      return "c";
   }

   public ActionType getActionType() {
      return KEY;
   }

   public String getTriggerName() {
      return "Toggle Cameras";
   }

   public void actionPerformed(ActionEvent event) {
      //toggle cameras somehow
   }

}

Original issue reported on code.google.com by pympno...@gmail.com on 5 Mar 2012 at 7:52

GoogleCodeExporter commented 9 years ago
Proposal infrastructure attached. Implementation different than above design. 
Please review.

Original comment by pympno...@gmail.com on 1 May 2012 at 2:39

Attachments:

GoogleCodeExporter commented 9 years ago
New proposal attached. I like this new implementation better. It favors 
KeyStrokes over a complicated hierarchy traversal. Diff also includes changes 
to MainFrameImpl to remove ESC and "c" bindings from the frame input and action 
maps.

Example bindings for ESC and "c" can be found in the recently committed 
KeyBindings-Example module found in openwonderland-modules/unstable

Original comment by pympno...@gmail.com on 8 May 2012 at 5:13

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by pympno...@gmail.com on 25 Oct 2012 at 2:23