/* ========================
* 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-2004, by :
* Corporate:
* EADS Corporate Research Center
* Individual:
* Nicolas Brodu
*
* $Id: Java3DXYZResultSyn3DPlugin.java,v 1.1 2005/06/14 13:12:40 ogor Exp $
*
* Changes
* -------
* 01-Jun-2004 : Creation date (NB);
*
*/
package examples.syn3d.plugin.java3d;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.ArrayList;
import syn3d.base.ActiveNode;
import syn3d.base.Syn3DPlugin;
import syn3d.nodes.GroupNode;
import syn3d.nodes.SceneNode;
/**
* This is an example plugin for Java3D Syn3D. Its main goal is to create
* nodes specialized in loading simple 3D files.
* Such files contain both a geometry and some values to display on it, the format
* is simple and used in other applications like TecPlot. It is described in the
* XYZResultNode class.
*
* The main goal of this plugin is to serve as an example, and to present a few
* tips and tricks when dealing with Java3D (and Syn3D in general).
*
*/
public class Java3DXYZResultSyn3DPlugin extends Syn3DPlugin implements KeyListener {
// see comments in Syn3DPlugin. To make it short, declare here the node
// types this plugin can create
public String[] getNodes() {
return nodes;
}
static String[] nodes = {
"XYZ Result Node"
};
// see comments in Syn3DPlugin. To make it short, return true
// if a node of a type returned by getNodes() can be created
// under an existing parent node
public boolean canCreate(String node, ActiveNode parent) {
if (!node.equals("XYZ Result Node")) return false;
if (parent instanceof GroupNode) return true;
return false;
}
// see comments in Syn3DPlugin. To make it short, this method
// asks the plugin to create a node of a type returned by getNodes()
// under an existing parent node. The canCreate method was previously
// called to ensure it is compatible.
public ActiveNode create(String node, ActiveNode parent) {
if (!node.equals("XYZ Result Node")) return null;
XYZResultNode plnode = null;
plnode = new XYZResultNodeJava3D(parent);
plnode.setName("XYZ Result Node");
return plnode;
}
// see comments in Syn3DPlugin. To make it short, this method
// is called when the user types a key, because this plugin
// implements the key listener interface
public void keyTyped(KeyEvent e) {
// Make it simple to visualize different variables defined in the file,
// just by typing their number.
// This is a naive implementation, changing all nodes at the same time.
// A more elaborate version could change only the "active" node, for example
// the one selected in the JTree (if the JTree of ActiveNode is used).
int num = e.getKeyChar() - '0';
if ((num>=0) && (num<=9)) {
SceneNode scene = (SceneNode)e.getSource();
ArrayList a = scene.findDescendantOfType(XYZResultNode.class);
for (int i=0; i<a.size(); ++i) ((XYZResultNode)a.get(i)).showResult(num);
}
}
public void keyReleased(KeyEvent e) {
}
public void keyPressed(KeyEvent e){
}
}