001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegraph/SGBehavior.java,v 1.1 2005/04/20 22:20:39 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegraph;
019:
020: import java.lang.reflect.*;
021:
022: import javax.media.j3d.Behavior;
023: import javax.media.j3d.Node;
024: import javax.media.j3d.TransformGroup;
025:
026: import org.jdesktop.j3dedit.scenegrapheditor.PropertiesDialog;
027: import org.jdesktop.j3dedit.scenegrapheditor.WindowManager;
028:
029: /**
030: * @author Paul Byrne
031: * @version $id$
032: */
033: public class SGBehavior extends SGLeaf {
034:
035: private SGObject actionNode; // Node on which this behavior acts
036:
037: /** Creates new BehaviorTreeNode */
038: public SGBehavior(javax.media.j3d.Node node,
039: org.jdesktop.j3dedit.J3dEditContext editContext) {
040: super (node, editContext);
041: actionNode = null;
042: }
043:
044: /**
045: * Set the node on which this behavior acts
046: * If this is set then a line is drawn between the behavior and
047: * node on which it acts.
048: */
049: public void setActionNode(SGObject actionNode) {
050: this .actionNode = actionNode;
051: }
052:
053: /**
054: * Return the node this behavior acts on
055: */
056: public SGObject getActionNode() {
057: return actionNode;
058: }
059:
060: /**
061: * Return true if node is a valid target for this behavior
062: */
063: public boolean isValidTarget(SGObject node) {
064:
065: Behavior behavior = (Behavior) getJ3dNode();
066: if (behavior instanceof javax.media.j3d.PathInterpolator
067: || behavior instanceof javax.media.j3d.PositionInterpolator
068: || behavior instanceof javax.media.j3d.PositionPathInterpolator
069: || behavior instanceof javax.media.j3d.RotationInterpolator
070: || behavior instanceof javax.media.j3d.ScaleInterpolator
071: || behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseRotate
072: || behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseTranslate
073: || behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseZoom
074: || behavior instanceof com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator
075: || behavior instanceof com.sun.j3d.utils.behaviors.interpolators.TCBSplinePathInterpolator)
076: if (node.getJ3dSceneGraphObject() instanceof javax.media.j3d.TransformGroup)
077: return true;
078:
079: return false;
080: }
081:
082: /**
083: * Set the target of this behavior to be node, updates both the view
084: * (using setActionNode) and the scene graph.
085: */
086: public void setTarget(SGObject node) {
087: setActionNode(node);
088:
089: // Update scenegraph
090:
091: // Call setTarget method in the Interpolator
092: Node target = (Node) node.getJ3dSceneGraphObject();
093: if (target == null)
094: target = new javax.media.j3d.TransformGroup();
095: Behavior behavior = (Behavior) getJ3dNode();
096: Method setTarget;
097: try {
098: if (behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseRotate
099: || behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseZoom
100: || behavior instanceof com.sun.j3d.utils.behaviors.mouse.MouseTranslate)
101: setTarget = behavior
102: .getClass()
103: .getMethod(
104: "setTransformGroup",
105: new Class[] { javax.media.j3d.TransformGroup.class });
106: else
107: setTarget = behavior
108: .getClass()
109: .getMethod(
110: "setTarget",
111: new Class[] { javax.media.j3d.TransformGroup.class });
112:
113: if (PropertiesDialog.performanceLevel != PropertiesDialog.READ_WRITE_ALLOWED) {
114: context.getLocale().setLive(false);
115: target
116: .setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
117: target
118: .setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
119: }
120:
121: node.setCapability("ALLOW_TRANSFORM_READ");
122: node.setCapability("ALLOW_TRANSFORM_WRITE");
123:
124: setTarget.invoke(behavior, new Object[] { target });
125:
126: if (PropertiesDialog.performanceLevel != PropertiesDialog.READ_WRITE_ALLOWED)
127: context.getLocale().setLive(true);
128:
129: } catch (Exception e) {
130: e.printStackTrace();
131: }
132: }
133:
134: }
|