import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class Test extends Applet
{
        private SimpleUniverse u = null;

    public BranchGroup createSceneGraph()
    {
                // Create the root of the branch graph
                BranchGroup objRoot = new BranchGroup();

                // Create a simple Shape3D node; add it to the scene graph.
                objRoot.addChild(new ColorCube(0.4));

                BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

                // Have Java 3D perform optimizations on this scene graph.
                objRoot.compile();

                return objRoot;
        }


        public Test() {}


        public void init()
        {
                setLayout(new BorderLayout());
                GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

                Canvas3D c = new Canvas3D(config);
                add("Center", c);

                // Create a simple scene and attach it to the virtual universe
                BranchGroup scene = createSceneGraph();
                u = new SimpleUniverse(c);

                // This will move the ViewPlatform back a bit so the
                // objects in the scene can be viewed.
                u.getViewingPlatform().setNominalViewingTransform();


                // Set up mouse interaction
                OrbitBehavior orbit = new OrbitBehavior(c, OrbitBehavior.REVERSE_ROTATE);
                orbit.setSchedulingBounds(new BoundingSphere(new Point3d(), Double.POSITIVE_INFINITY));
                u.getViewingPlatform().setViewPlatformBehavior(orbit);

                // Create home button
                Button home = new Button("Home");
                home.addActionListener( new ActionListener()
                {
                        public void actionPerformed(ActionEvent ae)
                        {
                                u.getViewingPlatform().setNominalViewingTransform();
                        }
                });
                add("North", home);

                u.addBranchGraph(scene);

        }


        public void destroy()
        {
                u.removeAllLocales();
        }


        public static void main(String[] args)
        {
                new MainFrame(new Test(), 256, 256);
        }

}
