Reworked tool tips to make the node map panel the tool tip observer.
Early work on evolving the node map into a miniaturized scene display. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@310 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
//
|
//
|
||||||
// $Id: Node.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
|
// $Id: Node.java,v 1.2 2001/08/23 00:22:30 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.nodemap;
|
package com.threerings.nodemap;
|
||||||
|
|
||||||
import java.awt.Graphics;
|
import java.awt.*;
|
||||||
import java.awt.Point;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.samskivert.swing.util.SwingUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The node class represents a single node in a directed graph of nodes.
|
* The node class represents a single node in a directed graph of nodes.
|
||||||
*
|
*
|
||||||
@@ -130,6 +131,34 @@ public abstract class Node
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
public void paintToolTip (Graphics g)
|
||||||
|
{
|
||||||
|
// calculate tool tip position and dimensions
|
||||||
|
FontMetrics fm = g.getFontMetrics(g.getFont());
|
||||||
|
|
||||||
|
int wid = fm.stringWidth(_name) + 10;
|
||||||
|
int hei = fm.getAscent() + 4;
|
||||||
|
|
||||||
|
int xpos = _pos.x + ((_width - wid) / 2);
|
||||||
|
int ypos = _pos.y + ((_height - hei) / 2);
|
||||||
|
|
||||||
|
// draw the yellow box
|
||||||
|
g.setColor(Color.yellow);
|
||||||
|
g.fillRect(xpos, ypos, wid, hei);
|
||||||
|
g.setColor(Color.black);
|
||||||
|
g.drawRect(xpos, ypos, wid, hei);
|
||||||
|
|
||||||
|
// draw the node name
|
||||||
|
SwingUtil.drawStringCentered(g, _name, xpos, ypos, wid, hei);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle mouse-entered events for this node.
|
* Handle mouse-entered events for this node.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
//
|
//
|
||||||
// $Id: NodeMap.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
|
// $Id: NodeMap.java,v 1.2 2001/08/23 00:22:30 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.nodemap;
|
package com.threerings.nodemap;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import javax.swing.JComponent;
|
||||||
|
|
||||||
|
import com.samskivert.swing.ToolTipManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The node map class represents a directed graph of nodes comprised
|
* The node map class represents a directed graph of nodes comprised
|
||||||
@@ -102,6 +105,11 @@ public class NodeMap
|
|||||||
g.drawRect(pos.x, pos.y, wid, hei);
|
g.drawRect(pos.x, pos.y, wid, hei);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw the tool tip, if any
|
||||||
|
if (_tip != null) {
|
||||||
|
_tip.paintToolTip(g);
|
||||||
|
}
|
||||||
|
|
||||||
// restore original origin
|
// restore original origin
|
||||||
g.translate(_minx, _miny);
|
g.translate(_minx, _miny);
|
||||||
}
|
}
|
||||||
@@ -186,10 +194,16 @@ public class NodeMap
|
|||||||
{
|
{
|
||||||
Node enternode = null;
|
Node enternode = null;
|
||||||
|
|
||||||
|
// tell the tip manager that the mouse moved
|
||||||
|
if (_tipmgr != null) {
|
||||||
|
_tipmgr.handleMouseMoved();
|
||||||
|
}
|
||||||
|
|
||||||
// translate coordinates to node map origin
|
// translate coordinates to node map origin
|
||||||
x += _minx;
|
x += _minx;
|
||||||
y += _miny;
|
y += _miny;
|
||||||
|
|
||||||
|
// check whether we've entered a node
|
||||||
int size = _nodes.size();
|
int size = _nodes.size();
|
||||||
for (int ii = 0; ii < size; ii++) {
|
for (int ii = 0; ii < size; ii++) {
|
||||||
Node n = (Node)_nodes.get(ii);
|
Node n = (Node)_nodes.get(ii);
|
||||||
@@ -209,11 +223,19 @@ public class NodeMap
|
|||||||
// exit the last node, if any
|
// exit the last node, if any
|
||||||
if (_lastnode != null) {
|
if (_lastnode != null) {
|
||||||
_lastnode.handleMouseExited();
|
_lastnode.handleMouseExited();
|
||||||
|
|
||||||
|
if (_tipmgr != null) {
|
||||||
|
_tipmgr.handleMouseExited(_lastnode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// enter the new node, if any
|
// enter the new node, if any
|
||||||
if (enternode != null) {
|
if (enternode != null) {
|
||||||
enternode.handleMouseEntered();
|
enternode.handleMouseEntered();
|
||||||
|
|
||||||
|
if (_tipmgr != null) {
|
||||||
|
_tipmgr.handleMouseEntered(enternode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// update the last node entered
|
// update the last node entered
|
||||||
@@ -244,12 +266,45 @@ public class NodeMap
|
|||||||
Point pos = n.getPosition();
|
Point pos = n.getPosition();
|
||||||
n.handleMouseClicked(x - pos.x, y - pos.y);
|
n.handleMouseClicked(x - pos.x, y - pos.y);
|
||||||
|
|
||||||
|
// 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
|
// nodes can't overlap for now, so we're done
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the node whose tool tip should be displayed when the node
|
||||||
|
* map is rendered.
|
||||||
|
*
|
||||||
|
* @param node the tool tip node.
|
||||||
|
*/
|
||||||
|
public void setToolTipNode (Node node)
|
||||||
|
{
|
||||||
|
_tip = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 node whose tool tip is currently displayed. */
|
||||||
|
protected Node _tip;
|
||||||
|
|
||||||
|
/** The tool tip manager. */
|
||||||
|
protected ToolTipManager _tipmgr;
|
||||||
|
|
||||||
/** The layout manager. */
|
/** The layout manager. */
|
||||||
protected LayoutManager _lmgr;
|
protected LayoutManager _lmgr;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: NodeMapPanel.java,v 1.1 2001/08/20 22:56:55 shaper Exp $
|
// $Id: NodeMapPanel.java,v 1.2 2001/08/23 00:22:30 shaper Exp $
|
||||||
|
|
||||||
package com.threerings.nodemap;
|
package com.threerings.nodemap;
|
||||||
|
|
||||||
@@ -7,17 +7,23 @@ import java.awt.*;
|
|||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
|
import com.samskivert.swing.ToolTipManager;
|
||||||
|
import com.samskivert.swing.ToolTipObserver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The node map panel handles display of a node map and passes Swing
|
* The node map panel handles display of a node map and passes Swing
|
||||||
* UI events on to the appropriate node map event handling methods.
|
* UI events on to the appropriate node map event handling methods.
|
||||||
*/
|
*/
|
||||||
public class NodeMapPanel extends JPanel
|
public class NodeMapPanel extends JPanel
|
||||||
implements MouseListener, MouseMotionListener
|
implements MouseListener, MouseMotionListener, ToolTipObserver
|
||||||
{
|
{
|
||||||
public NodeMapPanel (NodeMap map)
|
public NodeMapPanel (NodeMap map)
|
||||||
{
|
{
|
||||||
_map = map;
|
_map = map;
|
||||||
|
|
||||||
|
// create the tool tip manager and inform the node map
|
||||||
|
_map.setToolTipManager(new ToolTipManager(this));
|
||||||
|
|
||||||
// listen to our mouse events
|
// listen to our mouse events
|
||||||
addMouseListener(this);
|
addMouseListener(this);
|
||||||
addMouseMotionListener(this);
|
addMouseMotionListener(this);
|
||||||
@@ -34,6 +40,22 @@ public class NodeMapPanel extends JPanel
|
|||||||
return _map.getSize();
|
return _map.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void showToolTip (Object target)
|
||||||
|
{
|
||||||
|
_map.setToolTipNode((Node)target);
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void hideToolTip ()
|
||||||
|
{
|
||||||
|
showToolTip(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JComponent getComponent ()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/** MouseListener interface methods */
|
/** MouseListener interface methods */
|
||||||
|
|
||||||
public void mouseClicked (MouseEvent e)
|
public void mouseClicked (MouseEvent e)
|
||||||
|
|||||||
Reference in New Issue
Block a user