I love to make vast, sweeping changes. Now the place services incorporate

a place config object which is used to determine the classes of the place
manager and the (newly added) place controller.

Moved PlaceView and PlaceViewUtil into cocktail.party.client from
cocktail.party.util because the controller and the UI (in very abstract
form) are now part of the place services.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@399 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2001-10-05 23:57:26 +00:00
parent 7636e33a7c
commit 63191ec610
9 changed files with 327 additions and 57 deletions
@@ -1,5 +1,5 @@
//
// $Id: LocationDirector.java,v 1.9 2001/10/01 22:14:55 mdb Exp $
// $Id: LocationDirector.java,v 1.10 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.client;
@@ -10,8 +10,7 @@ import com.threerings.cocktail.cher.client.*;
import com.threerings.cocktail.cher.dobj.*;
import com.threerings.cocktail.party.Log;
import com.threerings.cocktail.party.data.BodyObject;
import com.threerings.cocktail.party.data.PlaceObject;
import com.threerings.cocktail.party.data.*;
import com.threerings.cocktail.party.util.PartyContext;
/**
@@ -127,13 +126,27 @@ public class LocationDirector
* effected.
*
* @param placeId the place oid of our new location.
* @param config the configuration information for the new place.
*/
protected void didMoveTo (int placeId)
protected void didMoveTo (int placeId, PlaceConfig config)
{
DObjectManager omgr = _ctx.getDObjectManager();
// unsubscribe from our old place object
// do some cleaning up if we were previously in a place
if (_plobj != null) {
// let the old controller know that things are going away
if (_controller != null) {
try {
_controller.didLeavePlace(_plobj);
} catch (Exception e) {
Log.warning("Place controller choked in " +
"didLeavePlace [plobj=" + _plobj + "].");
Log.logStackTrace(e);
}
_controller = null;
}
// unsubscribe from our old place object
omgr.unsubscribeFromObject(_plobj.getOid(), this);
_plobj = null;
}
@@ -142,6 +155,18 @@ public class LocationDirector
_previousPlaceId = _placeId;
_placeId = placeId;
try {
// start up a new place controller to manage the new place
Class cclass = config.getControllerClass();
_controller = (PlaceController)cclass.newInstance();
_controller.init(_ctx, config);
} catch (Exception e) {
Log.warning("Error creating or initializing place controller " +
"[config=" + config + "].");
Log.logStackTrace(e);
}
// subscribe to our new place object to complete the move
omgr.subscribeToObject(_placeId, this);
}
@@ -217,10 +242,10 @@ public class LocationDirector
/**
* Called in response to a successful <code>moveTo</code> request.
*/
public void handleMoveSucceeded (int invid)
public void handleMoveSucceeded (int invid, PlaceConfig config)
{
// handle the successful move
didMoveTo(_pendingPlaceId);
didMoveTo(_pendingPlaceId, config);
// and clear out the tracked pending oid
_pendingPlaceId = -1;
@@ -244,6 +269,15 @@ public class LocationDirector
// yay, we have our new place object
_plobj = (PlaceObject)object;
// let the place controller know that we're ready to roll
try {
_controller.willEnterPlace(_plobj);
} catch (Exception e) {
Log.warning("Controller choked in willEnterPlace " +
"[place=" + _plobj + "].");
Log.logStackTrace(e);
}
// let our observers know that all is well on the western front
for (int i = 0; i < _observers.size(); i++) {
LocationObserver obs = (LocationObserver)_observers.get(i);
@@ -265,6 +299,11 @@ public class LocationDirector
// let the kids know shit be fucked
notifyFailure(placeId, "m.unable_to_fetch_place_object");
// we need to sort out what to do about the half-initialized place
// controller. presently we punt and hope that calling
// didLeavePlace() without ever having called willEnterPlace()
// does whatever's necessary
// try to return to our previous location
recoverFailedMove(placeId);
}
@@ -313,6 +352,9 @@ public class LocationDirector
/** The place object that we currently occupy. */
protected PlaceObject _plobj;
/** The place controller in effect for our current place. */
protected PlaceController _controller;
/**
* The oid of the place for which we have an outstanding moveTo
* request, or -1 if we have no outstanding request.
@@ -0,0 +1,104 @@
//
// $Id: PlaceController.java,v 1.1 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.client;
import java.awt.event.ActionEvent;
import com.samskivert.swing.Controller;
import com.threerings.cocktail.party.data.PlaceConfig;
import com.threerings.cocktail.party.data.PlaceObject;
import com.threerings.cocktail.party.util.PartyContext;
/**
* Controls the user interface that is used to display a place. When the
* client moves to a new place, the appropriate place controller is
* constructed and requested to create and display the appopriate user
* interface for that place.
*/
public abstract class PlaceController
extends Controller
{
/**
* Initializes this place controller with a reference to the context
* that they can use to access client services and to the
* configuration record for this place. The controller should create
* as much of its user interface that it can without having access to
* the place object because this will be invoked in parallel with the
* fetching of the place object. When the place object is obtained,
* the controller will be notified and it can then finish the user
* interface configuration and put the user interface into operation.
*
* @param ctx the client context.
* @param config the place configuration for this place.
*/
public void init (PartyContext ctx, PlaceConfig config)
{
// keep these around
_ctx = ctx;
_config = config;
// create our user interface
_view = createPlaceView();
}
/**
* Creates the user interface that will be used to display this place.
* The view instance returned will later be configured with the place
* object, once it becomes available.
*/
protected abstract PlaceView createPlaceView ();
/**
* This is called by the location director once the place object has
* been fetched. The place controller will dispatch the place object
* to the user interface hierarchy via {@link
* PlaceViewUtil.dispatchWillEnterPlace}. Derived classes can override
* this and perform any other starting up that they need to do
*/
public void willEnterPlace (PlaceObject plobj)
{
// let the UI hierarchy know that we've got our place
if (_view != null ) {
PlaceViewUtil.dispatchWillEnterPlace(_view, plobj);
}
}
/**
* This is called by the location director when we are leaving this
* place and need to clean up after ourselves and shutdown. Derived
* classes should override this method (being sure to call
* <code>super.didLeavePlace</code>) and perform any necessary
* cleanup.
*/
public void didLeavePlace (PlaceObject plobj)
{
// let the UI hierarchy know that we're outta here
if (_view != null ) {
PlaceViewUtil.dispatchDidLeavePlace(_view, plobj);
}
}
/**
* Handles basic place controller action events. Derived classes
* should be sure to call <code>super.handleAction</code> for events
* they don't specifically handle.
*/
public boolean handleAction (ActionEvent action)
{
return false;
}
/** A reference to the active client context. */
protected PartyContext _ctx;
/** A reference to our place configuration. */
protected PlaceConfig _config;
/** A reference to the place object for which we're controlling a user
* interface. */
protected PlaceObject _plobj;
/** A reference to the root user interface component. */
protected PlaceView _view;
}
@@ -1,8 +0,0 @@
//
// $Id: PlaceDirector.java,v 1.1 2001/07/20 20:07:37 mdb Exp $
package com.threerings.cocktail.party.client;
public class PlaceDirector
{
}
@@ -1,7 +1,7 @@
//
// $Id: PlaceView.java,v 1.2 2001/10/04 22:47:48 mdb Exp $
// $Id: PlaceView.java,v 1.3 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.util;
package com.threerings.cocktail.party.client;
import com.threerings.cocktail.party.data.PlaceObject;
@@ -1,9 +1,8 @@
//
// $Id: PlaceViewUtil.java,v 1.1 2001/10/04 20:02:49 mdb Exp $
// $Id: PlaceViewUtil.java,v 1.2 2001/10/05 23:57:26 mdb Exp $
package com.threerings.cocktail.party.util;
package com.threerings.cocktail.party.client;
import java.awt.Component;
import java.awt.Container;
import com.threerings.cocktail.party.Log;
@@ -27,7 +26,7 @@ public class PlaceViewUtil
* @param plobj the place object that is about to be entered.
*/
public static void dispatchWillEnterPlace (
Component root, PlaceObject plobj)
Object root, PlaceObject plobj)
{
// dispatch the call on this component if it implements PlaceView
if (root instanceof PlaceView) {
@@ -60,7 +59,7 @@ public class PlaceViewUtil
* @param plobj the place object that is about to be entered.
*/
public static void dispatchDidLeavePlace (
Component root, PlaceObject plobj)
Object root, PlaceObject plobj)
{
// dispatch the call on this component if it implements PlaceView
if (root instanceof PlaceView) {