/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2007, by :
* Corporate:
* EADS Astrium
* Individual:
* Claude Cazenave
*
* $Id: ReferenceNode.java,v 1.5 2008/12/17 22:37:53 cazenave Exp $
*
* Changes
* -------
* 14 janv. 08 : Initial public release
*
*/
package jsynoptic.plugins.java3d.tree;
import java.awt.event.ActionEvent;
import java.util.ArrayList;
import javax.media.j3d.SceneGraphObject;
import jsynoptic.plugins.java3d.GraphObjectReference;
import jsynoptic.plugins.java3d.Universe;
/**
* A node to display a reference to a scene graph object
*/
public class ReferenceNode extends AbstractNode {
// required for dynamic node creation
public ReferenceNode(Tree tree, Object graphObject, boolean getChildren) {
super(tree, graphObject, getChildren);
GraphObjectReference gn = (GraphObjectReference) getGraphObject();
// by default name is equal to class name
String n = (gn.getObject() == null) ? "" : gn.getObject().getClass()
.getName();
int k = n.lastIndexOf('.');
_name = n.substring(k + 1);
_icon = getIcon(gn.getObject());
_description = getDescription(gn.getObject());
}
public String getName() {
GraphObjectReference gn = (GraphObjectReference) getGraphObject();
String sgoName = (gn.getObject()).getName();
if (sgoName != null) {
return "-> " + _name + "[" + sgoName + "]";
} else {
return "-> " + _name;
}
}
/*
* (non-Javadoc)
*
* @see jsynoptic.plugins.java3d.tree.AbstractNode#getSceneGraphChildren(java.util.ArrayList)
*/
@Override
protected void getSceneGraphChildren(ArrayList<Object> list) {
// none
}
public static class ExpandAction extends AbstractNodeAction {
// required for dynamic action creation
public ExpandAction() {
}
@Override
public void actionPerformed(ActionEvent e) {
ArrayList<SceneGraphObject> sgos = new ArrayList<SceneGraphObject>();
GraphObjectReference gn = (GraphObjectReference) getNode()
.getGraphObject();
Universe u = Universe.getGraphPath(gn.getNode(), gn.getObject(),
sgos);
if(u!=null){
getNode().getTree().expand(sgos, u);
}
else{
System.err.println("Can not expand "+gn.getObject()+" node is missing");
}
}
}
public Object[] getActions() {
Object[] res = { ExpandAction.class };
return res;
}
}