/* ========================
* 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: UniverseNode.java,v 1.9 2008/11/20 06:54:16 cazenave Exp $
*
* Changes
* -------
* 9 janv. 08 : Initial public release
*
*/
package jsynoptic.plugins.java3d.tree;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.io.IOException;
import java.util.ArrayList;
import javax.media.j3d.BranchGroup;
import jsynoptic.plugins.java3d.Universe;
/**
* The universe node
*/
/**
* @author cazenave_c
*
*/
public class UniverseNode extends AbstractNode implements Universe.Listener {
/**
* Register nodes resources and actions
*/
static void loadResources() {
addResources("jsynoptic.plugins.java3d.Universe", "Universe");
AbstractNodeAction.addActions("jsynoptic.plugins.java3d.Universe",
AddBranchGroupActionUniverse.class, SaveUniverseAction.class, null,
AddViewAction.class);
GroupNode.loadResources();
BranchGroupNode.loadResources();
addNodeClass("javax.media.j3d.Canvas3D", CanvasNode.class);
CanvasNode.loadResources();
}
// required for dynamic node creation
public UniverseNode(Tree tree, Object graphObject, boolean getChildren) {
super(tree, graphObject, getChildren);
Universe pu = (Universe) getGraphObject();
pu.addListner(this);
}
@Override
public String getName(){
return ((Universe)getGraphObject()).getName();
}
@Override
protected void getSceneGraphChildren(ArrayList<Object> list) {
Universe pu = (Universe) getGraphObject();
list.addAll(pu.getCanvas());
list.addAll(pu.getSceneGraphs());
}
public void notifyChange() {
refresh();
}
static class AddBranchGroupActionUniverse extends AbstractNodeAction {
// required for dynamic action creation
public AddBranchGroupActionUniverse() {
}
public void actionPerformed(ActionEvent e) {
((Universe) getNode().getGraphObject())
.addBranchGraph(new BranchGroup());
// TODO add undo
getNode().refresh();
}
}
static class AddViewAction extends AbstractNodeAction {
// required for dynamic action creation
public AddViewAction() {
}
@Override
public void actionPerformed(ActionEvent e) {
((Universe) getNode().getGraphObject()).addView(getNode().getTree());
getNode().refresh();
}
}
static class SaveUniverseAction extends AbstractNodeAction {
// required for dynamic action creation
public SaveUniverseAction() {
}
@Override
public void actionPerformed(ActionEvent e) {
try {
getNode().getTree().getPool().saveUniverse(
(Universe) getNode().getGraphObject(),
e.getSource() instanceof Component ? (Component) e
.getSource() : null);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
getNode().refresh();
}
}
}