package DVMS.frame;
import java.awt.*;
import java.awt.event.*;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.GLJPanel;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import com.sun.opengl.util.Animator;
/**
* This is the main frame of the system which extends Frame.
*
* @version 0.1.0
* @author Charles
*
*/
public class MainFrame extends Frame implements GLEventListener, MouseListener, MouseMotionListener {
/**
* Automatically generated ID.
*/
private static final long serialVersionUID = 1L;
private static final int DEFAULT_WIDTH = 800;
private static final int DEFAULT_HEIGHT = 600;
final Animator animator;
float rot = 0f;
public void startAnimation(){
animator.start();
}
public MainFrame(String title) {
// TODO Auto-generated constructor stub
super(title);
MenuBar menuBar = new MenuBar();
setMenuBar(menuBar);
// final JSlider slider = new JSlider(0, 100, 0);
// slider.addChangeListener(new ChangeListener() {
//
// @Override
// public void stateChanged(ChangeEvent e) {
//
// int i = slider.getValue();
// System.out.println(i);
// }
// });
Scrollbar timeLine = new Scrollbar(Scrollbar.HORIZONTAL, 0, 20, 0, 300);
this.add(timeLine);
timeLine.addAdjustmentListener (new AdjustmentListener()
{
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
// TODO Auto-generated method stub
int i = e.getValue();
System.out.println(i);
}
});
/**
* Slide tools
*/
Menu slideMenu = new Menu("Slide");
menuBar.add(slideMenu);
MenuItem fullSlideItem = new MenuItem("Full Slide");
slideMenu.add(fullSlideItem);
fullSlideItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem PartialSlideItem = new MenuItem("Partial Slide");
slideMenu.add(PartialSlideItem);
PartialSlideItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
/**
* Section tools
*/
Menu sectionMenu = new Menu("Section");
menuBar.add(sectionMenu);
MenuItem segmentSectionItem = new MenuItem("Segment Section");
sectionMenu.add(segmentSectionItem);
segmentSectionItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem pointSectionItem = new MenuItem("Point Section");
sectionMenu.add(pointSectionItem);
pointSectionItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem curveSectionItem = new MenuItem("Curve Section");
sectionMenu.add(curveSectionItem);
curveSectionItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem scanSectionItem = new MenuItem("Scan Section");
sectionMenu.add(scanSectionItem);
scanSectionItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
/**
* Spreading tools
*/
Menu spreadingMenu = new Menu("Spreading");
menuBar.add(spreadingMenu);
MenuItem upsideSpreadingItem = new MenuItem("Upside Spreading");
spreadingMenu.add(upsideSpreadingItem);
upsideSpreadingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem sideSpreadingItem = new MenuItem("Side Spreading");
spreadingMenu.add(sideSpreadingItem);
sideSpreadingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem horizontalSpreadingItem = new MenuItem("Horizontal Spreading");
spreadingMenu.add(horizontalSpreadingItem);
horizontalSpreadingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
/**
* Cutting tools
*/
Menu CuttingMenu = new Menu("Cutting");
menuBar.add(CuttingMenu);
MenuItem directCuttingItem = new MenuItem("Direct Cutting");
CuttingMenu.add(directCuttingItem);
directCuttingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem cubeCuttingItem = new MenuItem("Cube Cutting");
CuttingMenu.add(cubeCuttingItem);
cubeCuttingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
MenuItem coneCuttingItem = new MenuItem("Cone Cutting");
CuttingMenu.add(coneCuttingItem);
coneCuttingItem.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event) {
//System.exit(NORMAL);
}
});
/**
* Set the window in the middle of the screen and set the size
*/
Dimension d = getToolkit().getScreenSize();
int x = (int)(d.getWidth()/2)-(int)(DEFAULT_WIDTH/2);
int y = (int)(d.getHeight()/2)-(int)(DEFAULT_HEIGHT/2);
setBounds(x, y, DEFAULT_WIDTH, DEFAULT_HEIGHT);
setResizable(false);
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(this);
//this.add(canvas);
/**
* Add default close function to close button
*/
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
/**
* Add animator
*/
animator = new Animator(canvas);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
// exiting
new Thread(new Runnable() {
public void run() {
animator.stop();
System.exit(0);
}
}).start();
}
});
}
/**
* The main function
*
* @param args
* The args from command line.
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
/**
* Create the main frame
*/
MainFrame frame = new MainFrame("Test Frame");
frame.setVisible(true);
frame.startAnimation();
}
@Override
public void display(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
GL gl = drawable.getGL();
float red[] = { 0.8f, 0.1f, 0.0f, 1.0f };
//gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
if ((drawable instanceof GLJPanel)
&& !((GLJPanel) drawable).isOpaque()
&& ((GLJPanel) drawable)
.shouldPreserveColorBufferIfTranslucent()) {
gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
} else {
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
}
int teeth = 10;
int i;
float angle;
float r1 = 1.0f;
float r0 = 0.5f;
float width = .5f;
float da = .7f;
rot += 1.0f;
gl.glPushMatrix();
gl.glRotatef(30, 1.0f, 0, 0);
gl.glRotatef(40, 0, 1.0f, 0);
gl.glRotatef(50, 0, 0, 1.0f);
gl.glRotatef(rot, 1.0f, 1.0f, 1.0f);
gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, red, 0);
gl.glBegin(GL.GL_QUAD_STRIP);
for (i = 0; i <= teeth; i++) {
angle = i * 2.0f * (float) Math.PI / teeth;
gl.glVertex3f(r1 * (float) Math.cos(angle), r1
* (float) Math.sin(angle), -width * 0.5f);
gl.glVertex3f(r0 * (float) Math.cos(angle), r0
* (float) Math.sin(angle), -width * 0.5f);
gl.glVertex3f(r1 * (float) Math.cos(angle + 3 * da), r1
* (float) Math.sin(angle + 3 * da), -width * 0.5f);
gl.glVertex3f(r0 * (float) Math.cos(angle), r0
* (float) Math.sin(angle), -width * 0.5f);
}
gl.glEnd();
gl.glPopMatrix();
}
@Override
public void init(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
GL gl = drawable.getGL();
gl.setSwapInterval(1);
gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos, 0);
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_DEPTH_TEST);
drawable.addMouseListener(this);
drawable.addMouseMotionListener(this);
}
@Override
public void reshape(GLAutoDrawable drawable, int x, int y, int width,
int height) {
// TODO Auto-generated method stub
GL gl = drawable.getGL();
float h = (float) height / (float) width;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -20.0f);
}
@Override
public void mouseClicked(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mouseDragged(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent mouseevent) {
// TODO Auto-generated method stub
}
@Override
public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {
// TODO Auto-generated method stub
}
}