import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.behaviors.picking.*;

public class ColorTest extends Applet {

    public BranchGroup scene;
    public Canvas3D canvas;

    public class MyCallbackClass extends Object implements PickingCallback {
	public void transformChanged(int type, TransformGroup tg)
	    {
		System.out.println("picking");
	    }
    }
	
    public BranchGroup createSceneGraph()
	{
	    Cylinder cyl = new Cylinder(0.5f, 0.5f);
	    Cylinder cyl2 = new Cylinder(0.25f, 0.5f);
	    
	    Appearance app = new Appearance();
	    ColoringAttributes cAttr = new ColoringAttributes();
	    cAttr.setColor(new Color3f(0.0f, 0.0f, 1.0f));
	    app.setColoringAttributes(cAttr);
	    cyl.setAppearance(app);
	    
	    Transform3D moveit = new Transform3D();
	    moveit.setTranslation(new Vector3f(-0.5f, -0.2f, 0.6f));
	    
	    TransformGroup tg = new TransformGroup(moveit);
	    tg.addChild(cyl);

	    moveit.setTranslation(new Vector3f(0.5f, 0.0f, -0.6f));
	    TransformGroup tg2 = new TransformGroup(moveit);
	    ColorCube mycube = new ColorCube(0.3);
	    
	    tg2.addChild(mycube);
	    cyl2.setAppearance(app);
	    
	    scene = new BranchGroup();
	    scene.addChild(tg);
	    scene.addChild(tg2);

	     PickingCallback myCallback = new MyCallbackClass();
	    PickScreenObject pickit = new PickScreenObject(tg, scene, canvas);

	    // Get all objects from the screen point which belong
	    // to this branchgraph
	    pickit.setRetParam(PickScreenObject.GET_ALLSORTED);
	    pickit.setSchedulingBounds( new BoundingSphere(new Point3d(0.0,0.0,0.0),10.0));
//	    pickit.setUpCallback(myCallback);
	    scene.addChild(pickit);

	    
//	    scene.addChild(pickit2);
	    
	    return scene;
	}

    public ColorTest() {

	setLayout(new BorderLayout());
        GraphicsConfiguration config =
           SimpleUniverse.getPreferredConfiguration();

	canvas = new Canvas3D(config);
	scene = createSceneGraph();

        add("Center", canvas);
	SimpleUniverse u = new SimpleUniverse(canvas);

        // This will move the ViewPlatform back a bit so the
        // objects in the scene can be viewed.
        u.getViewingPlatform().setNominalViewingTransform();
	u.addBranchGraph(scene);
    }

    
    public static void main(String[] args) {
	
        new MainFrame(new ColorTest(), 256, 256);
    }

}
    
