001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/Editor.java,v 1.1 2005/04/20 22:20:44 paulby Exp $
003: *
004: * Sun Public License Notice
005: *
006: * The contents of this file are subject to the Sun Public License Version
007: * 1.0 (the "License"). You may not use this file except in compliance with
008: * the License. A copy of the License is available at http://www.sun.com/
009: *
010: * The Original Code is the Java 3D(tm) Scene Graph Editor.
011: * The Initial Developer of the Original Code is Paul Byrne.
012: * Portions created by Paul Byrne are Copyright (C) 2002.
013: * All Rights Reserved.
014: *
015: * Contributor(s): Paul Byrne.
016: *
017: **/
018: package org.jdesktop.j3dedit.scenegrapheditor;
019:
020: import javax.media.j3d.*;
021: import javax.vecmath.Point3d;
022: import java.awt.Point;
023: import java.awt.Cursor;
024: import java.io.*;
025: import javax.swing.ProgressMonitorInputStream;
026:
027: import com.sun.j3d.loaders.objectfile.ObjectFile;
028: import com.sun.j3d.loaders.Scene;
029: import com.sun.j3d.utils.behaviors.mouse.*;
030:
031: import org.jdesktop.j3dfly.utils.loadercontrol.ExampleFileFilter;
032: import org.jdesktop.j3dedit.J3dEdit;
033: import org.jdesktop.j3dedit.J3dEditContext;
034: import org.jdesktop.j3dfly.utils.gui.SplashWindow;
035: import org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool;
036: import org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale;
037: import org.jdesktop.j3dedit.scenegraph.SGObject;
038:
039: /**
040: * The original core of the editor. Most of this is now obsolete and this class
041: * will probably be replaced or merged into another class
042: *
043: * @author Paul Byrne
044: * @version $Revision: 1.1 $
045: */
046: public class Editor extends Object {
047:
048: private WindowManager windowManager;
049: private java.io.File j3dFile = null;
050: private PropertiesDialog propertiesDialog = null;
051: private boolean readOnly = false;
052: private J3dTreeFrame treeFrame;
053: private J3dEditContext context;
054:
055: private ShowBoundsVisualTool showBoundsVisualTool = null;
056:
057: /** Creates new form Editor */
058: /*
059: public Editor() {
060: SplashWindow.showSplashscreen("com/sun/j3d/demos/j3dedit/splash.jpg");
061: SplashWindow.showMessage("Initialising GUI");
062: initComponents ();
063: windowManager = new WindowManager( this, new UserUniverse() );
064: windowManager.getDevelopmentLocale().addBranchGraph( new BranchGroup() );
065: windowManager.getDevelopmentLocale().addBranchGraph( new BranchGroup() );
066: windowManager.getDevelopmentLocale().setLive( false );
067:
068: SplashWindow.showMessage("Installing Modules");
069: installModules();
070: //initialiseEditor( windowManager.getDevelopmentLocale(), false );
071:
072: windowManager.getDevelopmentLocale().setLive( true );
073: SplashWindow.destroySplashscreen();
074: }
075: */
076: /*
077: public Editor( File initialFile ) {
078: initComponents();
079: installModules();
080: windowManager = new WindowManager( this, new UserUniverse() );
081: windowManager.getDevelopmentLocale().setLive( false );
082:
083: String filename = initialFile.getName();
084: String extension = filename.substring( filename.lastIndexOf('.')+1, filename.length() );
085: if (extension.compareToIgnoreCase("j3f")==0) {
086: initialiseEditor( windowManager.getDevelopmentLocale(), false );
087: sceneGraphControl.loadSceneGraph( initialFile );
088: j3dFile = initialFile;
089: } else {
090: initialiseEditor( windowManager.getDevelopmentLocale(), false );
091: sceneGraphControl.load3dFile( initialFile );
092: windowManager.setCurrentMode( WindowManager.J3D_FLY_MODE );
093: }
094:
095: sceneGraphControl.checkForLights(null);
096:
097: windowManager.getDevelopmentLocale().setLive( true );
098: }
099: */
100:
101: /**
102: * Creates an editor for the BranchGroup root.
103: */
104: /*
105: public Editor( com.sun.j3d.demos.utils.developmenttools.DevelopmentLocale locale, boolean readOnly ) {
106: locale.setLive( false );
107: initComponents ();
108: windowManager = new WindowManager( this, (DevelopmentUniverse)locale.getVirtualUniverse() );
109: initialiseEditor( locale, readOnly );
110: windowManager.getDevelopmentLocale().setLive( true );
111: }
112: **/
113:
114: /**
115: * Creates an editor for the Universe.
116: */
117: public Editor(J3dEditContext context, boolean readOnly) {
118: this .context = context;
119: //initComponents ();
120: context.getLocale().setLive(false);
121: windowManager = new WindowManager(this , context.getLocale());
122: initialiseEditor(context.getLocale(), readOnly);
123: context.getLocale().setLive(true);
124: windowManager
125: .setCurrentMode(WindowManager.J3D_EDIT_SCENEGRAPH_MODE);
126: }
127:
128: private void initialiseEditor(
129: org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale locale,
130: boolean readOnly) {
131: this .readOnly = readOnly;
132:
133: //menuBar.remove( sgViewMenu );
134: //menuBar = null;
135:
136: treeFrame = new J3dTreeFrame(readOnly, context);
137: windowManager.setJ3dTreeFrame(treeFrame);
138:
139: //if (readOnly) {
140: // fileMenu.setEnabled(false);
141: // editMenu.setEnabled(false);
142: // packageMenu.setEnabled( false );
143: //}
144:
145: treeFrame.createTree();
146: treeFrame.setTreeLayoutMode(J3dTreePanel.CIRCULAR_LAYOUT);
147:
148: }
149:
150: /**
151: * Sets the Active state of the editor and it's associated windows
152: *
153: * When the editor is made active is starts listening for various events,
154: * when made inactive it will stop listening for the events
155: */
156: public void setActive(boolean active) {
157: treeFrame.setActive(active);
158:
159: context.getConfigLoader().getEditorManager().setActive(active);
160: }
161:
162: /**
163: * Get the frame that contains the tree representation of the
164: * scene graph
165: */
166: public J3dTreeFrame getTreeFrame() {
167: return treeFrame;
168: }
169:
170: /**
171: * Get the frame that contains the node editors
172: */
173: public javax.swing.JFrame getEditorFrame() {
174: return context.getConfigLoader().getEditorManager()
175: .getEditorFrame();
176: }
177:
178: public void updateViewMenu(javax.swing.JMenu viewMenu) {
179: //Thread.dumpStack();
180: //viewMenu.add( sgViewMenu );
181: treeFrame.updateViewMenu(viewMenu);
182: }
183:
184: private void propertiesMActionPerformed(
185: java.awt.event.ActionEvent evt) {
186: //com.sun.j3d.demos.utils.developmenttools.DevelopmentLocale locale = WindowManager.getManager().getDevelopmentLocale();
187: /*
188: if (propertiesDialog==null)
189: propertiesDialog = new PropertiesDialog( this, true );
190:
191: propertiesDialog.setVisible( true );
192:
193: if (propertiesDialog.exitOK()) {
194: boolean wasLive = locale.getLive();
195: if (wasLive)
196: locale.setLive( false );
197: sceneGraphControl.setEditorCapabilities();
198:
199: if (wasLive)
200: locale.setLive( true );
201: }
202: */
203: }
204:
205: /**
206: * Set the type of performance for the editor,
207: * level should be one of
208: * PropertiesDialog.NONE_ALLOWED, READ_ALLOWED, READ_WRITE_ALLOWED
209: */
210: public void setPerformanceLevel(int level) {
211: PropertiesDialog.performanceLevel = level;
212: context.getSceneGraphControl().setEditorCapabilities();
213: }
214:
215: /**
216: * Package the scenegraph into an executable Jar file
217: */
218: private void generateJarMActionPerformed(
219: java.awt.event.ActionEvent evt) {
220: // Add your handling code here
221: //saveActionPerformed(null);
222: JarBuilder builder = new JarBuilder();
223: builder.buildJar(j3dFile);
224: }
225:
226: /*
227: public void CutPasteCopyAction(int action) {
228: if (!treeFrame.hasFocus())
229: return;
230:
231:
232: switch(action) {
233: case J3dEdit.CutPasteCopyListener.COPY_ACTION :
234: treeFrame.copyNode();
235: break;
236: case J3dEdit.CutPasteCopyListener.CUT_ACTION :
237: treeFrame.cutNode();
238: break;
239: case J3dEdit.CutPasteCopyListener.PASTE_ACTION :
240: treeFrame.pasteNode();
241: break;
242: }
243: }
244: **/
245:
246: public void prepareToSave() {
247: treeFrame.prepareToSave();
248: context.getSceneGraphControl().prepareToSave();
249: }
250:
251: /**
252: * Save operation is complete, return system to runtime state
253: */
254: public void saveComplete() {
255: context.getSceneGraphControl().saveComplete();
256: }
257:
258: public SGObject getRoot() {
259: return context.getSceneGraphControl().getViewRoot();
260: }
261:
262: }
|