001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegraph/SGNodeComponent.java,v 1.1 2005/04/20 22:20:41 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.util.ArrayList;
021:
022: /**
023: *
024: * Represents a Java3D NodeComponent
025: *
026: * @author paulby
027: * @version $id$
028: */
029: public class SGNodeComponent extends SGObject {
030:
031: private ArrayList referencedBy;
032:
033: /**
034: * Creates a node component and registers it with SceneGraphControl
035: */
036: public SGNodeComponent(javax.media.j3d.NodeComponent nc,
037: org.jdesktop.j3dedit.J3dEditContext editContext) {
038: super (editContext);
039:
040: if (nc == null)
041: throw new RuntimeException("NodeComponent is null " + this );
042:
043: j3dNode = nc;
044: referencedBy = new ArrayList();
045: editContext.getSceneGraphControl().addNodeComponent(this );
046: }
047:
048: /**
049: * Set the Java3D which is represented by this object
050: *
051: * Store the capability bits for the node
052: */
053: public void setJ3dNode(javax.media.j3d.NodeComponent node) {
054: if (node == null) {
055: System.out.println("Null node component " + this );
056: Thread.dumpStack();
057: }
058: j3dNode = node;
059: capabilities.storeCapabilities(node);
060: }
061:
062: /**
063: * Get the Java3D node represented by this object
064: */
065: public javax.media.j3d.NodeComponent getJ3dNode() {
066: return (javax.media.j3d.NodeComponent) j3dNode;
067: }
068:
069: /**
070: * Return the Locale to which this node is connected
071: */
072: public javax.media.j3d.Locale getLocale() {
073: throw new RuntimeException("Not Implemented");
074: }
075:
076: /**
077: * Is this node live
078: */
079: public boolean isLive() {
080: return context.getLocale().getLive();
081: }
082:
083: /**
084: * Change the live state of this node, this may change the live
085: * state of other nodes in the graph, but in general the minimum
086: * change will be made
087: */
088: public void setLive(boolean live) {
089: context.getLocale().setLive(live);
090: }
091:
092: /**
093: * Add node to the list of objects that reference this node component
094: **
095: * @param node The Node or NodeComponent to add
096: */
097: public void addReferencedBy(SGObject node) {
098: referencedBy.add(node);
099: }
100:
101: /**
102: * Remove node from the list of objects that reference this node component.
103: * Once the node is not referenced by any other objects it will be destroyed
104: *
105: * @param node The Node or NodeComponent to remove
106: */
107: public void removeReferencedBy(SGObject node) {
108: if (!referencedBy.remove(node))
109: org.jdesktop.j3dfly.utils.gui.ErrorManager
110: .getDefault()
111: .notify(
112: new RuntimeException(
113: "Removing non-existant Reference"),
114: org.jdesktop.j3dfly.utils.gui.ErrorHandler.INFORMATIONAL);
115:
116: // TODO CHeck what other java 'pointers' we need to clear to enable GC
117: if (referencedBy.size() == 0) {
118: getContext().getSceneGraphControl().removeNodeComponent(
119: this );
120: j3dNode = null; // This MUST be after removeNodeComponent
121: }
122: }
123:
124: /**
125: * Returns the set of SGObjects that reference this node component
126: */
127: public SGObject[] getReferencedBy() {
128: return (SGObject[]) referencedBy
129: .toArray(new SGObject[referencedBy.size()]);
130: }
131:
132: /**
133: * Returns the number of objects that reference this node component
134: */
135: public int getReferencedByCount() {
136: return referencedBy.size();
137: }
138: }
|