/*
* $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegraph/SGNodeComponent.java,v 1.1 2005/04/20 22:20:41 paulby Exp $
*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License Version
* 1.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is available at http://www.sun.com/
*
* The Original Code is the Java 3D(tm) Scene Graph Editor.
* The Initial Developer of the Original Code is Paul Byrne.
* Portions created by Paul Byrne are Copyright (C) 2002.
* All Rights Reserved.
*
* Contributor(s): Paul Byrne.
*
**/
package org.jdesktop.j3dedit.scenegraph;
import java.util.ArrayList;
/**
*
* Represents a Java3D NodeComponent
*
* @author paulby
* @version $id$
*/
public class SGNodeComponent extends SGObject {
private ArrayList referencedBy;
/**
* Creates a node component and registers it with SceneGraphControl
*/
public SGNodeComponent( javax.media.j3d.NodeComponent nc, org.jdesktop.j3dedit.J3dEditContext editContext ) {
super(editContext);
if (nc==null)
throw new RuntimeException("NodeComponent is null "+this);
j3dNode = nc;
referencedBy = new ArrayList();
editContext.getSceneGraphControl().addNodeComponent( this );
}
/**
* Set the Java3D which is represented by this object
*
* Store the capability bits for the node
*/
public void setJ3dNode( javax.media.j3d.NodeComponent node ) {
if (node==null) {
System.out.println("Null node component "+this);
Thread.dumpStack();
}
j3dNode = node;
capabilities.storeCapabilities( node );
}
/**
* Get the Java3D node represented by this object
*/
public javax.media.j3d.NodeComponent getJ3dNode() {
return (javax.media.j3d.NodeComponent)j3dNode;
}
/**
* Return the Locale to which this node is connected
*/
public javax.media.j3d.Locale getLocale() {
throw new RuntimeException("Not Implemented");
}
/**
* Is this node live
*/
public boolean isLive() {
return context.getLocale().getLive();
}
/**
* Change the live state of this node, this may change the live
* state of other nodes in the graph, but in general the minimum
* change will be made
*/
public void setLive(boolean live) {
context.getLocale().setLive( live );
}
/**
* Add node to the list of objects that reference this node component
**
* @param node The Node or NodeComponent to add
*/
public void addReferencedBy( SGObject node ) {
referencedBy.add( node );
}
/**
* Remove node from the list of objects that reference this node component.
* Once the node is not referenced by any other objects it will be destroyed
*
* @param node The Node or NodeComponent to remove
*/
public void removeReferencedBy( SGObject node ) {
if (!referencedBy.remove( node ))
org.jdesktop.j3dfly.utils.gui.ErrorManager.getDefault().notify( new RuntimeException("Removing non-existant Reference"),
org.jdesktop.j3dfly.utils.gui.ErrorHandler.INFORMATIONAL );
// TODO CHeck what other java 'pointers' we need to clear to enable GC
if (referencedBy.size()==0) {
getContext().getSceneGraphControl().removeNodeComponent( this );
j3dNode = null; // This MUST be after removeNodeComponent
}
}
/**
* Returns the set of SGObjects that reference this node component
*/
public SGObject[] getReferencedBy() {
return (SGObject[])referencedBy.toArray( new SGObject[referencedBy.size()] );
}
/**
* Returns the number of objects that reference this node component
*/
public int getReferencedByCount() {
return referencedBy.size();
}
}
|