01: /*
02: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/treeview/TVBehavior.java,v 1.1 2005/04/20 22:21:27 paulby Exp $
03: *
04: * Sun Public License Notice
05: *
06: * The contents of this file are subject to the Sun Public License Version
07: * 1.0 (the "License"). You may not use this file except in compliance with
08: * the License. A copy of the License is available at http://www.sun.com/
09: *
10: * The Original Code is the Java 3D(tm) Scene Graph Editor.
11: * The Initial Developer of the Original Code is Paul Byrne.
12: * Portions created by Paul Byrne are Copyright (C) 2002.
13: * All Rights Reserved.
14: *
15: * Contributor(s): Paul Byrne.
16: *
17: **/
18: package org.jdesktop.j3dedit.scenegrapheditor.treeview;
19:
20: import java.awt.Graphics2D;
21: import java.awt.Graphics;
22: import java.awt.Polygon;
23: import java.awt.Point;
24: import java.awt.Color;
25:
26: import java.lang.reflect.*;
27:
28: import javax.media.j3d.Behavior;
29: import javax.media.j3d.Node;
30: import javax.media.j3d.TransformGroup;
31: import org.jdesktop.j3dedit.scenegraph.SGBehavior;
32: import org.jdesktop.j3dedit.scenegraph.SGObject;
33:
34: /**
35: * @author Paul Byrne
36: * @version 1.4, 01/18/02
37: */
38: public class TVBehavior extends TVObject {
39:
40: private Polygon triangle;
41:
42: /** Creates new BehaviorTreeNode */
43: public TVBehavior(SGObject sgObject) {
44: super (29, 29, 29, sgObject);
45: int w = getNodeSize().width;
46: int h = getNodeSize().height;
47: triangle = new Polygon(new int[] { w, 0, w / 2, w }, new int[] {
48: h, h, 0, h }, 4);
49: }
50:
51: public Point getBehaviorLinkEntry(Point behaviorLocation) {
52: throw new RuntimeException(
53: "Behaviors can not be the target of another Behavior");
54: }
55:
56: public Point getBehaviorLinkExit(Point targetLocation) {
57: return new Point(computedPosition.x + nodeSize.width / 2,
58: computedPosition.y + nodeSize.height / 2);
59:
60: }
61:
62: public void drawNode(Graphics2D g) {
63: super .drawNode(g);
64: if (((SGBehavior) sgObject).getActionNode() != null) {
65: Point actionNodePos = ((TVObject) ((SGBehavior) sgObject)
66: .getActionNode().getTreeViewObject())
67: .getBehaviorLinkEntry(computedPosition);
68: Point exitPos = getBehaviorLinkExit(actionNodePos);
69: currentColor = g.getColor();
70: g.setColor(Color.red);
71: g.drawLine(exitPos.x, exitPos.y, actionNodePos.x,
72: actionNodePos.y);
73: g.setColor(currentColor);
74: }
75:
76: if (icon != null && drawAsIcon) {
77: g.drawImage(icon, computedPosition.x, computedPosition.y,
78: null);
79: } else {
80: g.translate(computedPosition.x, computedPosition.y);
81: g.setColor(Color.white);
82: g.fill(triangle);
83: g.setColor(Color.black);
84: g.draw(triangle);
85: g.translate(-computedPosition.x, -computedPosition.y);
86: }
87:
88: drawNameLabel(g);
89: }
90:
91: }
|