/**********************************
 * Test35b - WinNT problem
 * -------
 * JFrame with BorderLayout + Canvas3D.
 *
 * PostSwap method of Canvas overridden to draw additional
 * lines on the canvas.  Can this be buffered to stop flicker?
 * Lines drawn on border of canvas.
 * 
 * ----
 * Test runs correctly on Win95 machine.
 * ----
 * Test fails on WinNT4.0 machine running more than 256 colours.
 *   - when window is resized, shape3D is no longer drawn to all
 *     of the canvas - J3D does not render to the bottom portion
 *     of the canvas.  (However, the border lines are drawn to
 *     the bottom portion of the canvas).
 *     Test works correctly on 256 colours.
 *
 * AJP 04-JUN-1999
 * 
 **********************************/ 

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import com.sun.j3d.utils.geometry.ColorCube;

public class test35b extends JFrame
{
    public BranchGroup getSceneGraph() {
        
    // Create the root of the branch graph
    BranchGroup rootBG = new BranchGroup();

    // Create the 'mouse' transform group node and initialize it to the
    // identity.
    TransformGroup transMouse = new TransformGroup();
    transMouse.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transMouse.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    rootBG.addChild(transMouse);

    // Create a simple shape leaf node, add it to the scene graph.
    transMouse.addChild(new ColorCube(0.4));

    BoundingSphere bounds =
      new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
      // Create the rotate behavior node
      MouseRotate behavior = new MouseRotate();
      behavior.setTransformGroup(transMouse);
      transMouse.addChild(behavior);
      behavior.setSchedulingBounds(bounds);

      // Create the zoom behavior node
      MouseZoom behavior2 = new MouseZoom();
      behavior2.setTransformGroup(transMouse);
      transMouse.addChild(behavior2);
      behavior2.setSchedulingBounds(bounds);

      // Create the translate behavior node
      MouseTranslate behavior3 = new MouseTranslate();
      behavior3.setTransformGroup(transMouse);
      transMouse.addChild(behavior3);
      behavior3.setSchedulingBounds(bounds);

    return rootBG;
    }
    
    public test35b()
    {
        
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {System.exit(0);}});
 
    // set layout
    getContentPane().setLayout(new BorderLayout());
    setSize(400,400);
    setVisible(false);
    setTitle("Test35b");
        
    Canvas3D c = new TestCanvas(null);
    getContentPane().add("Center", c); 
  
     // add a scene to the universe
     BranchGroup scene = getSceneGraph();
     scene.setCapability( BranchGroup.ALLOW_BOUNDS_READ );
     SimpleUniverse u = new SimpleUniverse(c);
     u.getViewingPlatform().setNominalViewingTransform();
 
     u.addBranchGraph(scene);
        
    }
      
    static public void main(String args[])
    {
     (new test35b()).setVisible(true);
    }
    
}

class TestCanvas extends Canvas3D{
    
    public TestCanvas(GraphicsConfiguration graphicsConfiguration){  
        
     super(graphicsConfiguration);

    }
    
    public void postSwap (){ 
        
       Graphics g = this.getGraphics();
       g.setFont(f);
       height = this.getHeight();
       width = this.getWidth();
       g.setColor(Color.yellow); 
       g.drawRect(3, 3, width - 6, height - 6);  
       g.drawString(s, 10, height - 20);
       g.dispose();

    }  
    
    Font f = new Font("SansSerif", Font.PLAIN, 10);
    String s = "Mouse buttons: left-rotate, right-translate, middle-zoom";
    int height;
    int width;
}
    

