Renamed ControllerEvent to CommandEvent.

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4281 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Ray Greenwell
2006-07-20 02:14:14 +00:00
parent 19219bb1a3
commit f1f6b3bdb2
5 changed files with 33 additions and 17 deletions
@@ -27,8 +27,6 @@ import com.threerings.crowd.data.PlaceConfig;
import com.threerings.crowd.data.PlaceObject; import com.threerings.crowd.data.PlaceObject;
import com.threerings.crowd.util.CrowdContext; import com.threerings.crowd.util.CrowdContext;
import com.threerings.events.ControllerEvent;
/** /**
* Controls the user interface that is used to display a place. When the * Controls the user interface that is used to display a place. When the
* client moves to a new place, the appropriate place controller is * client moves to a new place, the appropriate place controller is
@@ -4,7 +4,7 @@ import flash.events.MouseEvent;
import mx.controls.Button; import mx.controls.Button;
import com.threerings.events.ControllerEvent; import com.threerings.mx.events.CommandEvent;
/** /**
* A command button simply dispatches a Controller command (with an optional * A command button simply dispatches a Controller command (with an optional
@@ -37,7 +37,7 @@ public class CommandButton extends Button
// stop the click event // stop the click event
event.stopImmediatePropagation(); event.stopImmediatePropagation();
// dispatch the command event // dispatch the command event
dispatchEvent(new ControllerEvent(_cmd, _arg)); dispatchEvent(new CommandEvent(_cmd, _arg));
} }
} }
@@ -1,16 +1,16 @@
package com.threerings.events { package com.threerings.mx.events {
import flash.events.Event; import flash.events.Event;
public class ControllerEvent extends Event public class CommandEvent extends Event
{ {
/** The event type for all controller events. */ /** The event type for all controller events. */
public static const TYPE :String = "controller"; public static const TYPE :String = "commandEvt";
public var command :String; public var command :String;
public var arg :Object; public var arg :Object;
public function ControllerEvent (command :String, arg :Object = null) public function CommandEvent (command :String, arg :Object = null)
{ {
super(TYPE, true); super(TYPE, true);
this.command = command; this.command = command;
@@ -19,12 +19,12 @@ public class ControllerEvent extends Event
override public function clone () :Event override public function clone () :Event
{ {
return new ControllerEvent(command, arg); return new CommandEvent(command, arg);
} }
override public function toString () :String override public function toString () :String
{ {
return "ControllerEvent[" + command + " (" + arg + ")]"; return "CommandEvent[" + command + " (" + arg + ")]";
} }
} }
} }
+23 -5
View File
@@ -2,7 +2,7 @@ package com.threerings.util {
import flash.events.IEventDispatcher; import flash.events.IEventDispatcher;
import com.threerings.events.ControllerEvent; import com.threerings.mx.events.CommandEvent;
public class Controller public class Controller
{ {
@@ -13,12 +13,12 @@ public class Controller
{ {
if (_panel != null) { if (_panel != null) {
_panel.removeEventListener( _panel.removeEventListener(
ControllerEvent.TYPE, handleControllerEvent); CommandEvent.TYPE, handleCommandEvent);
} }
_panel = panel; _panel = panel;
if (_panel != null) { if (_panel != null) {
_panel.addEventListener( _panel.addEventListener(
ControllerEvent.TYPE, handleControllerEvent); CommandEvent.TYPE, handleCommandEvent);
} }
} }
@@ -32,7 +32,25 @@ public class Controller
*/ */
public function handleAction (cmd :String, arg :Object) :Boolean public function handleAction (cmd :String, arg :Object) :Boolean
{ {
// TODO: This warning should really be inside the ControllerEvent // fall back to a method named the cmd
try {
var fn :Function = (this["handle" + cmd] as Function);
if (fn != null) {
try {
fn(arg);
} catch (e :Error) {
Log.getLog(this).warning("Error handling controller " +
"command [error=" + e + ", cmd=" + cmd +
", arg=" + arg + "].");
}
// we "handled" the event, even if it threw an error
return true;
}
} catch (e :Error) {
// suppress, and fall through
}
// TODO: This warning should really be inside the CommandEvent
// somewhere, and only generated if the event never gets cancelled // somewhere, and only generated if the event never gets cancelled
Log.getLog(this).warning("Unhandled controller command " + Log.getLog(this).warning("Unhandled controller command " +
"[cmd=" + cmd + ", arg=" + arg + "]."); "[cmd=" + cmd + ", arg=" + arg + "].");
@@ -43,7 +61,7 @@ public class Controller
* Private function to handle the controller event and call * Private function to handle the controller event and call
* handleAction. * handleAction.
*/ */
private function handleControllerEvent (event :ControllerEvent) :void private function handleCommandEvent (event :CommandEvent) :void
{ {
if (handleAction(event.command, event.arg)) { if (handleAction(event.command, event.arg)) {
// if we handle the event, stop it from moving outward to another // if we handle the event, stop it from moving outward to another
+2 -2
View File
@@ -3,7 +3,7 @@ package com.threerings.util {
import flash.ui.ContextMenuItem; import flash.ui.ContextMenuItem;
import flash.events.ContextMenuEvent; import flash.events.ContextMenuEvent;
import com.threerings.events.ControllerEvent; import com.threerings.mx.events.CommandEvent;
/** /**
*/ */
@@ -21,7 +21,7 @@ public class MenuUtil
new ContextMenuItem(caption, separatorBefore, enabled, visible); new ContextMenuItem(caption, separatorBefore, enabled, visible);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT,
function (event :ContextMenuEvent) :void { function (event :ContextMenuEvent) :void {
event.mouseTarget.dispatchEvent(new ControllerEvent(cmd, arg)); event.mouseTarget.dispatchEvent(new CommandEvent(cmd, arg));
}); });
return item; return item;
} }