import java.util.Vector;

import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.Dimension;
import java.awt.Polygon;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JFrame;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2004</p>
 *
 * <p>Company: Technical University of Eindhoven</p>
 *
 * @author not attributable
 * @version 1.0
 */
public class JCTest3D_v0
    extends JFrame {
  private JBCad3D_OpenGl_v0 jBCad3D1;

//VM: -Xms256m -Xmx256m


  public static void main(String[] args) {
    JCTest3D_v0 jctest3d = new JCTest3D_v0();
  }

  public JCTest3D_v0() {
    int WIDTH = 1200, HEIGHT = 600;
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    System.out.println("in JCTestJB");
    setTitle("LaMarck Test");
    setSize(WIDTH, HEIGHT);
    setLocation(d.width / 2 - WIDTH / 2, d.height / 2 - HEIGHT / 2);
    getContentPane().setLayout(new BorderLayout());

    getContentPane().add(main3DPanel(), BorderLayout.CENTER);

    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        if (jBCad3D1 != null)
          jBCad3D1.close_canvas();
        System.out.println("end of app");
        System.exit(0);
      }
    });

    System.out.println("uit JCTestJB");

    setVisible(true);
  }

  private JPanel main3DPanel() {
    JPanel pane = new JPanel();
    pane.setLayout(new BorderLayout());

    jBCad3D1 = new JBCad3D_OpenGl_v0();
    pane.add(jBCad3D1.getCanvas(), BorderLayout.CENTER);

    JButton btn = new JButton("next");
    btn.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent evt) {
        calculate_3();
      }
    });
    pane.add(btn, BorderLayout.SOUTH);

    return pane;
  }

  private void calculate_3() {
    Vector data = new Vector();
    Polygon poly = new Polygon();
    poly.addPoint(0, 0);
    poly.addPoint(0, 10000);
    poly.addPoint(10000, 10000);
    poly.addPoint(10000, 0);
    data.add( poly) ;

    Polygon pg = new Polygon();
    pg.addPoint(0, 0);
    pg.addPoint( -12500, 0);
    pg.addPoint( -12500, 3500);
    pg.addPoint(0, 3500);
    data.add( pg );

    Polygon pg1 = new Polygon();
    pg1.addPoint( -5000, 3000);
    pg1.addPoint( -7500, 3000);
    pg1.addPoint( -7500, 8000);
    pg1.addPoint( -5000, 8000);
    data.add( pg1 );

    Polygon pg2 = new Polygon();
    pg2.addPoint(900, -1000);
    pg2.addPoint( -10500, -1000);
    pg2.addPoint( -10500, 12000);
    pg2.addPoint(900, 12000);
    data.add( pg2 );

    jBCad3D1.reset();
    jBCad3D1.setGebouwData( data );
  }

}
