diff --git a/src/java/com/threerings/miso/client/IsoSceneViewModel.java b/src/java/com/threerings/miso/client/IsoSceneViewModel.java index 9793ac06b..24c9f4a57 100644 --- a/src/java/com/threerings/miso/client/IsoSceneViewModel.java +++ b/src/java/com/threerings/miso/client/IsoSceneViewModel.java @@ -1,10 +1,11 @@ // -// $Id: IsoSceneViewModel.java,v 1.14 2001/10/17 22:21:22 shaper Exp $ +// $Id: IsoSceneViewModel.java,v 1.15 2001/10/18 21:01:44 shaper Exp $ package com.threerings.miso.scene; import java.awt.Dimension; import java.awt.Point; +import java.util.ArrayList; import com.samskivert.util.Config; @@ -109,6 +110,31 @@ public class IsoSceneViewModel showPaths = config.getValue(SHOW_PATHS_KEY, DEF_SHOW_PATHS); } + /** + * Add an iso scene view model listener. + * + * @param l the listener. + */ + public void addListener (IsoSceneViewModelListener l) + { + if (!_listeners.contains(l)) { + _listeners.add(l); + } + } + + /** + * Notify all model listeners that the iso scene view model has + * changed. + */ + protected void notifyListeners (int event) + { + int size = _listeners.size(); + for (int ii = 0; ii < size; ii++) { + ((IsoSceneViewModelListener)_listeners.get(ii)). + viewChanged(event); + } + } + /** * Returns whether the given tile coordinate is a valid coordinate * within the scene. @@ -133,49 +159,21 @@ public class IsoSceneViewModel } /** - * Return whether locations in the scene are currently drawn. + * Toggle whether locations in the scene should be drawn. */ - public boolean getShowLocations () + public void toggleShowLocations () { - return showLocs; + showLocs = !showLocs; + notifyListeners(IsoSceneViewModelListener.SHOW_LOCATIONS_CHANGED); } /** - * Set whether locations in the scene should be drawn. - * - * @param show whether to show locations. + * Toggle whether coordinates should be drawn for each tile. */ - public void setShowLocations (boolean show) + public void toggleShowCoordinates () { - showLocs = show; - } - - /** - * Return whether coordinates are currently drawn for each tile. - */ - public boolean getShowCoordinates () - { - return showCoords; - } - - /** - * Set whether coordinates should be drawn for each tile. - * - * @param show whether to show coordinates. - */ - public void setShowCoordinates (boolean show) - { - showCoords = show; - } - - /** - * Set whether sprite paths should be drawn. - * - * @param show whether to show paths. - */ - public void setShowSpritePaths (boolean show) - { - showPaths = show; + showCoords = !showCoords; + notifyListeners(IsoSceneViewModelListener.SHOW_COORDINATES_CHANGED); } /** @@ -297,4 +295,7 @@ public class IsoSceneViewModel protected static final boolean DEF_SHOW_COORDS = false; protected static final boolean DEF_SHOW_LOCS = false; protected static final boolean DEF_SHOW_PATHS = false; + + /** The model listeners. */ + protected ArrayList _listeners = new ArrayList(); } diff --git a/src/java/com/threerings/miso/client/IsoSceneViewModelListener.java b/src/java/com/threerings/miso/client/IsoSceneViewModelListener.java new file mode 100644 index 000000000..8c465883e --- /dev/null +++ b/src/java/com/threerings/miso/client/IsoSceneViewModelListener.java @@ -0,0 +1,23 @@ +// +// $Id: IsoSceneViewModelListener.java,v 1.1 2001/10/18 21:01:44 shaper Exp $ + +package com.threerings.miso.scene; + +/** + * The iso scene view model listener interface should be implemented + * by classes that would like to be notified when the iso scene view + * model is changed. + * + * @see IsoSceneViewModel + */ +public interface IsoSceneViewModelListener +{ + /** + * Called by the {@link IsoSceneView} when the model is changed. + */ + public void viewChanged (int event); + + /** Notification event constants. */ + public static final int SHOW_LOCATIONS_CHANGED = 0; + public static final int SHOW_COORDINATES_CHANGED = 1; +} diff --git a/src/java/com/threerings/miso/client/SceneViewPanel.java b/src/java/com/threerings/miso/client/SceneViewPanel.java index 08bb8aacf..7e00aab01 100644 --- a/src/java/com/threerings/miso/client/SceneViewPanel.java +++ b/src/java/com/threerings/miso/client/SceneViewPanel.java @@ -1,5 +1,5 @@ // -// $Id: SceneViewPanel.java,v 1.16 2001/10/17 22:21:22 shaper Exp $ +// $Id: SceneViewPanel.java,v 1.17 2001/10/18 21:01:44 shaper Exp $ package com.threerings.miso.scene; @@ -18,6 +18,7 @@ import com.threerings.miso.util.MisoUtil; * UI events. */ public class SceneViewPanel extends AnimatedPanel + implements IsoSceneViewModelListener { /** * Constructs the scene view panel. @@ -25,10 +26,22 @@ public class SceneViewPanel extends AnimatedPanel public SceneViewPanel (Config config, SpriteManager spritemgr) { // create the data model for the scene view - _smodel = new IsoSceneViewModel(config); + _scenemodel = new IsoSceneViewModel(config); + + // listen to the iso scene view model to receive notice when + // location or coordinate display is toggled + _scenemodel.addListener(this); // create the scene view - _view = newSceneView(spritemgr, _smodel); + _view = newSceneView(spritemgr, _scenemodel); + } + + /** + * Gets the iso scene view model associated with this panel. + */ + public IsoSceneViewModel getModel () + { + return _scenemodel; } /** @@ -75,13 +88,20 @@ public class SceneViewPanel extends AnimatedPanel */ public Dimension getPreferredSize () { - Dimension psize = (_smodel == null) ? - super.getPreferredSize() : _smodel.bounds; + Dimension psize = (_scenemodel == null) ? + super.getPreferredSize() : _scenemodel.bounds; return psize; } + // documentation inherited + public void viewChanged (int event) + { + // update the scene view display + repaint(); + } + /** The scene view data model. */ - protected IsoSceneViewModel _smodel; + protected IsoSceneViewModel _scenemodel; /** The scene view we're managing. */ protected SceneView _view;