Skip to content
Snippets Groups Projects
Commit b35ec782 authored by Radek Ošlejšek's avatar Radek Ošlejšek
Browse files

Finished control panel buttons

parent 3b8cc309
No related branches found
No related tags found
No related merge requests found
......@@ -19,22 +19,22 @@ import javax.swing.JPanel;
* @author Radek Oslejsek
*/
public class Canvas extends JPanel {
private GLCanvas glCanvas;
// Scene components:
private Scene scene;
private final SceneRenderer sceneRenderer;
private final Camera camera = new Camera();
private Scene scene;
// Listeners:
private final CanvasListener listener;
private final MouseRotationListener manipulator;
private final RotationAnimator animator;
private ControlButtons controlButtonsPanel;
private JLayeredPane layeredPane;
private JPanel canvasPanel;
// GUI elements:
private final JLayeredPane layeredPane;
private final JPanel canvasPanel;
private final ControlButtons controlButtonsPanel;
private GLCanvas glCanvas;
/**
* Constructor.
......@@ -50,7 +50,7 @@ public class Canvas extends JPanel {
canvasPanel = getCanvasPanel();
canvasPanel.add(glCanvas);
controlButtonsPanel = getButtonsPanel();
controlButtonsPanel = getButtonsPanel(this);
layeredPane = getLayeredPane();
layeredPane.add(canvasPanel, 1);
......@@ -60,61 +60,9 @@ public class Canvas extends JPanel {
setDarkBackground(true);
animator = new RotationAnimator(this.glCanvas);
validate();
}
private ControlButtons getButtonsPanel() {
ControlButtonsAction controlButtonsListener = new ControlButtonsAction();
ControlButtons ret = new ControlButtons(controlButtonsListener);
ret.setOpaque(false);
ret.setBounds(20, 20, ControlButtons.SIZE.width, ControlButtons.SIZE.height);
return ret;
}
private JLayeredPane getLayeredPane() {
JLayeredPane pane = new JLayeredPane();
pane.addComponentListener(new java.awt.event.ComponentAdapter() {
@Override
public void componentResized(java.awt.event.ComponentEvent evt) {
jLayeredPane1ComponentResized(evt);
}
@Override
public void componentShown(java.awt.event.ComponentEvent evt) {
jLayeredPane1ComponentShown(evt);
}
});
return pane;
}
private JPanel getCanvasPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBounds(0, 0, 0, 0);
return panel;
}
private void initGLCanvas() {
// gl version 2 is used
GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));
capabilities.setDoubleBuffered(true);
// creates new glCanvas panel for displaying model
glCanvas = new GLCanvas(capabilities);
glCanvas.setVisible(true);
// enables glCanvas to react to events
glCanvas.requestFocusInWindow();
glCanvas.setSize(getWidth() - getInsets().left - getInsets().right, getHeight() - getInsets().top - getInsets().bottom);
glCanvas.addGLEventListener(listener);
glCanvas.addMouseListener(manipulator);
glCanvas.addMouseMotionListener(manipulator);
glCanvas.addMouseWheelListener(manipulator);
}
/**
* Initializes the scene for a single face. Can be called only once.
*
......@@ -177,6 +125,16 @@ public class Canvas extends JPanel {
return camera;
}
/**
* Returns the underlying OpenGL canvas.
*
* @return the underlying OpenGL canvas.
*/
public GLCanvas getGLCanvas() {
return this.glCanvas;
}
/**
* Sets background color
*
......@@ -192,123 +150,56 @@ public class Canvas extends JPanel {
}
}
/**
* Returns the underlying OpenGL canvas.
*
* @return the underlying OpenGL canvas.
*/
/*
public GLCanvas getGLCanvas() {
return this.glCanvas;
}*/
private ControlButtons getButtonsPanel(Canvas canvas) {
ControlButtonsAction controlButtonsListener = new ControlButtonsAction(canvas);
ControlButtons ret = new ControlButtons(controlButtonsListener);
ret.setOpaque(false);
ret.setBounds(20, 20, ControlButtons.SIZE.width, ControlButtons.SIZE.height);
return ret;
}
private JLayeredPane getLayeredPane() {
JLayeredPane pane = new JLayeredPane();
pane.addComponentListener(new java.awt.event.ComponentAdapter() {
@Override
public void componentResized(java.awt.event.ComponentEvent evt) {
canvasPanel.setBounds(0, 0, layeredPane.getWidth(), layeredPane.getHeight());
glCanvas.setBounds(layeredPane.getX(), layeredPane.getY(), layeredPane.getWidth(), layeredPane.getHeight());
}
@Override
public void componentShown(java.awt.event.ComponentEvent evt) {
canvasPanel.setBounds(0, 0, layeredPane.getWidth(), layeredPane.getHeight());
glCanvas.setBounds(layeredPane.getX(), layeredPane.getY(), layeredPane.getWidth(), layeredPane.getHeight());
}
});
return pane;
}
/**
* Changing the size of glCanvas
*
* @param d New size of glCanvas
*/
/*
public void resizeCanvas(Dimension d) {
jPanel1.setSize(d);
glCanvas.setSize(d);
this.validate();
this.repaint();
private JPanel getCanvasPanel() {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBounds(0, 0, 0, 0);
return panel;
}
*/
private void jLayeredPane1ComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jLayeredPane1ComponentResized
canvasPanel.setBounds(0, 0, layeredPane.getWidth(), layeredPane.getHeight());
glCanvas.setBounds(layeredPane.getX(), layeredPane.getY(), layeredPane.getWidth(), layeredPane.getHeight());
}//GEN-LAST:event_jLayeredPane1ComponentResized
private void jLayeredPane1ComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_jLayeredPane1ComponentShown
canvasPanel.setBounds(0, 0, layeredPane.getWidth(), layeredPane.getHeight());
glCanvas.setBounds(layeredPane.getX(), layeredPane.getY(), layeredPane.getWidth(), layeredPane.getHeight());
}//GEN-LAST:event_jLayeredPane1ComponentShown
private void leftNavigationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leftNavigationButtonMousePressed
animator.startAnimation(Direction.ROTATE_LEFT, this.camera);
//leftNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/leftButtonPressed.png")));
}//GEN-LAST:event_leftNavigationButtonMousePressed
private void upNavigationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_upNavigationButtonMousePressed
animator.startAnimation(Direction.ROTATE_UP, this.camera);
//upNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/upButtonPressed.png")));
}//GEN-LAST:event_upNavigationButtonMousePressed
private void downNavigationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_downNavigationButtonMousePressed
animator.startAnimation(Direction.ROTATE_DOWN, this.camera);
//downNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/downButtonPressed.png")));
}//GEN-LAST:event_downNavigationButtonMousePressed
private void plusNavigationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_plusNavigationButtonMousePressed
animator.startAnimation(Direction.ZOOM_IN, this.camera);
//plusNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/plusPressed.png")));
}//GEN-LAST:event_plusNavigationButtonMousePressed
private void minusNavigationButtonMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_minusNavigationButtonMousePressed
animator.startAnimation(Direction.ZOOM_OUT, this.camera);
//minusNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/minusPressed.png")));
}//GEN-LAST:event_minusNavigationButtonMousePressed
private void leftNavigationButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_leftNavigationButtonMouseReleased
animator.stopAnimation(this.camera);
//leftNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/leftButton.png")));
}//GEN-LAST:event_leftNavigationButtonMouseReleased
private void upNavigationButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_upNavigationButtonMouseReleased
animator.stopAnimation(this.camera);
//upNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/upButton.png")));
}//GEN-LAST:event_upNavigationButtonMouseReleased
private void downNavigationButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_downNavigationButtonMouseReleased
animator.stopAnimation(this.camera);
//downNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/downButton.png")));
}//GEN-LAST:event_downNavigationButtonMouseReleased
private void plusNavigationButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_plusNavigationButtonMouseReleased
animator.stopAnimation(this.camera);
//plusNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/plus.png")));
}//GEN-LAST:event_plusNavigationButtonMouseReleased
private void minusNavigationButtonMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_minusNavigationButtonMouseReleased
animator.stopAnimation(this.camera);
//minusNavigationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/minus.png")));
}//GEN-LAST:event_minusNavigationButtonMouseReleased
private void rightNavigationButton1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rightNavigationButton1MousePressed
animator.startAnimation(Direction.ROTATE_RIGHT, this.camera);
//rightNavigationButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rightButtonPressed.png")));
}//GEN-LAST:event_rightNavigationButton1MousePressed
private void rightNavigationButton1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rightNavigationButton1MouseReleased
animator.stopAnimation(this.camera);
//rightNavigationButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/rightButton.png")));
}//GEN-LAST:event_rightNavigationButton1MouseReleased
private void resetButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseClicked
camera.initLocation();
renderScene();
}//GEN-LAST:event_resetButtonMouseClicked
private void resetButtonMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseMoved
//resetButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resetButtonPressed.png")));
//resetButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}//GEN-LAST:event_resetButtonMouseMoved
private void initGLCanvas() {
// gl version 2 is used
GLCapabilities capabilities = new GLCapabilities(GLProfile.get(GLProfile.GL2));
capabilities.setDoubleBuffered(true);
// creates new glCanvas panel for displaying model
glCanvas = new GLCanvas(capabilities);
glCanvas.setVisible(true);
// enables glCanvas to react to events
glCanvas.requestFocusInWindow();
glCanvas.setSize(getWidth() - getInsets().left - getInsets().right, getHeight() - getInsets().top - getInsets().bottom);
private void resetButtonMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_resetButtonMouseExited
//resetButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resetButton.png")));
}//GEN-LAST:event_resetButtonMouseExited
glCanvas.addGLEventListener(listener);
// Variables declaration - do not modify//GEN-BEGIN:variables
//private javax.swing.JButton downNavigationButton;
//private javax.swing.JLabel jLabel1;
//private javax.swing.JButton leftNavigationButton;
//private javax.swing.JButton minusNavigationButton;
//private javax.swing.JButton plusNavigationButton;
//private javax.swing.JLabel resetButton;
//private javax.swing.JButton rightNavigationButton1;
//private javax.swing.JButton upNavigationButton;
// End of variables declaration//GEN-END:variables
glCanvas.addMouseListener(manipulator);
glCanvas.addMouseMotionListener(manipulator);
glCanvas.addMouseWheelListener(manipulator);
}
}
......@@ -23,6 +23,23 @@ public class ControlButtonsAction extends AbstractAction {
public static final String ACTION_COMMAND_MINUS_PRESSED = "zoom out pressed";
public static final String ACTION_COMMAND_MINUS_RELEASED = "zoom out released";
public static final String ACTION_COMMAND_RESET = "reset";
private final RotationAnimator animator;
private final Canvas canvas;
/**
* Constructor.
*
* @param canvas OpenGL canvas
* @throws IllegalArgumentException if some param is missing
*/
public ControlButtonsAction(Canvas canvas) {
if (canvas == null) {
throw new IllegalArgumentException("canvas");
}
this.canvas = canvas;
this.animator = new RotationAnimator(canvas.getGLCanvas());
}
@Override
public void actionPerformed(ActionEvent e) {
......@@ -30,33 +47,37 @@ public class ControlButtonsAction extends AbstractAction {
switch (command) {
case ACTION_COMMAND_LEFT_PRESSED:
break;
case ACTION_COMMAND_LEFT_RELEASED:
animator.startAnimation(Direction.ROTATE_LEFT, canvas.getCamera());
break;
case ACTION_COMMAND_RIGHT_PRESSED:
break;
case ACTION_COMMAND_RIGHT_RELEASED:
animator.startAnimation(Direction.ROTATE_RIGHT, canvas.getCamera());
break;
case ACTION_COMMAND_UP_PRESSED:
break;
case ACTION_COMMAND_UP_RELEASED:
animator.startAnimation(Direction.ROTATE_UP, canvas.getCamera());
break;
case ACTION_COMMAND_DOWN_PRESSED:
break;
case ACTION_COMMAND_DOWN_RELEASED:
animator.startAnimation(Direction.ROTATE_DOWN, canvas.getCamera());
break;
case ACTION_COMMAND_RESET:
canvas.getCamera().initLocation();
canvas.renderScene();
break;
case ACTION_COMMAND_PLUS_PRESSED:
break;
case ACTION_COMMAND_PLUS_RELEASED:
animator.startAnimation(Direction.ZOOM_IN, canvas.getCamera());
break;
case ACTION_COMMAND_MINUS_PRESSED:
animator.startAnimation(Direction.ZOOM_OUT, canvas.getCamera());
break;
case ACTION_COMMAND_LEFT_RELEASED:
case ACTION_COMMAND_RIGHT_RELEASED:
case ACTION_COMMAND_UP_RELEASED:
case ACTION_COMMAND_DOWN_RELEASED:
case ACTION_COMMAND_PLUS_RELEASED:
case ACTION_COMMAND_MINUS_RELEASED:
animator.stopAnimation(canvas.getCamera());
break;
default:
throw new UnsupportedOperationException(command);
// do nothing
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment