0001: /*
0002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/J3dEdit.java,v 1.3 2007/03/16 22:50:12 paulby Exp $
0003: *
0004: * Sun Public License Notice
0005: *
0006: * The contents of this file are subject to the Sun Public License Version
0007: * 1.0 (the "License"). You may not use this file except in compliance with
0008: * the License. A copy of the License is available at http://www.sun.com/
0009: *
0010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
0011: * The Initial Developer of the Original Code is Paul Byrne.
0012: * Portions created by Paul Byrne are Copyright (C) 2002.
0013: * All Rights Reserved.
0014: *
0015: * Contributor(s): Paul Byrne.
0016: *
0017: **/
0018: package org.jdesktop.j3dedit;
0019:
0020: import java.util.Enumeration;
0021: import java.util.Iterator;
0022: import javax.media.j3d.*;
0023: import javax.vecmath.Point3d;
0024: import javax.vecmath.Point3f;
0025: import java.awt.Point;
0026: import java.awt.Cursor;
0027: import java.io.*;
0028: import java.awt.event.KeyEvent;
0029: import javax.swing.KeyStroke;
0030: import java.util.ArrayList;
0031:
0032: import com.sun.j3d.utils.behaviors.interpolators.KBKeyFrame;
0033: import com.sun.j3d.utils.behaviors.interpolators.KBRotPosScaleSplinePathInterpolator;
0034: import org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale;
0035: import org.jdesktop.j3dfly.utils.gui.SplashWindow;
0036: import org.jdesktop.j3dfly.J3dFlyController;
0037: import org.jdesktop.j3dedit.scenegrapheditor.ConfigLoader;
0038: import org.jdesktop.j3dedit.scenegrapheditor.sourcecontrol.ClassGenerator;
0039: import org.jdesktop.j3dedit.scenegraph.SGLocale;
0040: import org.jdesktop.j3dfly.utils.loadercontrol.ManifestParser;
0041: import org.jdesktop.j3dedit.scenegrapheditor.InterposerListener;
0042: import org.jdesktop.j3dedit.interposer.InterposerUniverse;
0043: import org.jdesktop.j3dedit.interposer.InterposerLocale;
0044:
0045: import org.jdesktop.j3dfly.utils.gui.ErrorManager;
0046: import org.jdesktop.j3dfly.utils.gui.ErrorHandler;
0047:
0048: import org.jdesktop.j3dedit.actions.ActionManager;
0049: import org.jdesktop.j3dedit.actions.CutAction;
0050: import org.jdesktop.j3dedit.actions.CopyAction;
0051: import org.jdesktop.j3dedit.actions.PasteAction;
0052: import org.jdesktop.j3dedit.actions.DeleteAction;
0053: import org.jdesktop.j3dedit.editormodules.J3dFlyEditorModule;
0054: import org.jdesktop.j3dedit.editormodules.AbstractEditorModule;
0055: import org.jdesktop.j3dedit.editormodules.LocationEditorModule;
0056: import org.jdesktop.j3dedit.editormodules.SceneGraphEditorModule;
0057:
0058: /**
0059: * The main class for the editor
0060: *
0061: * @author Paul Byrne
0062: * @version $id$
0063: */
0064: public class J3dEdit extends javax.swing.JFrame implements
0065: ManifestParser.ManifestListener {
0066:
0067: private boolean readOnly = false;
0068:
0069: private J3dFlyEditorModule flyModule;
0070: //private AnimationEditorModule animModule;
0071: private SceneGraphEditorModule graphModule;
0072: private LocationEditorModule locationModule;
0073: private AbstractEditorModule currentModule = null;
0074:
0075: private J3dFlyController j3dflyController;
0076: private EditorControlFrame editorControlFrame;
0077:
0078: private File projectFile = null; // File for current project
0079:
0080: private org.jdesktop.j3dedit.interposerext.InterposerCallbacks interposer = null;
0081: private javax.media.j3d.Locale locale = null;
0082:
0083: /**
0084: * Constructor used by interposer
0085: */
0086: public J3dEdit(
0087: org.jdesktop.j3dedit.interposerext.InterposerCallbacks interposer,
0088: Object locale) {
0089: super ();
0090: this .interposer = interposer;
0091: this .locale = (javax.media.j3d.Locale) locale;
0092: InterposerListener listener = new InterposerListener();
0093: InterposerUniverse universeWrapper = new InterposerUniverse(
0094: this .locale.getVirtualUniverse(), new InterposerLocale(
0095: this .locale));
0096: startEditor(null, universeWrapper);
0097: listener.setContext(flyModule.getContext());
0098:
0099: // This call must be made after the listener context has been set and after
0100: // the editor
0101: interposer.setInterposerListener(listener);
0102:
0103: // This needs to be called after InterposerListener has been set
0104: universeWrapper.finishHiddenLocaleInit(flyModule.getContext());
0105: }
0106:
0107: /**
0108: * Universe MUST contain DevelopmentLocales
0109: */
0110: public J3dEdit(VirtualUniverse universe) {
0111: super ();
0112: Enumeration it = universe.getAllLocales();
0113: this .locale = (DevelopmentLocale) it.nextElement();
0114: assert (this .locale instanceof DevelopmentLocale);
0115:
0116: InterposerUniverse universeWrapper = new InterposerUniverse(
0117: this .locale.getVirtualUniverse(),
0118: (DevelopmentLocale) this .locale);
0119: startEditor(null, universeWrapper);
0120:
0121: new GraphChangeListener((DevelopmentLocale) locale);
0122:
0123: }
0124:
0125: /** Creates new form Editor */
0126: public J3dEdit(String[] args) {
0127: super ();
0128: startEditor(args, null);
0129: }
0130:
0131: private void startEditor(String[] args,
0132: InterposerUniverse universeWrapper) {
0133: SplashWindow
0134: .showSplashscreen("org/jdesktop/j3dedit/splash.jpg");
0135: SplashWindow.showMessage("Initialising GUI");
0136:
0137: // copyCutPasteDeleteActions must be instantiated before the call
0138: // to initComponents so that the menu actions are defined
0139: CopyCutPasteDeleteActions copyCutPasteDeleteActions = new CopyCutPasteDeleteActions();
0140: initComponents();
0141:
0142: this .setTitle("Java 3D(tm) Scene Graph Editor 2.0 alpha "
0143: + Version.version);
0144:
0145: menuBar.remove(fileMenu);
0146: menuBar.remove(editMenu);
0147: menuBar.remove(viewMenu);
0148: menuBar.remove(packageMenu);
0149: menuBar.remove(helpMenu);
0150:
0151: mainToolbarP.add(copyCutPasteDeleteActions.getToolBar());
0152:
0153: // TODO
0154: // setHelpMenu is not yet implemented in JDK 1.4
0155: //menuBar.remove( helpMenu );
0156: //menuBar.setHelpMenu( helpMenu );
0157:
0158: SplashWindow.showMessage("Loading Config");
0159: ConfigLoader config = new ConfigLoader();
0160:
0161: SplashWindow.showMessage("Initializing Modules");
0162: flyModule = new J3dFlyEditorModule(this , j3dflyToolbarsP,
0163: universeWrapper);
0164: flyModule.getContext().setConfigLoader(config);
0165:
0166: //animModule = new AnimationEditorModule( this, flyModule );
0167: graphModule = new SceneGraphEditorModule(this , flyModule);
0168: locationModule = new LocationEditorModule(this , flyModule);
0169: currentModule = null;
0170:
0171: if (interposer == null)
0172: checkLoaderManifests();
0173:
0174: // TODO Reorder the menus
0175: menuBar.add(editMenu);
0176: menuBar.add(viewMenu);
0177: menuBar.add(packageMenu);
0178: menuBar.add(helpMenu);
0179:
0180: flyModule.populateMenuBar(menuBar);
0181: //animModule.populateMenuBar( menuBar );
0182: graphModule.populateMenuBar(menuBar);
0183:
0184: locationModule.populateMenuBar(menuBar);
0185:
0186: // Make all menus heavyweight
0187: javax.swing.JPopupMenu.setDefaultLightWeightPopupEnabled(false);
0188:
0189: pack(); // Pack so modules can tell how big this frame is
0190:
0191: SplashWindow.showMessage("Installing Modules");
0192: installModules();
0193:
0194: if (universeWrapper == null) {
0195: j3dflyController = flyModule.getController();
0196:
0197: // Add some default branch graphs
0198: // TODO allow the user to add BranchGraphs to the Locale
0199: j3dflyController.addBranchGraph(new BranchGroup());
0200: j3dflyController.addBranchGraph(new BranchGroup());
0201: }
0202:
0203: if (args != null && args.length != 0) {
0204: SplashWindow.showMessage("Loading Project " + args[0]);
0205: projectFile = new File(args[0]);
0206: j3dflyController.loadGeometry(projectFile);
0207: setWindowTitle();
0208: saveM.setEnabled(true);
0209: }
0210:
0211: SplashWindow.destroySplashscreen();
0212: }
0213:
0214: /**
0215: * Check the loader manifests for any Editor setup information
0216: */
0217: private void checkLoaderManifests() {
0218: System.out.println("Editor Checking Manifests");
0219: java.net.URL[] urls = flyModule.getContext().getJ3dFly()
0220: .getController().getLoaderControl().getClassLoader()
0221: .getURLs();
0222: for (int i = 0; i < urls.length; i++)
0223: if (urls[i].getFile().toLowerCase().endsWith(".jar")) {
0224: try {
0225: //System.out.println("CHecking url "+urls[i]);
0226: ManifestParser
0227: .processMainAttributes(
0228: new java.util.jar.JarFile(urls[i]
0229: .getFile()),
0230: new String[] { "J3dEditor-Config" },
0231: this );
0232: } catch (java.io.IOException e) {
0233: ErrorManager.getDefault().notify(e,
0234: ErrorHandler.INFORMATIONAL,
0235: "Error with jar " + urls[i]);
0236: }
0237: }
0238:
0239: }
0240:
0241: /**
0242: * Listener for ManifestParser
0243: */
0244: public void foundManifestAttribute(String name, String value) {
0245: //System.out.println("Editor Found "+name+" "+value);
0246: ClassLoader classLoader = flyModule.getContext().getJ3dFly()
0247: .getController().getLoaderControl().getClassLoader();
0248: InputStream in = classLoader.getResourceAsStream(value);
0249: //System.out.println("Resource "+in);
0250: flyModule.getContext().getConfigLoader().addConfig(in,
0251: classLoader);
0252: }
0253:
0254: /**
0255: * Returns the editors View Menu
0256: */
0257: public javax.swing.JMenu getViewMenu() {
0258: return viewMenu;
0259: }
0260:
0261: /**
0262: * Return the current context
0263: */
0264: public J3dEditContext getContext() {
0265: return flyModule.getContext();
0266: }
0267:
0268: private void installModules() {
0269: javax.swing.ButtonGroup modeGroup = new javax.swing.ButtonGroup();
0270:
0271: modeGroup.add(viewUniverseB);
0272: modeGroup.add(editSceneGraphB);
0273: //modeGroup.add( editAnimationB );
0274: modeGroup.add(editPositionB);
0275:
0276: editorControlFrame = new EditorControlFrame(flyModule
0277: .getContext());
0278: editorControlFrame.setBounds(0, this .getHeight(), 200, 500);
0279: editorControlFrame.setVisible(true);
0280:
0281: pack();
0282: setVisible(true);
0283: viewUniverseB.setSelected(true);
0284: graphModule.setActive(true);
0285: currentModule = graphModule;
0286: editSceneGraphB.setSelected(true);
0287: }
0288:
0289: /**
0290: * Get the panel on the left of the control window in which
0291: * module toolbars can be placed
0292: */
0293: public javax.swing.JPanel getLeftToolbarPanel() {
0294: return leftToolbarP;
0295: }
0296:
0297: public EditorControlFrame getEditorControlFrame() {
0298: return editorControlFrame;
0299: }
0300:
0301: /** This method is called from within the constructor to
0302: * initialize the form.
0303: * WARNING: Do NOT modify this code. The content of this method is
0304: * always regenerated by the FormEditor.
0305: */
0306: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0307: private void initComponents() {
0308: java.awt.GridBagConstraints gridBagConstraints;
0309:
0310: modePanel = new javax.swing.JPanel();
0311: viewUniverseB = new javax.swing.JToggleButton();
0312: editSceneGraphB = new javax.swing.JToggleButton();
0313: editPositionB = new javax.swing.JToggleButton();
0314: editAnimationB = new javax.swing.JToggleButton();
0315: leftToolbarP = new javax.swing.JPanel();
0316: j3dflyToolbarsP = new javax.swing.JPanel();
0317: mainToolbarP = new javax.swing.JPanel();
0318: leftToolbars = new javax.swing.JToolBar();
0319: loadB = new javax.swing.JButton();
0320: saveB = new javax.swing.JButton();
0321: jSeparator7 = new javax.swing.JSeparator();
0322: zoomInB = new javax.swing.JButton();
0323: zoomOutB = new javax.swing.JButton();
0324: menuBar = new javax.swing.JMenuBar();
0325: fileMenu = new javax.swing.JMenu();
0326: loadM = new javax.swing.JMenuItem();
0327: importM = new javax.swing.JMenuItem();
0328: configureLoadersM = new javax.swing.JMenuItem();
0329: saveM = new javax.swing.JMenuItem();
0330: saveAsM = new javax.swing.JMenuItem();
0331: jSeparator3 = new javax.swing.JSeparator();
0332: newGraphM = new javax.swing.JMenu();
0333: newSimpleSceneGraphMI = new javax.swing.JMenuItem();
0334: newInterpTestMI = new javax.swing.JMenuItem();
0335: jSeparator4 = new javax.swing.JSeparator();
0336: exitM = new javax.swing.JMenuItem();
0337: editMenu = new javax.swing.JMenu();
0338: cutM = new javax.swing.JMenuItem();
0339: copyM = new javax.swing.JMenuItem();
0340: pasteM = new javax.swing.JMenuItem();
0341: deleteM = new javax.swing.JMenuItem();
0342: jSeparator5 = new javax.swing.JSeparator();
0343: propertiesM = new javax.swing.JMenuItem();
0344: viewMenu = new javax.swing.JMenu();
0345: updateGraphM = new javax.swing.JMenuItem();
0346: universeRunningMI = new javax.swing.JCheckBoxMenuItem();
0347: packageMenu = new javax.swing.JMenu();
0348: generateSourceM = new javax.swing.JMenuItem();
0349: generateJarM = new javax.swing.JMenuItem();
0350: helpMenu = new javax.swing.JMenu();
0351: aboutM = new javax.swing.JMenuItem();
0352:
0353: getContentPane().setLayout(new java.awt.GridBagLayout());
0354:
0355: setName("editorFrame");
0356: addWindowListener(new java.awt.event.WindowAdapter() {
0357: public void windowClosing(java.awt.event.WindowEvent evt) {
0358: exitForm(evt);
0359: }
0360: });
0361:
0362: modePanel.setLayout(new java.awt.GridBagLayout());
0363:
0364: modePanel.setBorder(new javax.swing.border.EtchedBorder());
0365: viewUniverseB.setText("View Universe");
0366: viewUniverseB.setMargin(new java.awt.Insets(2, 2, 2, 2));
0367: viewUniverseB
0368: .addActionListener(new java.awt.event.ActionListener() {
0369: public void actionPerformed(
0370: java.awt.event.ActionEvent evt) {
0371: modeSelectionActionPerformed(evt);
0372: }
0373: });
0374:
0375: modePanel.add(viewUniverseB, new java.awt.GridBagConstraints());
0376:
0377: editSceneGraphB.setText("Edit Scene Graph");
0378: editSceneGraphB.setMargin(new java.awt.Insets(2, 2, 2, 2));
0379: editSceneGraphB
0380: .addActionListener(new java.awt.event.ActionListener() {
0381: public void actionPerformed(
0382: java.awt.event.ActionEvent evt) {
0383: modeSelectionActionPerformed(evt);
0384: }
0385: });
0386:
0387: modePanel.add(editSceneGraphB,
0388: new java.awt.GridBagConstraints());
0389:
0390: editPositionB.setText("Position Editor");
0391: editPositionB.setMargin(new java.awt.Insets(2, 2, 2, 2));
0392: editPositionB
0393: .addActionListener(new java.awt.event.ActionListener() {
0394: public void actionPerformed(
0395: java.awt.event.ActionEvent evt) {
0396: modeSelectionActionPerformed(evt);
0397: }
0398: });
0399:
0400: modePanel.add(editPositionB, new java.awt.GridBagConstraints());
0401:
0402: editAnimationB.setText("Edit Animation");
0403: editAnimationB.setMargin(new java.awt.Insets(2, 2, 2, 2));
0404: editAnimationB.setEnabled(false);
0405: editAnimationB
0406: .addActionListener(new java.awt.event.ActionListener() {
0407: public void actionPerformed(
0408: java.awt.event.ActionEvent evt) {
0409: modeSelectionActionPerformed(evt);
0410: }
0411: });
0412:
0413: modePanel
0414: .add(editAnimationB, new java.awt.GridBagConstraints());
0415:
0416: gridBagConstraints = new java.awt.GridBagConstraints();
0417: gridBagConstraints.gridx = 0;
0418: gridBagConstraints.gridy = 2;
0419: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0420: getContentPane().add(modePanel, gridBagConstraints);
0421:
0422: gridBagConstraints = new java.awt.GridBagConstraints();
0423: gridBagConstraints.gridx = 1;
0424: gridBagConstraints.gridy = 0;
0425: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
0426: gridBagConstraints.gridheight = 2;
0427: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0428: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0429: getContentPane().add(leftToolbarP, gridBagConstraints);
0430:
0431: j3dflyToolbarsP.setLayout(new java.awt.FlowLayout(
0432: java.awt.FlowLayout.CENTER, 0, 2));
0433:
0434: gridBagConstraints = new java.awt.GridBagConstraints();
0435: gridBagConstraints.gridx = 0;
0436: gridBagConstraints.gridy = 1;
0437: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0438: getContentPane().add(j3dflyToolbarsP, gridBagConstraints);
0439:
0440: mainToolbarP.setLayout(new java.awt.FlowLayout(
0441: java.awt.FlowLayout.CENTER, 0, 2));
0442:
0443: loadB
0444: .setIcon(new javax.swing.ImageIcon(
0445: getClass()
0446: .getResource(
0447: "/org/jdesktop/j3dedit/scenegrapheditor/resources/JavaLookAndFeel/toolbarButtonGraphics/general/Open16.gif")));
0448: loadB.setToolTipText("Load a New Scenegraph");
0449: loadB.setMaximumSize(new java.awt.Dimension(28, 28));
0450: loadB.setMinimumSize(new java.awt.Dimension(28, 28));
0451: loadB.setPreferredSize(new java.awt.Dimension(28, 28));
0452: loadB.addActionListener(new java.awt.event.ActionListener() {
0453: public void actionPerformed(java.awt.event.ActionEvent evt) {
0454: loadActionPerformed(evt);
0455: }
0456: });
0457:
0458: leftToolbars.add(loadB);
0459:
0460: saveB
0461: .setIcon(new javax.swing.ImageIcon(
0462: getClass()
0463: .getResource(
0464: "/org/jdesktop/j3dedit/scenegrapheditor/resources/JavaLookAndFeel/toolbarButtonGraphics/general/Save16.gif")));
0465: saveB.setToolTipText("Save the scenegraph");
0466: saveB.setMaximumSize(new java.awt.Dimension(28, 28));
0467: saveB.setMinimumSize(new java.awt.Dimension(28, 28));
0468: saveB.setPreferredSize(new java.awt.Dimension(28, 28));
0469: saveB.addActionListener(new java.awt.event.ActionListener() {
0470: public void actionPerformed(java.awt.event.ActionEvent evt) {
0471: saveActionPerformed(evt);
0472: }
0473: });
0474:
0475: leftToolbars.add(saveB);
0476:
0477: jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);
0478: jSeparator7.setBorder(new javax.swing.border.EtchedBorder());
0479: jSeparator7.setMinimumSize(new java.awt.Dimension(2, 0));
0480: leftToolbars.add(jSeparator7);
0481:
0482: zoomInB
0483: .setIcon(new javax.swing.ImageIcon(
0484: getClass()
0485: .getResource(
0486: "/org/jdesktop/j3dedit/scenegrapheditor/resources/JavaLookAndFeel/toolbarButtonGraphics/general/ZoomIn16.gif")));
0487: zoomInB.setToolTipText("Zoom In");
0488: zoomInB.setMaximumSize(new java.awt.Dimension(28, 28));
0489: zoomInB.setMinimumSize(new java.awt.Dimension(28, 28));
0490: zoomInB.setPreferredSize(new java.awt.Dimension(28, 28));
0491: zoomInB.setEnabled(false);
0492: zoomInB.addActionListener(new java.awt.event.ActionListener() {
0493: public void actionPerformed(java.awt.event.ActionEvent evt) {
0494: zoomActionPerformed(evt);
0495: }
0496: });
0497:
0498: leftToolbars.add(zoomInB);
0499:
0500: zoomOutB
0501: .setIcon(new javax.swing.ImageIcon(
0502: getClass()
0503: .getResource(
0504: "/org/jdesktop/j3dedit/scenegrapheditor/resources/JavaLookAndFeel/toolbarButtonGraphics/general/ZoomOut16.gif")));
0505: zoomOutB.setToolTipText("Zoom Out");
0506: zoomOutB.setMaximumSize(new java.awt.Dimension(28, 28));
0507: zoomOutB.setMinimumSize(new java.awt.Dimension(28, 28));
0508: zoomOutB.setPreferredSize(new java.awt.Dimension(28, 28));
0509: zoomOutB.setEnabled(false);
0510: zoomOutB.addActionListener(new java.awt.event.ActionListener() {
0511: public void actionPerformed(java.awt.event.ActionEvent evt) {
0512: zoomActionPerformed(evt);
0513: }
0514: });
0515:
0516: leftToolbars.add(zoomOutB);
0517:
0518: mainToolbarP.add(leftToolbars);
0519:
0520: gridBagConstraints = new java.awt.GridBagConstraints();
0521: gridBagConstraints.gridx = 0;
0522: gridBagConstraints.gridy = 0;
0523: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
0524: getContentPane().add(mainToolbarP, gridBagConstraints);
0525:
0526: fileMenu.setMnemonic('F');
0527: fileMenu.setText("File");
0528: loadM.setMnemonic('L');
0529: loadM.setText("Load ...");
0530: loadM.setToolTipText("Load a new scene");
0531: loadM.addActionListener(new java.awt.event.ActionListener() {
0532: public void actionPerformed(java.awt.event.ActionEvent evt) {
0533: loadActionPerformed(evt);
0534: }
0535: });
0536:
0537: fileMenu.add(loadM);
0538:
0539: importM.setMnemonic('I');
0540: importM.setText("Import...");
0541: importM.setToolTipText("Import an object to the scene");
0542: importM.addActionListener(new java.awt.event.ActionListener() {
0543: public void actionPerformed(java.awt.event.ActionEvent evt) {
0544: importMActionPerformed(evt);
0545: }
0546: });
0547:
0548: fileMenu.add(importM);
0549:
0550: configureLoadersM.setText("Configure Loaders...");
0551: configureLoadersM
0552: .addActionListener(new java.awt.event.ActionListener() {
0553: public void actionPerformed(
0554: java.awt.event.ActionEvent evt) {
0555: configureLoadersMActionPerformed(evt);
0556: }
0557: });
0558:
0559: fileMenu.add(configureLoadersM);
0560:
0561: saveM.setMnemonic('S');
0562: saveM.setText("Save");
0563: saveM.setEnabled(false);
0564: saveM.addActionListener(new java.awt.event.ActionListener() {
0565: public void actionPerformed(java.awt.event.ActionEvent evt) {
0566: saveActionPerformed(evt);
0567: }
0568: });
0569:
0570: fileMenu.add(saveM);
0571:
0572: saveAsM.setText("Save As...");
0573: saveAsM.addActionListener(new java.awt.event.ActionListener() {
0574: public void actionPerformed(java.awt.event.ActionEvent evt) {
0575: saveAsActionPerformed(evt);
0576: }
0577: });
0578:
0579: fileMenu.add(saveAsM);
0580:
0581: fileMenu.add(jSeparator3);
0582:
0583: newGraphM.setText("New Universe");
0584: newSimpleSceneGraphMI.setText("Simple Universe");
0585: newSimpleSceneGraphMI
0586: .addActionListener(new java.awt.event.ActionListener() {
0587: public void actionPerformed(
0588: java.awt.event.ActionEvent evt) {
0589: newSimpleSceneGraphMIActionPerformed(evt);
0590: }
0591: });
0592:
0593: newGraphM.add(newSimpleSceneGraphMI);
0594:
0595: newInterpTestMI.setText("Iterpolator Test");
0596: newInterpTestMI
0597: .addActionListener(new java.awt.event.ActionListener() {
0598: public void actionPerformed(
0599: java.awt.event.ActionEvent evt) {
0600: newInterpTestMIActionPerformed(evt);
0601: }
0602: });
0603:
0604: newGraphM.add(newInterpTestMI);
0605:
0606: fileMenu.add(newGraphM);
0607:
0608: fileMenu.add(jSeparator4);
0609:
0610: exitM.setMnemonic('X');
0611: exitM.setText("Exit");
0612: exitM.addActionListener(new java.awt.event.ActionListener() {
0613: public void actionPerformed(java.awt.event.ActionEvent evt) {
0614: exitActionPerformed(evt);
0615: }
0616: });
0617:
0618: fileMenu.add(exitM);
0619:
0620: menuBar.add(fileMenu);
0621:
0622: editMenu.setMnemonic('E');
0623: editMenu.setLabel("Edit");
0624: cutM.setMnemonic('T');
0625: cutM.setAction(ActionManager.getAction(CutAction.class));
0626: cutM.setEnabled(false);
0627: editMenu.add(cutM);
0628:
0629: copyM.setAction(ActionManager.getAction(CopyAction.class));
0630: copyM.setEnabled(false);
0631: editMenu.add(copyM);
0632:
0633: pasteM.setAction(ActionManager.getAction(PasteAction.class));
0634: pasteM.setEnabled(false);
0635: editMenu.add(pasteM);
0636:
0637: deleteM.setAction(ActionManager.getAction(DeleteAction.class));
0638: deleteM.setEnabled(false);
0639: editMenu.add(deleteM);
0640:
0641: editMenu.add(jSeparator5);
0642:
0643: propertiesM.setText("Properties...");
0644: propertiesM
0645: .addActionListener(new java.awt.event.ActionListener() {
0646: public void actionPerformed(
0647: java.awt.event.ActionEvent evt) {
0648: propertiesMActionPerformed(evt);
0649: }
0650: });
0651:
0652: editMenu.add(propertiesM);
0653:
0654: menuBar.add(editMenu);
0655:
0656: viewMenu.setMnemonic('V');
0657: viewMenu.setText("View");
0658: updateGraphM.setText("Update Scene Graph - not implemented");
0659: updateGraphM
0660: .setToolTipText("Traverse the running SceneGraph and update the tree view");
0661: updateGraphM
0662: .addActionListener(new java.awt.event.ActionListener() {
0663: public void actionPerformed(
0664: java.awt.event.ActionEvent evt) {
0665: updateGraphMActionPerformed(evt);
0666: }
0667: });
0668:
0669: viewMenu.add(updateGraphM);
0670:
0671: universeRunningMI.setSelected(true);
0672: universeRunningMI.setText("Universe Live");
0673: universeRunningMI
0674: .setToolTipText("Enable/Disable the 3D Universe");
0675: universeRunningMI
0676: .addActionListener(new java.awt.event.ActionListener() {
0677: public void actionPerformed(
0678: java.awt.event.ActionEvent evt) {
0679: universeRunningMIActionPerformed(evt);
0680: }
0681: });
0682:
0683: viewMenu.add(universeRunningMI);
0684:
0685: menuBar.add(viewMenu);
0686:
0687: packageMenu.setText("Package");
0688: generateSourceM.setText("Generate Source");
0689: generateSourceM
0690: .setToolTipText("Generate Java Source code for this SceneGraph");
0691: generateSourceM
0692: .addActionListener(new java.awt.event.ActionListener() {
0693: public void actionPerformed(
0694: java.awt.event.ActionEvent evt) {
0695: generateSourceMActionPerformed(evt);
0696: }
0697: });
0698:
0699: packageMenu.add(generateSourceM);
0700:
0701: generateJarM.setText("Generate Jar");
0702: generateJarM
0703: .setToolTipText("Generate a Jar of this SceneGraph");
0704: generateJarM
0705: .addActionListener(new java.awt.event.ActionListener() {
0706: public void actionPerformed(
0707: java.awt.event.ActionEvent evt) {
0708: generateJarMActionPerformed(evt);
0709: }
0710: });
0711:
0712: packageMenu.add(generateJarM);
0713:
0714: menuBar.add(packageMenu);
0715:
0716: helpMenu.setText("Help");
0717: aboutM.setText("About");
0718: aboutM.addActionListener(new java.awt.event.ActionListener() {
0719: public void actionPerformed(java.awt.event.ActionEvent evt) {
0720: aboutMActionPerformed(evt);
0721: }
0722: });
0723:
0724: helpMenu.add(aboutM);
0725:
0726: menuBar.add(helpMenu);
0727:
0728: setJMenuBar(menuBar);
0729:
0730: }
0731:
0732: // </editor-fold>//GEN-END:initComponents
0733:
0734: private void generateSourceMActionPerformed(
0735: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateSourceMActionPerformed
0736: generateSource();
0737: }//GEN-LAST:event_generateSourceMActionPerformed
0738:
0739: public void generateSource() {
0740: ClassGenerator generator = new ClassGenerator(flyModule
0741: .getContext(), (SGLocale) graphModule.getRoot(), "Tst");
0742: generator.create();
0743: System.out.println(generator);
0744: }
0745:
0746: private void newInterpTestMIActionPerformed(
0747: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newInterpTestMIActionPerformed
0748: // Add your handling code here:
0749: j3dflyController.clearUniverse();
0750:
0751: BranchGroup bg = new BranchGroup();
0752: TransformGroup tg = new TransformGroup();
0753: bg.addChild(tg);
0754: Appearance app = new Appearance();
0755: PolygonAttributes polyAttr = new PolygonAttributes();
0756: polyAttr.setPolygonMode(PolygonAttributes.POLYGON_LINE);
0757: app.setPolygonAttributes(polyAttr);
0758: tg.addChild(new com.sun.j3d.utils.geometry.Box(0.5f, 0.5f,
0759: 0.5f, app));
0760:
0761: Alpha alpha = new Alpha(-1, 5000);
0762: Transform3D axis = new Transform3D();
0763: axis.setIdentity();
0764: KBKeyFrame[] keys = new KBKeyFrame[] {
0765: new KBKeyFrame(0f, 0, new Point3f(0f, 0f, 0f), 0f, 0f,
0766: 0f, new Point3f(1f, 1f, 1f), 0f, 0f, 0f),
0767: new KBKeyFrame(1f, 0, new Point3f(2f, 2f, 2f), 0f, 0f,
0768: 0f, new Point3f(1f, 1f, 1f), 0f, 0f, 0f)
0769:
0770: };
0771:
0772: KBRotPosScaleSplinePathInterpolator interp = new KBRotPosScaleSplinePathInterpolator(
0773: alpha, tg, axis, keys);
0774: interp.setSchedulingBounds(new BoundingSphere(new Point3d(),
0775: Double.POSITIVE_INFINITY));
0776: bg.addChild(interp);
0777:
0778: j3dflyController.addBranchGraph(bg);
0779: }//GEN-LAST:event_newInterpTestMIActionPerformed
0780:
0781: private void newSimpleSceneGraphMIActionPerformed(
0782: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newSimpleSceneGraphMIActionPerformed
0783: // Add your handling code here:
0784: j3dflyController.clearUniverse();
0785: j3dflyController.addBranchGraph(new BranchGroup());
0786: j3dflyController.addBranchGraph(new BranchGroup());
0787: }//GEN-LAST:event_newSimpleSceneGraphMIActionPerformed
0788:
0789: private void importMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_importMActionPerformed
0790: // Add your handling code here:
0791: j3dflyController.loadScene();
0792: }//GEN-LAST:event_importMActionPerformed
0793:
0794: private void universeRunningMIActionPerformed(
0795: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_universeRunningMIActionPerformed
0796: // Add your handling code here:
0797: flyModule.getContext().getLocale().setLive(
0798: universeRunningMI.isSelected());
0799: }//GEN-LAST:event_universeRunningMIActionPerformed
0800:
0801: private void configureLoadersMActionPerformed(
0802: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_configureLoadersMActionPerformed
0803: // Add your handling code here:
0804: j3dflyController.configureLoaders(null);
0805: }//GEN-LAST:event_configureLoadersMActionPerformed
0806:
0807: private void modeSelectionActionPerformed(
0808: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modeSelectionActionPerformed
0809: // Add your handling code here:
0810: if (evt.getSource() == viewUniverseB) {
0811: if (currentModule != null)
0812: currentModule.setActive(false);
0813: flyModule.setActive(true);
0814: currentModule = flyModule;
0815: } else if (evt.getSource() == editSceneGraphB) {
0816: if (currentModule != null)
0817: currentModule.setActive(false);
0818: graphModule.setActive(true);
0819: currentModule = graphModule;
0820: // } else if (evt.getSource()==editAnimationB) {
0821: // if (currentModule!=null)
0822: // currentModule.setActive( false );
0823: // animModule.setActive( true );
0824: // currentModule = animModule;
0825: } else if (evt.getSource() == editPositionB) {
0826: if (currentModule != null)
0827: currentModule.setActive(false);
0828: locationModule.setActive(true);
0829: currentModule = locationModule;
0830: }
0831: }//GEN-LAST:event_modeSelectionActionPerformed
0832:
0833: private void updateGraphMActionPerformed(
0834: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateGraphMActionPerformed
0835: // Add your handling code here:
0836: System.out
0837: .println("updateGraphMActionPerformed not implemented");
0838: //sceneGraphControl.updateSceneGraph();
0839: //treeFrame.repaint();
0840: }//GEN-LAST:event_updateGraphMActionPerformed
0841:
0842: private void propertiesMActionPerformed(
0843: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_propertiesMActionPerformed
0844: // Add your handling code here:
0845:
0846: }//GEN-LAST:event_propertiesMActionPerformed
0847:
0848: /**
0849: * Set the type of performance for the editor,
0850: * level should be one of
0851: * PropertiesDialog.NONE_ALLOWED, READ_ALLOWED, READ_WRITE_ALLOWED
0852: */
0853: public void setPerformanceLevel(int level) {
0854: //PropertiesDialog.performanceLevel = level;
0855: //sceneGraphControl.setEditorCapabilities();
0856: }
0857:
0858: private void aboutMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMActionPerformed
0859: // Add your handling code here:
0860: javax.swing.JOptionPane.showMessageDialog(this ,
0861: new AboutPanel());
0862: }//GEN-LAST:event_aboutMActionPerformed
0863:
0864: private void zoomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomActionPerformed
0865: }//GEN-LAST:event_zoomActionPerformed
0866:
0867: private void exitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitActionPerformed
0868: // Add your handling code here:
0869: exit();
0870: }//GEN-LAST:event_exitActionPerformed
0871:
0872: private void saveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsActionPerformed
0873: // Add your handling code here:
0874: //treeFrame.prepareToSave();
0875: //j3dFile = windowManager.chooseSaveFile( "Save J3D");
0876: //sceneGraphControl.saveSceneGraph( j3dFile );
0877: //setWindowTitle();
0878: flyModule.getContext().getLocale().setLive(false);
0879:
0880: flyModule.prepareToSave();
0881: //animModule.prepareToSave();
0882: graphModule.prepareToSave();
0883: locationModule.prepareToSave();
0884: projectFile = j3dflyController.saveAsScene();
0885: setWindowTitle();
0886:
0887: saveM.setEnabled(true);
0888:
0889: System.out.println("Save complete");
0890:
0891: flyModule.saveComplete();
0892: //animModule.saveComplete();
0893: graphModule.saveComplete();
0894: locationModule.saveComplete();
0895:
0896: System.out.println("Doing setLive");
0897:
0898: flyModule.getContext().getLocale().setLive(true);
0899: }//GEN-LAST:event_saveAsActionPerformed
0900:
0901: private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
0902: // Add your handling code here:
0903: flyModule.getContext().getLocale().setLive(false);
0904:
0905: flyModule.prepareToSave();
0906: //animModule.prepareToSave();
0907: graphModule.prepareToSave();
0908: locationModule.prepareToSave();
0909: j3dflyController.saveScene(projectFile);
0910:
0911: System.out.println("Save complete");
0912:
0913: flyModule.saveComplete();
0914: //animModule.saveComplete();
0915: graphModule.saveComplete();
0916: locationModule.saveComplete();
0917:
0918: System.out.println("Doing setLive");
0919: flyModule.getContext().getLocale().setLive(true);
0920: }//GEN-LAST:event_saveActionPerformed
0921:
0922: /** @deprecated
0923: */
0924: private void menuShowUserUniverseActionPerformed(
0925: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuShowUserUniverseActionPerformed
0926: // Add your handling code here:
0927: }//GEN-LAST:event_menuShowUserUniverseActionPerformed
0928:
0929: private void loadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadActionPerformed
0930: // Add your handling code here:
0931: j3dflyController.clearUniverse();
0932: projectFile = j3dflyController.loadScene();
0933: setWindowTitle();
0934: saveM.setEnabled(true);
0935: }//GEN-LAST:event_loadActionPerformed
0936:
0937: /**
0938: * Package the scenegraph into an executable Jar file
0939: */
0940: private void generateJarMActionPerformed(
0941: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_generateJarMActionPerformed
0942: // Add your handling code here
0943: //saveActionPerformed(null);
0944: //JarBuilder builder = new JarBuilder();
0945: //builder.buildJar( j3dFile );
0946: }//GEN-LAST:event_generateJarMActionPerformed
0947:
0948: /** Exit the Application */
0949: private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
0950: exit();
0951: }//GEN-LAST:event_exitForm
0952:
0953: public javax.swing.JMenuBar getMainMenuBar() {
0954: return menuBar;
0955: }
0956:
0957: private void exit() {
0958: //TODO - Check with user and save data
0959: System.exit(0);
0960: }
0961:
0962: /**
0963: * Set the title of the window to be the current filename
0964: */
0965: private void setWindowTitle() {
0966: if (projectFile == null)
0967: setTitle("J3dEdit");
0968: else {
0969: String path = projectFile.getName();
0970: String filename = path
0971: .substring(
0972: path.lastIndexOf(File.separatorChar) + 1,
0973: path.length());
0974: setTitle("J3dEdit - " + filename);
0975: }
0976: }
0977:
0978: /**
0979: * @param args the command line arguments
0980: */
0981: public static void main(String args[]) {
0982: //if (args.length>0) {
0983: // new Editor( new File( args[0] ));
0984: //} else
0985: new J3dEdit(args);
0986: }
0987:
0988: class GraphChangeListener implements
0989: javax.media.j3d.GraphStructureChangeListener {
0990:
0991: private DevelopmentLocale locale;
0992:
0993: public GraphChangeListener(DevelopmentLocale locale) {
0994: this .locale = locale;
0995: locale.getVirtualUniverse()
0996: .addGraphStructureChangeListener(this );
0997: }
0998:
0999: public void branchGroupAdded(java.lang.Object parent,
1000: BranchGroup child) {
1001: if (parent instanceof Locale) {
1002: return;
1003: }
1004:
1005: locale.notifyGroupAddChild((Group) parent, child);
1006: }
1007:
1008: public void branchGroupMoved(java.lang.Object oldParent,
1009: java.lang.Object newParent, BranchGroup child) {
1010: if (!(oldParent instanceof Locale))
1011: locale.notifyGroupRemoveChild((Group) oldParent, child);
1012: if (!(newParent instanceof Locale))
1013: locale.notifyGroupAddChild((Group) newParent, child);
1014: }
1015:
1016: public void branchGroupRemoved(java.lang.Object parent,
1017: BranchGroup child) {
1018: if (parent instanceof Locale) {
1019: return;
1020: }
1021: locale.notifyGroupRemoveChild((Group) parent, child);
1022: }
1023: }
1024:
1025: // Variables declaration - do not modify//GEN-BEGIN:variables
1026: private javax.swing.JMenuItem aboutM;
1027: private javax.swing.JMenuItem configureLoadersM;
1028: private javax.swing.JMenuItem copyM;
1029: private javax.swing.JMenuItem cutM;
1030: private javax.swing.JMenuItem deleteM;
1031: private javax.swing.JToggleButton editAnimationB;
1032: private javax.swing.JMenu editMenu;
1033: private javax.swing.JToggleButton editPositionB;
1034: private javax.swing.JToggleButton editSceneGraphB;
1035: private javax.swing.JMenuItem exitM;
1036: private javax.swing.JMenu fileMenu;
1037: private javax.swing.JMenuItem generateJarM;
1038: private javax.swing.JMenuItem generateSourceM;
1039: private javax.swing.JMenu helpMenu;
1040: private javax.swing.JMenuItem importM;
1041: private javax.swing.JPanel j3dflyToolbarsP;
1042: private javax.swing.JSeparator jSeparator3;
1043: private javax.swing.JSeparator jSeparator4;
1044: private javax.swing.JSeparator jSeparator5;
1045: private javax.swing.JSeparator jSeparator7;
1046: private javax.swing.JPanel leftToolbarP;
1047: private javax.swing.JToolBar leftToolbars;
1048: private javax.swing.JButton loadB;
1049: private javax.swing.JMenuItem loadM;
1050: private javax.swing.JPanel mainToolbarP;
1051: private javax.swing.JMenuBar menuBar;
1052: private javax.swing.JPanel modePanel;
1053: private javax.swing.JMenu newGraphM;
1054: private javax.swing.JMenuItem newInterpTestMI;
1055: private javax.swing.JMenuItem newSimpleSceneGraphMI;
1056: private javax.swing.JMenu packageMenu;
1057: private javax.swing.JMenuItem pasteM;
1058: private javax.swing.JMenuItem propertiesM;
1059: private javax.swing.JMenuItem saveAsM;
1060: private javax.swing.JButton saveB;
1061: private javax.swing.JMenuItem saveM;
1062: private javax.swing.JCheckBoxMenuItem universeRunningMI;
1063: private javax.swing.JMenuItem updateGraphM;
1064: private javax.swing.JMenu viewMenu;
1065: private javax.swing.JToggleButton viewUniverseB;
1066: private javax.swing.JButton zoomInB;
1067: private javax.swing.JButton zoomOutB;
1068: // End of variables declaration//GEN-END:variables
1069:
1070: }
|