Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SwingEasel.java
- // SwingEasel
- //
- // Created by Philip Rhodes on 8/3/05.
- // Copyright (c) 2005 Philip J Rhodes. All rights reserved.
- //
- // For information on setting Java configuration information, including
- // setting Java properties, refer to the documentation at
- // http://developer.apple.com/techpubs/java/java.html
- //
- import java.util.Locale;
- import java.util.ResourceBundle;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.KeyEvent;
- import javax.swing.*;
- public class SwingEasel extends JFrame {
- protected Action newAction, openAction, closeAction, saveAction, saveAsAction, quitAction,
- undoAction, cutAction, copyAction, pasteAction, clearAction, selectAllAction;
- static final JMenuBar mainMenuBar = new JMenuBar();
- protected JMenu fileMenu, editMenu;
- public SwingEasel() {
- super("Easel");
- this.getContentPane().setLayout(null);
- this.setBackground(Color.gray);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- createActions();
- addMenus();
- setSize(1200, 800); // Set the window size
- Shape s1 = new Sphere(300, 16, 16);
- Shape s2 = new Cube(50);
- Shape s3 = new Cylinder(100, 300, 15, 5);
- Shape s4 = new Cube(200);
- Shape s5 = new Tetrahedron(100);
- Shape s6 = new Sphere(100, 4, 2);
- Shape s7 = new Sphere(50, 5, 3);
- s1.setXRotation(45 * Math.PI / 180);
- s2.setTranslation(500, 0, 0);
- s2.setZRotation(45 * Math.PI / 180);
- s3.setTranslation(0, -150, 0);
- s3.setZRotation(10 * Math.PI / 180);
- s4.setTranslation(-100, -100, -100);
- s4.setXRotation(10 * Math.PI / 180);
- s5.setTranslation(0, 50, 0);
- s5.setXRotation(10 * Math.PI / 180);
- s6.setXRotation(10 * Math.PI / 180);
- s7.setXRotation(10 * Math.PI / 180);
- World w = new World();
- w.addShape(s1, -200, 0, 0);
- w.addShape(s2, -200, 0, 0);
- w.addShape(s3, 375, 200, 0);
- w.addShape(s4, 250, -200, 0);
- w.addShape(s5, 0, -400, 0);
- w.addShape(s6, 150, 200, 0);
- w.addShape(s7, -430, 300, 0);
- // Make a 1024x768 Renderer with fps display
- Renderer r = new SimpleRenderer(w, 1024, 768, true);
- this.getContentPane().add(r);
- r.setLocation(5, 5);
- setVisible(true); // Call this BEFORE calling r.init()
- r.init();
- double theta=0;
- while(true){
- s1.setYRotation(theta);
- s2.setYRotation(5 * theta);
- s3.setXRotation(theta);
- s4.setYRotation(theta);
- s5.setYRotation(theta);
- s6.setYRotation(theta);
- s7.setYRotation(theta);
- r.render();
- theta += 0.01;
- }
- }
- public void createActions() {
- int shortcutKeyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
- //Create actions that can be used by menus, buttons, toolbars, etc.
- newAction = new newActionClass( "New",
- KeyStroke.getKeyStroke(KeyEvent.VK_N, shortcutKeyMask) );
- openAction = new openActionClass( "Open",
- KeyStroke.getKeyStroke(KeyEvent.VK_O, shortcutKeyMask) );
- closeAction = new closeActionClass( "Close",
- KeyStroke.getKeyStroke(KeyEvent.VK_W, shortcutKeyMask) );
- saveAction = new saveActionClass("Save",
- KeyStroke.getKeyStroke(KeyEvent.VK_S, shortcutKeyMask) );
- saveAsAction = new saveAsActionClass( "Save As" );
- quitAction = new quitActionClass("Quit",
- KeyStroke.getKeyStroke(KeyEvent.VK_Q, shortcutKeyMask) );
- undoAction = new undoActionClass( "Undo",
- KeyStroke.getKeyStroke(KeyEvent.VK_Z, shortcutKeyMask) );
- cutAction = new cutActionClass( "Cut",
- KeyStroke.getKeyStroke(KeyEvent.VK_X, shortcutKeyMask) );
- copyAction = new copyActionClass( "Copy",
- KeyStroke.getKeyStroke(KeyEvent.VK_C, shortcutKeyMask) );
- pasteAction = new pasteActionClass( "Paste",
- KeyStroke.getKeyStroke(KeyEvent.VK_V, shortcutKeyMask) );
- clearAction = new clearActionClass( "Clear" );
- selectAllAction = new selectAllActionClass( "Select All",
- KeyStroke.getKeyStroke(KeyEvent.VK_A, shortcutKeyMask) );
- }
- public void addMenus() {
- fileMenu = new JMenu("File");
- fileMenu.add(new JMenuItem(newAction));
- fileMenu.add(new JMenuItem(openAction));
- fileMenu.add(new JMenuItem(closeAction));
- fileMenu.add(new JMenuItem(saveAction));
- fileMenu.add(new JMenuItem(saveAsAction));
- fileMenu.add(new JMenuItem(quitAction));
- mainMenuBar.add(fileMenu);
- editMenu = new JMenu("Edit");
- editMenu.add(new JMenuItem(undoAction));
- editMenu.addSeparator();
- editMenu.add(new JMenuItem(cutAction));
- editMenu.add(new JMenuItem(copyAction));
- editMenu.add(new JMenuItem(pasteAction));
- editMenu.add(new JMenuItem(clearAction));
- editMenu.addSeparator();
- editMenu.add(new JMenuItem(selectAllAction));
- mainMenuBar.add(editMenu);
- setJMenuBar (mainMenuBar);
- }
- public class newActionClass extends AbstractAction {
- public newActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("New...");
- }
- }
- public class openActionClass extends AbstractAction {
- public openActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Open...");
- }
- }
- public class closeActionClass extends AbstractAction {
- public closeActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Close...");
- }
- }
- public class saveActionClass extends AbstractAction {
- public saveActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Save...");
- }
- }
- public class saveAsActionClass extends AbstractAction {
- public saveAsActionClass(String text) {
- super(text);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Save As...");
- }
- }
- public class quitActionClass extends AbstractAction {
- public quitActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- }
- public class undoActionClass extends AbstractAction {
- public undoActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Undo...");
- }
- }
- public class cutActionClass extends AbstractAction {
- public cutActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Cut...");
- }
- }
- public class copyActionClass extends AbstractAction {
- public copyActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Copy...");
- }
- }
- public class pasteActionClass extends AbstractAction {
- public pasteActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Paste...");
- }
- }
- public class clearActionClass extends AbstractAction {
- public clearActionClass(String text) {
- super(text);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Clear...");
- }
- }
- public class selectAllActionClass extends AbstractAction {
- public selectAllActionClass(String text, KeyStroke shortcut) {
- super(text);
- putValue(ACCELERATOR_KEY, shortcut);
- }
- public void actionPerformed(ActionEvent e) {
- System.out.println("Select All...");
- }
- }
- public static void main(String args[]) {
- new SwingEasel();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement