diff --git a/src/java/com/threerings/nodemap/DuplicateEdgeException.java b/src/java/com/threerings/nodemap/DuplicateEdgeException.java deleted file mode 100644 index 62496735c..000000000 --- a/src/java/com/threerings/nodemap/DuplicateEdgeException.java +++ /dev/null @@ -1,34 +0,0 @@ -// -// $Id: DuplicateEdgeException.java,v 1.2 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -/** - * Thrown when an action is attempted on an edge that is already - * present in the involved node. - */ -public class DuplicateEdgeException extends NodeMapException -{ - public DuplicateEdgeException () - { - super("error.duplicate_edge"); - } -} diff --git a/src/java/com/threerings/nodemap/DuplicateNodeException.java b/src/java/com/threerings/nodemap/DuplicateNodeException.java deleted file mode 100644 index 7c24852da..000000000 --- a/src/java/com/threerings/nodemap/DuplicateNodeException.java +++ /dev/null @@ -1,34 +0,0 @@ -// -// $Id: DuplicateNodeException.java,v 1.2 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -/** - * Thrown when an action is attempted on a node that is already - * present in the node map. - */ -public class DuplicateNodeException extends NodeMapException -{ - public DuplicateNodeException () - { - super("error.duplicate_node"); - } -} diff --git a/src/java/com/threerings/nodemap/Edge.java b/src/java/com/threerings/nodemap/Edge.java deleted file mode 100644 index 450d29782..000000000 --- a/src/java/com/threerings/nodemap/Edge.java +++ /dev/null @@ -1,102 +0,0 @@ -// -// $Id: Edge.java,v 1.4 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -import java.awt.Color; -import java.awt.Graphics; -import java.awt.Stroke; - -/** - * The edge class represents an edge connecting two nodes. - */ -public abstract class Edge -{ - /** The source node. */ - public Node src; - - /** The destination node. */ - public Node dst; - - /** - * Construct an edge object connecting the given nodes. - * - * @param src the source node. - * @param dst the destination node. - */ - public Edge (Node src, Node dst) - { - this.src = src; - this.dst = dst; - } - - /** - * Paint the edge to the given graphics context. - * - * @param g the graphics context. - */ - public abstract void paint (Graphics g); - - /** - * Sets the color used to render the edge, or null (the - * default) to use the current graphics context color. - */ - public void setColor (Color color) - { - _color = color; - } - - /** - * Sets the stroke used to render the edge, or null (the - * default) to use the current graphics context stroke. - */ - public void setStroke (Stroke stroke) - { - _stroke = stroke; - } - - /** - * Return a string representation of this edge. - */ - public String toString () - { - StringBuffer buf = new StringBuffer("["); - toString(buf); - return buf.append("]").toString(); - } - - /** - * This should be overridden by derived classes (which should be sure - * to call super.toString()) to append the derived class - * specific event information to the string buffer. - */ - public void toString (StringBuffer buf) - { - buf.append("src=").append(src); - buf.append(", dst=").append(dst); - } - - /** The edge color. */ - protected Color _color; - - /** The edge stroke. */ - protected Stroke _stroke; -} diff --git a/src/java/com/threerings/nodemap/LayoutManager.java b/src/java/com/threerings/nodemap/LayoutManager.java deleted file mode 100644 index 8f8da8308..000000000 --- a/src/java/com/threerings/nodemap/LayoutManager.java +++ /dev/null @@ -1,42 +0,0 @@ -// -// $Id: LayoutManager.java,v 1.3 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -import java.util.List; - -/** - * The layout manager class provides an interface that lays out nodes - * in a node map via some preordained desirable methodology. - */ -public interface LayoutManager -{ - /** - * Lay out the nodes in the list in the fashion dictated by this - * particular layout manager. The node positions are updated via - * {@link Node#setLocation} such that subsequent rendering of the - * nodes will place them in appropriate positions. - * - * @param root the root node for the graph. - * @param nodes the list of nodes. - */ - public void layout (Node root, List nodes); -} diff --git a/src/java/com/threerings/nodemap/Log.java b/src/java/com/threerings/nodemap/Log.java deleted file mode 100644 index 807a677d3..000000000 --- a/src/java/com/threerings/nodemap/Log.java +++ /dev/null @@ -1,56 +0,0 @@ -// -// $Id: Log.java,v 1.2 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -/** - * A placeholder class that contains a reference to the log object used by - * the nodemap package. - */ -public class Log -{ - public static com.samskivert.util.Log log = - new com.samskivert.util.Log("nodemap"); - - /** Convenience function. */ - public static void debug (String message) - { - log.debug(message); - } - - /** Convenience function. */ - public static void info (String message) - { - log.info(message); - } - - /** Convenience function. */ - public static void warning (String message) - { - log.warning(message); - } - - /** Convenience function. */ - public static void logStackTrace (Throwable t) - { - log.logStackTrace(com.samskivert.util.Log.WARNING, t); - } -} diff --git a/src/java/com/threerings/nodemap/NoSuchNodeException.java b/src/java/com/threerings/nodemap/NoSuchNodeException.java deleted file mode 100644 index 9a4c94a44..000000000 --- a/src/java/com/threerings/nodemap/NoSuchNodeException.java +++ /dev/null @@ -1,33 +0,0 @@ -// -// $Id: NoSuchNodeException.java,v 1.2 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -/** - * Thrown when a node cannot be found in the node map. - */ -public class NoSuchNodeException extends NodeMapException -{ - public NoSuchNodeException () - { - super("error.no_such_node"); - } -} diff --git a/src/java/com/threerings/nodemap/Node.java b/src/java/com/threerings/nodemap/Node.java deleted file mode 100644 index 97a399eb6..000000000 --- a/src/java/com/threerings/nodemap/Node.java +++ /dev/null @@ -1,239 +0,0 @@ -// -// $Id: Node.java,v 1.8 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.FontMetrics; -import java.awt.Graphics; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; - -import com.samskivert.swing.ToolTipProvider; -import com.samskivert.swing.util.SwingUtil; - -/** - * The node class represents a single node in a directed graph of nodes. - * - * @see NodeMap - */ -public abstract class Node implements ToolTipProvider -{ - /** - * Construct a node with the given attributes. - * - * @param name the node name. - * @param width the width in pixels. - * @param height the height in pixels. - */ - public Node (String name, int width, int height) - { - _name = name; - _width = width; - _height = height; - - _edges = new ArrayList(); - } - - /** - * Add a connecting edge to this node. An edge may not be - * added to the node more than once. - * - * @param e the new edge. - * - * @exception DuplicateEdgeException thrown if the node already - * contains the given edge. - */ - protected void addEdge (Edge e) throws DuplicateEdgeException - { - // don't allow adding the same edge object twice - if (_edges.contains(e)) { - throw new DuplicateEdgeException(); - } - - // save off the new connecting edge - _edges.add(e); - } - - /** - * Returns an Iterator object that iterates over the - * edges leaving this node. - * - * @return the iterator object. - */ - public Iterator getEdges () - { - return (Collections.unmodifiableList(_edges)).iterator(); - } - - /** - * Returns the node's x position in screen coordinates. - */ - public int getX () - { - return _x; - } - - - /** - * Returns the node's y position in screen coordinates. - */ - public int getY () - { - return _y; - } - - /** - * Set the node's position in pixels. - * - * @param x the x-position. - * @param y the y-position. - */ - public void setLocation (int x, int y) - { - _x = x; - _y = y; - } - - /** - * Returns whether the node contains the given point. - * - * @param x the x-position. - * @param y the y-position. - * - * @return true if the node contains the point, false if not. - */ - public boolean contains (int x, int y) - { - return (x >= _x && x <= (_x + _width) && - y >= _y && y <= (_y + _height)); - } - - /** - * Returns the node width in pixels. - */ - public int getWidth () - { - return _width; - } - - /** - * Returns the node height in pixels. - */ - public int getHeight () - { - return _height; - } - - /** - * Render the node to the given graphics context. - * - * @param g the graphics context. - */ - public abstract void paint (Graphics g); - - /** - * Render the node's connecting edges to the given graphics context. - * - * @param g the graphics context. - */ - public void paintEdges (Graphics g) - { - int size = _edges.size(); - for (int ii = 0; ii < size; ii++) { - ((Edge)_edges.get(ii)).paint(g); - } - } - - /** - * Render a tool tip for this node to the given graphics context. - * By default, the tool tip is a yellow box containing the node's - * name. - * - * @param g the graphics context. - * @param x the x-position at which the tip should be drawn. - * @param y the y-position at which the tip should be drawn. - */ - public void paintToolTip (Graphics g, int x, int y) - { - Dimension d = getToolTipSize(g); - - // draw the yellow box - g.setColor(Color.yellow); - g.fillRect(x, y, d.width, d.height); - g.setColor(Color.black); - g.drawRect(x, y, d.width, d.height); - - // draw the node name - SwingUtil.drawStringCentered(g, _name, x, y, d.width, d.height); - } - - public Dimension getToolTipSize (Graphics g) - { - // calculate tool tip dimensions - FontMetrics fm = g.getFontMetrics(g.getFont()); - - int wid = fm.stringWidth(_name) + 10; - int hei = fm.getAscent() + 4; - - return new Dimension(wid, hei); - } - - /** - * Handle mouse-entered events for this node. - */ - public void handleMouseEntered () { } - - /** - * Handle mouse-exited events for this node. - */ - public void handleMouseExited () { } - - /** - * Handle mouse-clicked events for this node. - * - * @param x the x-coordinate in intra-node pixels. - * @param y the y-coordinate in intra-node pixels. - */ - public void handleMouseClicked (int x, int y) { } - - /** - * Returns a string representation of this node. - */ - public String toString () - { - return _name; - } - - /** The position in pixel coordinates. */ - protected int _x, _y; - - /** The dimensions in pixel coordinates. */ - protected int _width, _height; - - /** The node name. */ - protected String _name; - - /** The edges leaving this node. */ - protected ArrayList _edges; -} diff --git a/src/java/com/threerings/nodemap/NodeMap.java b/src/java/com/threerings/nodemap/NodeMap.java deleted file mode 100644 index 7b8641134..000000000 --- a/src/java/com/threerings/nodemap/NodeMap.java +++ /dev/null @@ -1,407 +0,0 @@ -// -// $Id: NodeMap.java,v 1.10 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -import java.awt.*; -import java.util.*; - -import com.samskivert.swing.ToolTipManager; -import com.samskivert.swing.ToolTipProvider; -import com.samskivert.swing.util.SwingUtil; - -/** - * The node map class represents a directed graph of nodes comprised - * of {@link Node} objects. A user-specifiable {@link LayoutManager} - * is used to lay out the nodes in the graph. - */ -public class NodeMap -{ - /** - * Construct a node map object with the given layout manager. - * - * @param lgmr the layout manager. - */ - public NodeMap (LayoutManager lmgr) - { - _lmgr = lmgr; - _nodes = new ArrayList(); - _dirty = false; - } - - /** - * Returns an iterator over the nodes in this node map. - */ - public Iterator nodes () - { - return _nodes.iterator(); - } - - /** - * Force the nodes in the map to be re-laid out. - */ - public void layout () - { - // do nothing if we have no nodes - if (_nodes.size() == 0) { - return; - } - - // default to using the first node as the root - if (_root == null) { - _root = (Node)_nodes.get(0); - } - - // lay out the nodes - _lmgr.layout(_root, _nodes); - - // update bounding node positions - updateBounds(); - - // note that we're no longer dirty - _dirty = false; - } - - /** - * Returns the coordinates of the supplied node, adjusted into - * absolute coordinates (where 0,0 is the upper left of the node map). - */ - public Point getNodeCoords (Node node) - { - return new Point(node.getX()-_minx, node.getY()-_miny); - } - - /** - * Calculate the bounding rectangle that wholly contains the node - * map. - */ - protected void updateBounds () - { - Iterator iter = _nodes.iterator(); - while (iter.hasNext()) { - Node n = (Node)iter.next(); - int x = n.getX(), y = n.getY(); - int wid = n.getWidth(), hei = n.getHeight(); - - _minx = Math.min(_minx, x); - _maxx = Math.max(_maxx, x + wid); - _miny = Math.min(_miny, y); - _maxy = Math.max(_maxy, y + hei); - } - } - - /** - * Render the node map to the given graphics context. - * - * @param g the graphics context. - */ - public void paint (Graphics g) - { - // lay out the nodes if necessary - if (_dirty) { - layout(); - } - - // translate context to node map origin - g.translate(-_minx, -_miny); - - // render all node edges - int size = _nodes.size(); - for (int ii = 0; ii < size; ii++) { - Node n = (Node)_nodes.get(ii); - n.paintEdges(g); - } - - // render all nodes - for (int ii = 0; ii < size; ii++) { - Node n = (Node)_nodes.get(ii); - n.paint(g); - } - - // highlight the last node entered -// if (_lastnode != null) { -// g.setColor(Color.red); -// int x = _lastnode.getX(), y = _lastnode.getY(); -// int wid = _lastnode.getWidth(), hei = _lastnode.getHeight(); -// g.drawRect(x, y, wid, hei); -// } - - // draw the tool tip, if any - if (_tipper != null) { - // determine proper tool tip placement - Dimension tsize = _tipper.getToolTipSize(g); - Point pos = SwingUtil.fitRectInRect( - new Rectangle(_tipx, _tipy, tsize.width, tsize.height), - getBounds()); - // paint away - _tipper.paintToolTip(g, pos.x, pos.y); - } - - // restore original origin - g.translate(_minx, _miny); - } - - /** - * Add the given node to the node map. A given node may not be - * present in the node map more than once. - * - * @param n the node to add. - * - * @exception DuplicateNodeException thrown if the node already - * exists in the node map. - */ - public void addNode (Node n) throws DuplicateNodeException - { - // don't allow adding a node more than once - if (_nodes.contains(n)) { - throw new DuplicateNodeException(); - } - - // add the node - _nodes.add(n); - _dirty = true; - } - - /** - * Add the given edge to the node. Edges may not be added to a - * node more than once, or to a node that is not present in the - * node map. - * - * @param n the node. - * @param e the edge to add. - * - * @exception NoSuchNodeException thrown if the given node does - * not exist in the node map. - * @exception DuplicateEdgeException thrown if the given node - * already contains the given edge. - */ - public void addEdge (Node n, Edge e) - throws NoSuchNodeException, DuplicateEdgeException - { - // don't allow adding an edge to an unknown node - if (!_nodes.contains(n)) { - throw new NoSuchNodeException(); - } - - // add the edge to the node - n.addEdge(e); - _dirty = true; - } - - /** - * Set the root node for the node map. The given node must be - * present in the node map. - * - * @param n the root node. - * - * @exception NoSuchNodeException thrown if the given node does - * not exist in the node map. - */ - public void setRootNode (Node n) throws NoSuchNodeException - { - if (!_nodes.contains(n)) { - throw new NoSuchNodeException(); - } - - _root = n; - _dirty = true; - } - - /** - * Returns the dimensions of the node map in pixels. - */ - public Dimension getSize () - { - // lay out the nodes if necessary - if (_dirty) { - layout(); - } - - return new Dimension(_maxx - _minx, _maxy - _miny); - } - - /** - * Returns the bounding rectangle of the node map. - */ - public Rectangle getBounds () - { - Dimension size = getSize(); - return new Rectangle(_minx, _miny, size.width, size.height); - } - - /** - * Handle mouse-moved events passed on by the containing panel. - * Inform any affected nodes of mouse-entered and mouse-exited - * events. - * - * @param x the mouse x-coordinate. - * @param y the mouse y-coordinate. - */ - public void handleMouseMoved (int x, int y) - { - Node enternode = null; - - // translate coordinates to node map origin - x += _minx; - y += _miny; - - // tell the tip manager that the mouse moved - if (_tipmgr != null) { - _tipmgr.handleMouseMoved(x, y); - } - - // check whether we've entered a node - int size = _nodes.size(); - for (int ii = 0; ii < size; ii++) { - Node n = (Node)_nodes.get(ii); - - if (n.contains(x, y)) { - - // bail if we're in the same node we were in last - if (_lastnode == n) return; - - // note that we're entering this node - enternode = n; - - break; - } - } - - // exit the last node, if any - if (_lastnode != null) { - _lastnode.handleMouseExited(); - - if (_tipmgr != null) { - _tipmgr.handleMouseExited(); - } - } - - // enter the new node, if any - if (enternode != null) { - enternode.handleMouseEntered(); - - if (_tipmgr != null) { - _tipmgr.handleMouseEntered(enternode, x, y); - } - } - - // update the last node entered - _lastnode = enternode; - } - - /** - * Handle mouse-clicked events passed on by the containing panel. - * Inform any affected nodes of mouse-clicked events. - * - * @param x the mouse x-coordinate. - * @param y the mouse y-coordinate. - */ - public void handleMouseClicked (int x, int y) - { - // translate coordinates to node map origin - x += _minx; - y += _miny; - - int size = _nodes.size(); - for (int ii = 0; ii < size; ii++) { - Node n = (Node)_nodes.get(ii); - - if (n.contains(x, y)) { - - // inform the node of the mouse click, with - // coordinates translated to suit node interior - int nx = n.getX(), ny = n.getY(); - n.handleMouseClicked(x - nx, y - ny); - - // let the tool tip manager know about the click - if (_tipmgr != null) { - _tipmgr.handleMouseClicked(n); - } - - // nodes can't overlap for now, so we're done - return; - } - } - } - - /** - * Handle mouse-exited events passed on by the containing panel. - * Inform the tool tip manager that we've exited any node we may - * have been within. - */ - public void handleMouseExited () - { - handleMouseMoved(-1, -1); - } - - /** - * Set the tool tip provider for display when the node map is - * rendered. - * - * @param tipper the tool tip provider - * @param x the last mouse x-position. - * @param y the last mouse y-position. - */ - public void setToolTipProvider (ToolTipProvider tipper, int x, int y) - { - _tipper = tipper; - _tipx = x; - _tipy = y; - } - - /** - * Set the tool tip manager that the node map should notify of - * node enter, exit, and clicked events. - * - * @param tipmgr the tool tip manager. - */ - public void setToolTipManager (ToolTipManager tipmgr) - { - _tipmgr = tipmgr; - } - - /** The current tool tip provider. */ - protected ToolTipProvider _tipper; - - /** The mouse position for calculating tool tip display position. */ - protected int _tipx, _tipy; - - /** The tool tip manager. */ - protected ToolTipManager _tipmgr; - - /** The layout manager. */ - protected LayoutManager _lmgr; - - /** The nodes in the node map. */ - protected ArrayList _nodes; - - /** The root node. */ - protected Node _root; - - /** The bounding box coordinates. */ - protected int _minx, _maxx, _miny, _maxy; - - /** The last node the mouse entered. */ - protected Node _lastnode; - - /** Whether the node map needs to be laid out. */ - protected boolean _dirty; -} diff --git a/src/java/com/threerings/nodemap/NodeMapException.java b/src/java/com/threerings/nodemap/NodeMapException.java deleted file mode 100644 index 0d04d3500..000000000 --- a/src/java/com/threerings/nodemap/NodeMapException.java +++ /dev/null @@ -1,34 +0,0 @@ -// -// $Id: NodeMapException.java,v 1.2 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -/** - * Thrown when an error occurs while performing certain activities - * involving a node map object. - */ -public class NodeMapException extends Exception -{ - public NodeMapException (String message) - { - super(message); - } -} diff --git a/src/java/com/threerings/nodemap/NodeMapPanel.java b/src/java/com/threerings/nodemap/NodeMapPanel.java deleted file mode 100644 index 90abf5a74..000000000 --- a/src/java/com/threerings/nodemap/NodeMapPanel.java +++ /dev/null @@ -1,188 +0,0 @@ -// -// $Id: NodeMapPanel.java,v 1.10 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap; - -import java.awt.*; -import java.awt.event.*; -import javax.swing.*; - -import com.samskivert.swing.ToolTipManager; -import com.samskivert.swing.ToolTipObserver; -import com.samskivert.swing.ToolTipProvider; - -/** - * The node map panel handles display of a node map and passes user - * interface events on to the appropriate node map event handling - * methods. - */ -public class NodeMapPanel extends JPanel - implements MouseListener, MouseMotionListener, ToolTipObserver -{ - /** - * Constructs a node map panel. - */ - public NodeMapPanel () - { - init(); - } - - /** - * Constructs a node map panel that displays the given node map. - * - * @param map the node map to display. - */ - public NodeMapPanel (NodeMap map) - { - init(); - setNodeMap(map); - } - - /** - * Initializes the node map panel. - */ - protected void init () - { - // listen to our mouse events - addMouseListener(this); - addMouseMotionListener(this); - } - - /** - * Sets the node map displayed by this panel. - * - * @param map the node map to display. - */ - public void setNodeMap (NodeMap map) - { - _map = map; - - // create the tool tip manager and inform the node map - _map.setToolTipManager(new ToolTipManager(this)); - } - - /** - * Returns the node map currently being displayed by this panel. - */ - public NodeMap getNodeMap () - { - return _map; - } - - /** - * Instructs the panel to center the displayed node map on the - * specified node. If the node is null, the panel will revert back to - * centering on the entire map. - */ - public void centerOnNode (Node node) - { - _centerNode = node; - repaint(); - } - - // documentation inherited - public void paintComponent (Graphics g) - { - super.paintComponent(g); - if (_map != null) { - Dimension osize = getSize(); - int tx, ty; - - // compute the necessary centering offset - if (_centerNode != null) { - Point ncoords = _map.getNodeCoords(_centerNode); - tx = (osize.width - _centerNode.getWidth())/2 - ncoords.x; - ty = (osize.height - _centerNode.getHeight())/2 - ncoords.y; - - } else { - Dimension msize = _map.getSize(); - tx = (osize.width - msize.width)/2; - ty = (osize.height - msize.height)/2; - } - - g.translate(tx, ty); - _map.paint(g); - g.translate(-tx, -ty); - } - } - - public Dimension getPreferredSize () - { - if (_map != null) { - return _map.getSize(); - } else { - return new Dimension(100, 100); - } - } - - public void showToolTip (ToolTipProvider tipper, int x, int y) - { - _map.setToolTipProvider(tipper, x, y); - repaint(); - } - - public void hideToolTip () - { - showToolTip(null, -1, -1); - } - - public JComponent getComponent () - { - return this; - } - - /** MouseListener interface methods */ - - public void mouseClicked (MouseEvent e) - { - if (_map != null) { - _map.handleMouseClicked(e.getX(), e.getY()); - } - } - - public void mouseExited (MouseEvent e) - { - if (_map != null) { - _map.handleMouseExited(); - } - } - - public void mousePressed (MouseEvent e) { } - public void mouseReleased (MouseEvent e) { } - public void mouseEntered (MouseEvent e) { } - - /** MouseMotionListener interface methods */ - - public void mouseMoved (MouseEvent e) - { - if (_map != null) { - _map.handleMouseMoved(e.getX(), e.getY()); - } - } - - public void mouseDragged (MouseEvent e) { } - - /** The node map. */ - protected NodeMap _map; - - /** The node on which we're centering, or null. */ - protected Node _centerNode; -} diff --git a/src/java/com/threerings/nodemap/direction/DirectionalEdge.java b/src/java/com/threerings/nodemap/direction/DirectionalEdge.java deleted file mode 100644 index f30d8f3b0..000000000 --- a/src/java/com/threerings/nodemap/direction/DirectionalEdge.java +++ /dev/null @@ -1,86 +0,0 @@ -// -// $Id: DirectionalEdge.java,v 1.7 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap.direction; - -import java.awt.Graphics2D; -import java.awt.Graphics; -import java.awt.Stroke; - -import com.threerings.nodemap.Edge; -import com.threerings.nodemap.Node; - -/** - * A directional edge extends the {@link Edge} object to allow associating - * a direction with the edge and rendering the edge to the screen. The - * edge direction must be one of the directional constants detailed in the - * {@link DirectionCodes} class. - */ -public class DirectionalEdge extends Edge -{ - /** The edge direction as a {@link DirectionCodes} constant. */ - public int dir; - - /** - * Construct a directional edge. - * - * @param src the source node. - * @param dst the destination node. - * @param dir the edge direction. - */ - public DirectionalEdge (Node src, Node dst, int dir) - { - super(src, dst); - this.dir = dir; - } - - // documentation inherited - public void paint (Graphics g) - { - Graphics2D gfx = (Graphics2D)g; - Stroke ostroke = gfx.getStroke(); - if (_stroke != null) { - gfx.setStroke(_stroke); - } - if (_color != null) { - gfx.setColor(_color); - } - - int sx = src.getX(), sy = src.getY(); - int dx = dst.getX(), dy = dst.getY(); - - int csx = sx + (src.getWidth() / 2); - int csy = sy + (src.getHeight() / 2); - - int cdx = dx + (dst.getWidth() / 2); - int cdy = dy + (dst.getHeight() / 2); - - gfx.drawLine(csx, csy, cdx, cdy); - gfx.setStroke(ostroke); - } - - // documentation inherited - public void toString (StringBuffer buf) - { - super.toString(buf); - buf.append(", dir=").append(dir); - } -} diff --git a/src/java/com/threerings/nodemap/direction/DirectionalLayoutManager.java b/src/java/com/threerings/nodemap/direction/DirectionalLayoutManager.java deleted file mode 100644 index a1efd6fb7..000000000 --- a/src/java/com/threerings/nodemap/direction/DirectionalLayoutManager.java +++ /dev/null @@ -1,130 +0,0 @@ -// -// $Id: DirectionalLayoutManager.java,v 1.5 2004/08/27 02:20:11 mdb Exp $ -// -// Narya library - tools for developing networked games -// Copyright (C) 2002-2004 Three Rings Design, Inc., All Rights Reserved -// http://www.threerings.net/code/narya/ -// -// This library is free software; you can redistribute it and/or modify it -// under the terms of the GNU Lesser General Public License as published -// by the Free Software Foundation; either version 2.1 of the License, or -// (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -package com.threerings.nodemap.direction; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import com.threerings.util.DirectionCodes; - -import com.threerings.nodemap.Node; -import com.threerings.nodemap.LayoutManager; - -/** - * The directional layout manager lays nodes out according to the eight - * cardinal directions as specified in the {@link DirectionCodes} class. - * The nodes must be fully connected in both directions with {@link - * DirectionalEdge} edges. - */ -public class DirectionalLayoutManager - implements LayoutManager, DirectionCodes -{ - /** - * Construct a directional layout manager that lays out nodes - * connected by edges that are edgelen pixels long. - * - * @param edgelen the length of the edges in pixels. - */ - public DirectionalLayoutManager (int edgelen) - { - _edgelen = edgelen; - _closed = new HashMap(); - } - - public void layout (Node root, List nodes) - { - _closed.clear(); - - // lay out all nodes - layoutNode(root, 0, 0, root); - } - - protected void layoutNode (Node root, int x, int y, Node n) - { - // consider each node only once for now - if (_closed.containsKey(n)) { - return; - } - - // set the node's location - n.setLocation(x, y); - - // remember that we've placed this node - _closed.put(n, null); - - Iterator iter = n.getEdges(); - while (iter.hasNext()) { - DirectionalEdge e = (DirectionalEdge)iter.next(); - - int tx = x, ty = y; - int wid = e.dst.getWidth(), hei = e.dst.getHeight(); - - // shift the node in the appropriate direction - switch (e.dir) { - case NORTH: - tx -= (_edgelen + wid); - ty -= (_edgelen + hei); - break; - - case NORTHEAST: - ty -= (_edgelen + hei); - break; - - case EAST: - tx += (_edgelen + wid); - ty -= (_edgelen + hei); - break; - - case SOUTHEAST: - tx += (_edgelen + wid); - break; - - case SOUTH: - tx += (_edgelen + wid); - ty += (_edgelen + hei); - break; - - case SOUTHWEST: - ty += (_edgelen + hei); - break; - - case WEST: - tx -= (_edgelen + wid); - ty += (_edgelen + hei); - break; - - case NORTHWEST: - tx -= (_edgelen + wid); - break; - } - - layoutNode(root, tx, ty, e.dst); - } - } - - /** The length of the edges between nodes in pixels. */ - protected int _edgelen; - - /** The set of nodes already positioned. */ - protected HashMap _closed; -}