001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/WindowManager.java,v 1.1 2005/04/20 22:20:49 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 java.awt.*;
021: import java.awt.event.*;
022: import java.io.File;
023: import javax.swing.JWindow;
024:
025: import javax.swing.JColorChooser;
026: import javax.swing.JFileChooser;
027: import javax.swing.filechooser.*;
028: import javax.swing.JOptionPane; //import javax.swing.SwingUtilities;
029:
030: import javax.media.j3d.BranchGroup;
031:
032: import org.jdesktop.j3dfly.utils.loadercontrol.ExampleFileFilter;
033: import org.jdesktop.j3dfly.utils.developmenttools.DevelopmentLocale;
034:
035: public class WindowManager {
036:
037: private static WindowManager currentWindowManager = null;
038:
039: public static final int J3D_NO_MODE = 0;
040: public static final int J3D_FLY_MODE = 1;
041: public static final int J3D_EDIT_SCENEGRAPH_MODE = 2;
042: public static final int J3D_EDIT_ANIMATION_MODE = 3;
043: public static final int J3D_EDIT_POSITION_MODE = 4;
044:
045: private int currentMode = J3D_NO_MODE;
046:
047: private Editor editor;
048:
049: private DevelopmentLocale developmentLocale;
050:
051: private JFileChooser fileChooser = null;
052: private JColorChooser colorChooser = null;
053:
054: private FileFilter defaultFileFilter;
055:
056: private J3dTreeFrame j3dTreeFrame;
057:
058: // Associate Java3D nodes with Icons (images) that represent them
059: private TreeIconControl treeIconControl;
060:
061: private boolean rendererRunning; // Indicates if the renderer
062:
063: // should be running
064:
065: /*
066: public WindowManager( Editor editor, UserUniverse userUniverse ) {
067: this( editor, userUniverse.getJ3dLocale() );
068: this.userUniverse = userUniverse;
069: userUniverse.setLocation( new Point(0, 300) );
070: userUniverse.setSize( 600, 600 );
071:
072: currentWindowManager = this;
073: }
074: */
075:
076: public WindowManager(Editor editor,
077: DevelopmentLocale developmentLocale) {
078: this .editor = editor;
079: this .developmentLocale = developmentLocale;
080:
081: String currentDir = new String();
082: try {
083: currentDir = System.getProperty("user.dir");
084: } catch (SecurityException e) {
085: }
086:
087: defaultFileFilter = new ExampleFileFilter("j3f");
088: fileChooser = new JFileChooser(currentDir);
089:
090: colorChooser = new JColorChooser();
091:
092: currentWindowManager = this ;
093: }
094:
095: public static WindowManager getManager() {
096: return currentWindowManager;
097: }
098:
099: /**
100: * Set the current windowing mode and layout the windows accordingly
101: * mode should be one of J3D_FLY_MODE, J3D_EDIT_SCENEGRAPH_MODE,
102: * J3D_EDIT_ANIMATION_MODE, J3D_EDIT_POSITION_MODE
103: */
104: public void setCurrentMode(int mode) {
105: currentMode = mode;
106: layoutWindows();
107: }
108:
109: /**
110: * Return the current windowing mode
111: */
112: public int getCurrentMode() {
113: return currentMode;
114: }
115:
116: /**
117: * Layout the windows depending on the current mode
118: */
119: public void layoutWindows() {
120: /*
121: int nx = editor.getSize().width;
122: int ny = editor.getSize().height;
123:
124: editorManager.setPosition( new Point(nx, ny ));
125:
126: switch(currentMode) {
127: case J3D_NO_MODE:
128: editor.setLocation( 0, 0);
129: editor.show();
130: break;
131: case J3D_FLY_MODE:
132: j3dFlyLayout();
133: break;
134: case J3D_EDIT_SCENEGRAPH_MODE:
135: j3dSceneGraphEditLayout();
136: break;
137: case J3D_EDIT_ANIMATION_MODE:
138: break;
139: case J3D_EDIT_POSITION_MODE:
140: break;
141: }
142: */
143: }
144:
145: /*
146: private void j3dFlyLayout() {
147: //editor.hide();
148: editorManager.hide();
149: j3dTreeFrame.hide();
150:
151: if (userUniverse!=null) {
152: Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
153: userUniverse.setSize( screenSize );
154: userUniverse.setLocation(0,0);
155: userUniverse.show();
156: }
157: }
158:
159: private void j3dSceneGraphEditLayout() {
160: Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
161:
162: editor.setLocation( 0, 0);
163: editor.show();
164:
165: editorManager.setLocation( screenSize.width - editorManager.getPreferredSize().width,
166: 0 );
167: j3dTreeFrame.setLocation( 0, editor.getPreferredSize().height );
168: editorManager.show();
169: j3dTreeFrame.show();
170:
171: if (userUniverse!=null) {
172: userUniverse.setSize( 600,600 );
173: userUniverse.setLocation( screenSize.width - 600,
174: editor.getPreferredSize().height );
175: userUniverse.show();
176: }
177: }
178: */
179:
180: public void setJ3dTreeFrame(J3dTreeFrame treeFrame) {
181: j3dTreeFrame = treeFrame;
182: }
183:
184: public J3dTreeFrame getJ3dTreeFrame() {
185: return j3dTreeFrame;
186: }
187:
188: public void setTreeIconControl(TreeIconControl treeIconControl) {
189: this .treeIconControl = treeIconControl;
190: }
191:
192: public TreeIconControl getTreeIconControl() {
193: return treeIconControl;
194: }
195:
196: //public final DevelopmentLocale getDevelopmentLocale() {
197: // return developmentLocale;
198: //}
199:
200: //public final EditorManager getEditorManager() {
201: // return editorManager;
202: //}
203:
204: //public final UserUniverse getUserUniverse() {
205: // return userUniverse;
206: //}
207:
208: //public final Editor getEditor() {
209: // return editor;
210: //}
211:
212: /**
213: * Put application in a state for waiting for a long process to
214: * complete, disables all user input and stops the renderer.
215: */
216: public void setWaitState(boolean wait) {
217: if (wait) {
218: //editor.setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ));
219:
220: //if (userUniverse!=null) {
221: // userUniverse.setCursor(
222: // Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ));
223: // userUniverse.setEnabled( false );
224: //}
225:
226: j3dTreeFrame.setEnabled(false);
227: //editor.setEnabled( false );
228: rendererRunning = developmentLocale.getLive();
229: developmentLocale.setLive(false);
230: } else {
231: //editor.setCursor( Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ));
232: //if (userUniverse!=null) {
233: // userUniverse.setCursor(
234: // Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR ));
235: // userUniverse.setEnabled( true );
236: //}
237:
238: j3dTreeFrame.setEnabled(true);
239: //editor.setEnabled( true );
240: developmentLocale.setLive(rendererRunning);
241: }
242: }
243:
244: /**
245: * Returns a JColorChooser
246: * Control will be needed to ensure the chooser is only used by a
247: * single consumer
248: */
249: public JColorChooser getColorChooser() {
250: return colorChooser;
251: }
252:
253: /**
254: * Static method to invoke user interaction and return a color
255: */
256: public Color chooseColor(Color initialColor) {
257: return colorChooser.showDialog(null, "Choose Color",
258: initialColor);
259: }
260:
261: /**
262: * Display a one line error message in a Dialog
263: */
264: public void showErrorMessage(String error) {
265: JOptionPane.showMessageDialog(null, error, "Error",
266: JOptionPane.ERROR_MESSAGE);
267: }
268:
269: /**
270: * Display the message in a dialog
271: */
272: public void showMessage(String title, String message) {
273: JOptionPane.showMessageDialog(null, message, title,
274: JOptionPane.INFORMATION_MESSAGE);
275: }
276:
277: /**
278: * Given a file return the Canonical path relative to the users
279: * current working directory as long as the File is either in the
280: * current working directory of a subdirectory.
281: *
282: * If the file is not under the current working directory the
283: * AbsolutePath for the file is returned
284: */
285: public String getRelativePath(File file) {
286: String ret;
287:
288: //System.out.println( System.getProperty("user.dir"));
289:
290: //System.out.println( file.getAbsolutePath() );
291:
292: String userDir = System.getProperty("user.dir");
293:
294: if (file.getAbsolutePath().startsWith(userDir)) {
295: ret = file.getAbsolutePath()
296: .substring(userDir.length() + 1);
297: } else
298: ret = file.getAbsolutePath();
299:
300: //System.out.println("--------- "+ret );
301:
302: return ret;
303: }
304:
305: public File chooseOpenFile(String title, FileFilter fileFilter) {
306: File file = null;
307:
308: fileChooser.addChoosableFileFilter(fileFilter);
309: fileChooser.setDialogTitle(title);
310: fileChooser
311: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
312: int ret = fileChooser.showOpenDialog(null);
313: if (ret == JFileChooser.APPROVE_OPTION) {
314: file = fileChooser.getSelectedFile();
315: }
316:
317: return file;
318: }
319:
320: public File chooseOpenFile(String title, FileFilter fileFilter,
321: File path) {
322: fileChooser.setCurrentDirectory(path);
323: return chooseOpenFile(title, fileFilter);
324: }
325:
326: public File chooseOpenFile(String title) {
327: return chooseOpenFile(title, defaultFileFilter);
328: }
329:
330: public File chooseSaveFile(String title) {
331: return chooseSaveFile(title, defaultFileFilter);
332: }
333:
334: public File chooseSaveFile(String title, FileFilter fileFilter,
335: File defaultSelection) {
336: fileChooser.setSelectedFile(defaultSelection);
337: return chooseSaveFile(title, fileFilter);
338: }
339:
340: public File chooseSaveFile(String title, FileFilter fileFilter) {
341: File file = null;
342:
343: fileChooser.setDialogTitle(title);
344: fileChooser
345: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
346: fileChooser.setFileFilter(fileFilter);
347: int ret = fileChooser.showSaveDialog(null);
348: if (ret == JFileChooser.APPROVE_OPTION) {
349: file = fileChooser.getSelectedFile();
350: }
351:
352: return file;
353: }
354:
355: public File chooseSaveDirectory(String title,
356: String approveButtonText, String approveButtonToolTip) {
357: File file = null;
358:
359: fileChooser.setDialogTitle(title);
360: fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
361: fileChooser.setFileFilter(null);
362: fileChooser.setApproveButtonText(approveButtonText);
363: fileChooser.setApproveButtonToolTipText(approveButtonToolTip);
364: int ret = fileChooser.showSaveDialog(null);
365: if (ret == JFileChooser.APPROVE_OPTION) {
366: file = fileChooser.getSelectedFile();
367: }
368:
369: return file;
370: }
371:
372: /**
373: * Open a window with a progress bar with the given message.
374: * The progress bar will be full when maxValue is reached
375: * and startValue is the initial value for the bar.
376: *
377: */
378: /*
379: public void showProgressBar( String message, int maxValue, int startValue ) {
380:
381: final String msg = message;
382: final int mxValue = maxValue;
383: final int stValue = startValue;
384:
385: Runnable run = new Runnable() {
386: public void run() {
387: progressDialog.setMessage( msg );
388: progressDialog.setMaxValue( mxValue );
389: progressDialog.setValue( stValue );
390: progressDialog.setVisible( true);
391: }
392: };
393:
394: SwingUtilities.invokeLater( run );
395: }
396: */
397: /**
398: * Increment the progress bar by tick amount
399: */
400: /*
401: public void madeProgress( int tick ) {
402: final int t = tick;
403:
404: Runnable run = new Runnable() {
405: public void run() {
406: progressDialog.incrementValue( t );
407: }
408: };
409:
410: SwingUtilities.invokeLater( run );
411: }
412: */
413: /**
414: * Hides the progress bar window
415: */
416: /*
417: public void hideProgressBar() {
418: Runnable run = new Runnable() {
419: public void run() {
420: progressDialog.setVisible( false );
421: }
422: };
423:
424: SwingUtilities.invokeLater( run );
425: }
426: */
427:
428: /**
429: * Return the component used as parent for dialogs etc
430: */
431: public Component getParentComponent() {
432: return null;
433: }
434: }
|