001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/J3dTreeFrame.java,v 1.1 2005/04/20 22:20:46 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.j3dedit.J3dEditContext;
032: import org.jdesktop.j3dedit.scenegrapheditor.treeview.TVObject;
033: import org.jdesktop.j3dfly.utils.loadercontrol.ExampleFileFilter;
034: import org.jdesktop.j3dfly.utils.loadercontrol.LoaderControl;
035: import org.jdesktop.j3dfly.utils.vpbehaviors.ViewUtils;
036: import org.jdesktop.j3dfly.utils.gui.ErrorManager;
037: import org.jdesktop.j3dfly.utils.gui.ErrorHandler;
038: import org.jdesktop.j3dfly.event.EventProcessor;
039: import org.jdesktop.j3dfly.event.FlyEventListener;
040: import org.jdesktop.j3dfly.event.FileLoadEvent;
041: import org.jdesktop.j3dfly.event.ViewClipDistanceChangedEvent;
042: import org.jdesktop.j3dfly.namecontrol.NameControl;
043: import org.jdesktop.j3dedit.event.NamedObjectSelectionEvent;
044: import org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsVisualTool;
045:
046: import org.jdesktop.j3dedit.actions.ActionManager;
047: import org.jdesktop.j3dedit.actions.CutAction;
048: import org.jdesktop.j3dedit.actions.CopyAction;
049: import org.jdesktop.j3dedit.actions.PasteAction;
050: import org.jdesktop.j3dedit.actions.DeleteAction;
051: import org.jdesktop.j3dedit.actions.ActionCallbackInterface;
052: import org.jdesktop.j3dedit.actions.CallbackAction;
053: import org.jdesktop.j3dedit.scenegraph.SGBehavior;
054: import org.jdesktop.j3dedit.scenegraph.SGLocale;
055: import org.jdesktop.j3dedit.scenegraph.SGObject;
056: import org.jdesktop.j3dedit.scenegraph.SGNode;
057: import org.jdesktop.j3dedit.scenegraph.SGGroup;
058:
059: /**
060: * The Frame in which the scenegraph is drawn.
061: *
062: * @author Paul Byrne
063: * @version $Id: J3dTreeFrame.java,v 1.1 2005/04/20 22:20:46 paulby Exp $
064: */
065: public class J3dTreeFrame extends javax.swing.JFrame implements
066: NodeCreationListener, FlyEventListener, ActionCallbackInterface {
067:
068: public static final int ZOOM_IN = 0;
069: public static final int ZOOM_OUT = 1;
070: public static final int ZOOM_SHOW_ALL = 2;
071: public static final int ZOOM_RESET = 3;
072:
073: private SceneGraphControl sceneGraphControl;
074: private NodeEditControl editControl;
075:
076: private WindowManager windowManager;
077: private java.io.File j3dFile = null;
078: private PropertiesDialog propertiesDialog = null;
079: private boolean readOnly = false;
080:
081: private ShowBoundsVisualTool showBoundsVisualTool = null;
082: private GroupSelectionListener groupSelectionListener;
083: private javax.swing.JMenu addChildMenu;
084: private SGObject highlightedNode = null;
085:
086: private J3dEditContext context;
087:
088: private boolean cutEnabled = false;
089: private boolean pasteEnabled = false;
090: private boolean copyEnabled = false;
091: private boolean deleteEnabled = false;
092:
093: private Point mousePosForPopup;
094:
095: /** Creates new form Editor */
096: public J3dTreeFrame(boolean readOnly, J3dEditContext context) {
097: super ();
098: this .context = context;
099: initComponents();
100: dummyMenu.remove(sgViewMenu);
101: dummyMenu = null;
102:
103: windowManager = WindowManager.getManager();
104:
105: pack();
106:
107: editControl = new NodeEditControl(readOnly, context
108: .getConfigLoader().getEditorManager());
109:
110: sceneGraphControl = new SceneGraphControl(treePanel, context);
111:
112: addChildMenu = context.getConfigLoader().getAddChildMenu();
113: nodePopupMenu.insert(addChildMenu, 0);
114:
115: context.getConfigLoader().setNodeCreationListener(this );
116:
117: // Add listener to treeFrame so that toolbar can enable/disable
118: // components when Group nodes are selected/deselected
119: setGroupSelectionListener(context.getConfigLoader()
120: .getJ3dNodesToolbar());
121:
122: setTitle("Java3D Scene Graph");
123: }
124:
125: /**
126: * Set the active status of this class
127: *
128: * When it's active it will listen for various events, when inactive
129: * it will stop listening.
130: *
131: * Active status also controls visibility
132: */
133: public void setActive(boolean active) {
134: if (active) {
135: setVisible(true);
136: context.getEventProcessor().addListener(this ,
137: NamedObjectSelectionEvent.class);
138: context.getEventProcessor().addListener(this ,
139: FileLoadEvent.class);
140: } else {
141: context.getEventProcessor().removeListener(this ,
142: NamedObjectSelectionEvent.class);
143: context.getEventProcessor().removeListener(this ,
144: FileLoadEvent.class);
145: setVisible(false);
146: }
147: }
148:
149: /**
150: * Add extra items to the view menu
151: */
152: public void updateViewMenu(javax.swing.JMenu viewMenu) {
153: viewMenu.add(sgViewMenu);
154: }
155:
156: /**
157: * Initial call to create the tree, called from Editor
158: */
159: public void createTree() {
160: sceneGraphControl.setSceneGraph(context);
161:
162: treePanel.setTree((TVObject) sceneGraphControl.getViewRoot()
163: .getTreeViewObject());
164: }
165:
166: private void setGroupSelectionListener(
167: GroupSelectionListener groupSelectionListener) {
168: this .groupSelectionListener = groupSelectionListener;
169: }
170:
171: /**
172: * Set the tree layout mode
173: * @see J3dTreePanel.SIMPLE_LAYOUT
174: * @see J3dTreePanel.CIRCULAR_LAYOUT
175: */
176: public void setTreeLayoutMode(int mode) {
177: treePanel.setTreeLayout(J3dTreePanel.CIRCULAR_LAYOUT);
178: treePanel.layoutTree();
179: treePanel.showNode((TVObject) sceneGraphControl.getViewRoot()
180: .getTreeViewObject());
181: }
182:
183: /**
184: * Prepare to save the scene graph
185: *
186: * Force user to apply any partial changes
187: */
188: public void prepareToSave() {
189: editControl.selectNode(null);
190: }
191:
192: /** This method is called from within the constructor to
193: * initialize the form.
194: * WARNING: Do NOT modify this code. The content of this method is
195: * always regenerated by the FormEditor.
196: */
197: private void initComponents() {//GEN-BEGIN:initComponents
198: javax.swing.JMenuItem copyPM;
199: javax.swing.JMenuItem cutPM;
200: javax.swing.JMenuItem deletePM;
201: javax.swing.JMenuItem pastePM;
202:
203: nodePopupMenu = new javax.swing.JPopupMenu();
204: editM = new javax.swing.JMenuItem();
205: showBoundsCB = new javax.swing.JCheckBoxMenuItem();
206: showM = new javax.swing.JMenu();
207: showPosX = new javax.swing.JMenuItem();
208: showPosY = new javax.swing.JMenuItem();
209: showPosZ = new javax.swing.JMenuItem();
210: showNegX = new javax.swing.JMenuItem();
211: showNegY = new javax.swing.JMenuItem();
212: showNegZ = new javax.swing.JMenuItem();
213: hideChildrenCB = new javax.swing.JCheckBoxMenuItem();
214: showOneChildLevelMI = new javax.swing.JMenuItem();
215: cutPM = new javax.swing.JMenuItem();
216: pastePM = new javax.swing.JMenuItem();
217: copyPM = new javax.swing.JMenuItem();
218: deletePM = new javax.swing.JMenuItem();
219: setTargetPM = new javax.swing.JMenuItem();
220: highlight3DMI = new javax.swing.JMenuItem();
221: enableHighlight3DModeMI = new javax.swing.JCheckBoxMenuItem();
222: backgroundPopupMenu = new javax.swing.JPopupMenu();
223: zoomInMI = new javax.swing.JMenuItem();
224: zoomOutMI = new javax.swing.JMenuItem();
225: zoomShowAllMI = new javax.swing.JMenuItem();
226: zoomResetMI = new javax.swing.JMenuItem();
227: jSeparator1 = new javax.swing.JSeparator();
228: hideGraphsMI = new javax.swing.JMenuItem();
229: dummyMenu = new javax.swing.JPopupMenu();
230: sgViewMenu = new javax.swing.JMenu();
231: circularLayoutMI = new javax.swing.JMenuItem();
232: simpleLayoutMI = new javax.swing.JMenuItem();
233: jScrollPane1 = new javax.swing.JScrollPane();
234: treePanel = new org.jdesktop.j3dedit.scenegrapheditor.J3dTreePanel();
235:
236: editM.setText("Edit...");
237: editM.addActionListener(new java.awt.event.ActionListener() {
238: public void actionPerformed(java.awt.event.ActionEvent evt) {
239: editMActionPerformed(evt);
240: }
241: });
242:
243: nodePopupMenu.add(editM);
244:
245: showBoundsCB.setText("Show Bounds");
246: showBoundsCB
247: .addActionListener(new java.awt.event.ActionListener() {
248: public void actionPerformed(
249: java.awt.event.ActionEvent evt) {
250: showBoundsCBActionPerformed(evt);
251: }
252: });
253:
254: nodePopupMenu.add(showBoundsCB);
255:
256: showM.setText("Show");
257: showM
258: .setToolTipText("Reposition the viewer so the subgraph is visible");
259: showPosX.setText("+X");
260: showPosX.addActionListener(new java.awt.event.ActionListener() {
261: public void actionPerformed(java.awt.event.ActionEvent evt) {
262: showMenuActionPerformed(evt);
263: }
264: });
265:
266: showM.add(showPosX);
267:
268: showPosY.setText("+Y");
269: showPosY.addActionListener(new java.awt.event.ActionListener() {
270: public void actionPerformed(java.awt.event.ActionEvent evt) {
271: showMenuActionPerformed(evt);
272: }
273: });
274:
275: showM.add(showPosY);
276:
277: showPosZ.setText("+Z");
278: showPosZ.addActionListener(new java.awt.event.ActionListener() {
279: public void actionPerformed(java.awt.event.ActionEvent evt) {
280: showMenuActionPerformed(evt);
281: }
282: });
283:
284: showM.add(showPosZ);
285:
286: showNegX.setText("-X");
287: showNegX.addActionListener(new java.awt.event.ActionListener() {
288: public void actionPerformed(java.awt.event.ActionEvent evt) {
289: showMenuActionPerformed(evt);
290: }
291: });
292:
293: showM.add(showNegX);
294:
295: showNegY.setText("-Y");
296: showNegY.addActionListener(new java.awt.event.ActionListener() {
297: public void actionPerformed(java.awt.event.ActionEvent evt) {
298: showMenuActionPerformed(evt);
299: }
300: });
301:
302: showM.add(showNegY);
303:
304: showNegZ.setText("-Z");
305: showNegZ.addActionListener(new java.awt.event.ActionListener() {
306: public void actionPerformed(java.awt.event.ActionEvent evt) {
307: showMenuActionPerformed(evt);
308: }
309: });
310:
311: showM.add(showNegZ);
312:
313: nodePopupMenu.add(showM);
314:
315: hideChildrenCB.setText("Hide Children");
316: hideChildrenCB
317: .setToolTipText("Hide this nodes children and redraw the SceneGraph");
318: hideChildrenCB
319: .addActionListener(new java.awt.event.ActionListener() {
320: public void actionPerformed(
321: java.awt.event.ActionEvent evt) {
322: hideChildrenCBActionPerformed(evt);
323: }
324: });
325:
326: nodePopupMenu.add(hideChildrenCB);
327:
328: showOneChildLevelMI.setText("Show Next Child Level");
329: showOneChildLevelMI
330: .setToolTipText("Show the next level of children");
331: showOneChildLevelMI.setEnabled(false);
332: showOneChildLevelMI
333: .addActionListener(new java.awt.event.ActionListener() {
334: public void actionPerformed(
335: java.awt.event.ActionEvent evt) {
336: showOneChildLevelMIActionPerformed(evt);
337: }
338: });
339:
340: nodePopupMenu.add(showOneChildLevelMI);
341:
342: cutPM.setText("Cut");
343: cutPM.setAction(ActionManager.getAction(CutAction.class));
344: nodePopupMenu.add(cutPM);
345:
346: pastePM.setText("Paste");
347: pastePM.setAction(ActionManager.getAction(PasteAction.class));
348: nodePopupMenu.add(pastePM);
349:
350: copyPM.setText("Copy");
351: copyPM.setAction(ActionManager.getAction(CopyAction.class));
352: nodePopupMenu.add(copyPM);
353:
354: deletePM.setText("Delete");
355: deletePM.setAction(ActionManager.getAction(DeleteAction.class));
356: nodePopupMenu.add(deletePM);
357:
358: setTargetPM.setText("Set Target");
359: setTargetPM.setToolTipText("Set the Target for the behavior");
360: setTargetPM.setEnabled(false);
361: setTargetPM
362: .addActionListener(new java.awt.event.ActionListener() {
363: public void actionPerformed(
364: java.awt.event.ActionEvent evt) {
365: setBehaviorTargetActionPerformed(evt);
366: }
367: });
368:
369: nodePopupMenu.add(setTargetPM);
370:
371: highlight3DMI.setText("Hightlight 3D");
372: highlight3DMI
373: .setToolTipText("Highlight this node in the Universe");
374: highlight3DMI.setEnabled(false);
375: highlight3DMI
376: .addActionListener(new java.awt.event.ActionListener() {
377: public void actionPerformed(
378: java.awt.event.ActionEvent evt) {
379: highlight3DMIActionPerformed(evt);
380: }
381: });
382:
383: nodePopupMenu.add(highlight3DMI);
384:
385: enableHighlight3DModeMI.setText("Enable 3D Highlight");
386: enableHighlight3DModeMI
387: .addActionListener(new java.awt.event.ActionListener() {
388: public void actionPerformed(
389: java.awt.event.ActionEvent evt) {
390: enableHighlight3DModeMIActionPerformed(evt);
391: }
392: });
393:
394: nodePopupMenu.add(enableHighlight3DModeMI);
395:
396: zoomInMI.setText("Zoom In");
397: zoomInMI.setEnabled(false);
398: zoomInMI.addActionListener(new java.awt.event.ActionListener() {
399: public void actionPerformed(java.awt.event.ActionEvent evt) {
400: zoomActionPerformed(evt);
401: }
402: });
403:
404: backgroundPopupMenu.add(zoomInMI);
405:
406: zoomOutMI.setText("Zoom Out");
407: zoomOutMI
408: .addActionListener(new java.awt.event.ActionListener() {
409: public void actionPerformed(
410: java.awt.event.ActionEvent evt) {
411: zoomActionPerformed(evt);
412: }
413: });
414:
415: backgroundPopupMenu.add(zoomOutMI);
416:
417: zoomShowAllMI.setText("Show All");
418: zoomShowAllMI
419: .addActionListener(new java.awt.event.ActionListener() {
420: public void actionPerformed(
421: java.awt.event.ActionEvent evt) {
422: zoomActionPerformed(evt);
423: }
424: });
425:
426: backgroundPopupMenu.add(zoomShowAllMI);
427:
428: zoomResetMI.setText("Reset");
429: zoomResetMI
430: .addActionListener(new java.awt.event.ActionListener() {
431: public void actionPerformed(
432: java.awt.event.ActionEvent evt) {
433: zoomActionPerformed(evt);
434: }
435: });
436:
437: backgroundPopupMenu.add(zoomResetMI);
438:
439: backgroundPopupMenu.add(jSeparator1);
440:
441: hideGraphsMI.setText("Hide Graphs");
442: hideGraphsMI.setToolTipText("Hide all the Branch Graphs");
443: hideGraphsMI
444: .addActionListener(new java.awt.event.ActionListener() {
445: public void actionPerformed(
446: java.awt.event.ActionEvent evt) {
447: hideGraphsMIActionPerformed(evt);
448: }
449: });
450:
451: backgroundPopupMenu.add(hideGraphsMI);
452:
453: sgViewMenu.setText("Scene Graph");
454: circularLayoutMI.setLabel("Circular");
455: circularLayoutMI
456: .addActionListener(new java.awt.event.ActionListener() {
457: public void actionPerformed(
458: java.awt.event.ActionEvent evt) {
459: circularLayoutMIActionPerformed(evt);
460: }
461: });
462:
463: sgViewMenu.add(circularLayoutMI);
464:
465: simpleLayoutMI.setText("Simple");
466: simpleLayoutMI
467: .addActionListener(new java.awt.event.ActionListener() {
468: public void actionPerformed(
469: java.awt.event.ActionEvent evt) {
470: simpleLayoutMIActionPerformed(evt);
471: }
472: });
473:
474: sgViewMenu.add(simpleLayoutMI);
475:
476: dummyMenu.add(sgViewMenu);
477:
478: setTitle("Editor");
479: setName("editorFrame");
480: jScrollPane1
481: .setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
482: jScrollPane1
483: .setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
484: jScrollPane1.setPreferredSize(new java.awt.Dimension(600, 600));
485: jScrollPane1.setAutoscrolls(true);
486: treePanel.addMouseListener(new java.awt.event.MouseAdapter() {
487: public void mousePressed(java.awt.event.MouseEvent evt) {
488: treePanelMousePressed(evt);
489: }
490:
491: public void mouseReleased(java.awt.event.MouseEvent evt) {
492: treePanelMouseReleased(evt);
493: }
494:
495: public void mouseClicked(java.awt.event.MouseEvent evt) {
496: treePanelMouseClicked(evt);
497: }
498:
499: public void mouseEntered(java.awt.event.MouseEvent evt) {
500: treePanelMouseEntered(evt);
501: }
502: });
503:
504: jScrollPane1.setViewportView(treePanel);
505:
506: getContentPane()
507: .add(jScrollPane1, java.awt.BorderLayout.CENTER);
508:
509: }//GEN-END:initComponents
510:
511: private void showMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showMenuActionPerformed
512: // Add your handling code here:
513: SGNode node = (SGNode) editControl.getCurrentNode();
514: boolean wasLive = node.isLive();
515: int axis;
516: node.setLive(false);
517: if (evt.getSource() == showPosX)
518: axis = ViewUtils.POSITIVE_X_AXIS;
519: else if (evt.getSource() == showPosY)
520: axis = ViewUtils.POSITIVE_Y_AXIS;
521: else if (evt.getSource() == showPosZ)
522: axis = ViewUtils.POSITIVE_Z_AXIS;
523: else if (evt.getSource() == showNegX)
524: axis = ViewUtils.NEGATIVE_X_AXIS;
525: else if (evt.getSource() == showNegY)
526: axis = ViewUtils.NEGATIVE_Y_AXIS;
527: else if (evt.getSource() == showNegZ)
528: axis = ViewUtils.NEGATIVE_Z_AXIS;
529: else {
530: ErrorManager.getDefault().notify(
531: new RuntimeException("Unknown axis"),
532: ErrorHandler.WARNING);
533: return;
534: }
535:
536: double distance = ViewUtils.setViewpoint(context.getUniverse()
537: .getViewingPlatform().getViewPlatformTransform(), node
538: .getJ3dNode().getBounds(), context.getUniverse()
539: .getViewer().getView().getFieldOfView(), axis);
540: View view = context.getUniverse().getViewer().getView();
541: double backClip = view.getBackClipDistance();
542:
543: if (distance > backClip) {
544: view.setBackClipDistance(distance);
545: context.getEventProcessor().postEvent(
546: new ViewClipDistanceChangedEvent(view
547: .getFrontClipDistance(), distance));
548: }
549: node.setLive(wasLive);
550: }//GEN-LAST:event_showMenuActionPerformed
551:
552: private void treePanelMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treePanelMouseEntered
553: // Add your handling code here:
554: CutAction cutAction = (CutAction) ActionManager
555: .getAction(CutAction.class);
556: cutAction.setEnabled(cutEnabled);
557: cutAction.setActionCallback(this );
558: CopyAction copyAction = (CopyAction) ActionManager
559: .getAction(CopyAction.class);
560: copyAction.setEnabled(copyEnabled);
561: copyAction.setActionCallback(this );
562: PasteAction pasteAction = (PasteAction) ActionManager
563: .getAction(PasteAction.class);
564: pasteAction.setEnabled(pasteEnabled);
565: pasteAction.setActionCallback(this );
566: DeleteAction deleteAction = (DeleteAction) ActionManager
567: .getAction(DeleteAction.class);
568: deleteAction.setEnabled(deleteEnabled);
569: deleteAction.setActionCallback(this );
570: }//GEN-LAST:event_treePanelMouseEntered
571:
572: private void simpleLayoutMIActionPerformed(
573: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simpleLayoutMIActionPerformed
574: // Add your handling code here:
575: setTreeLayout(J3dTreePanel.SIMPLE_LAYOUT);
576: }//GEN-LAST:event_simpleLayoutMIActionPerformed
577:
578: private void circularLayoutMIActionPerformed(
579: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_circularLayoutMIActionPerformed
580: // Add your handling code here:
581: setTreeLayout(J3dTreePanel.CIRCULAR_LAYOUT);
582: }//GEN-LAST:event_circularLayoutMIActionPerformed
583:
584: private void hideGraphsMIActionPerformed(
585: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideGraphsMIActionPerformed
586: // Add your handling code here:
587: SGGroup root = (SGGroup) sceneGraphControl.getViewRoot();
588:
589: for (int i = 0; i < root.numChildren(); i++)
590: ((SGGroup) root.getChild(i)).hideChildren(true);
591:
592: treePanel.layoutTree();
593: }//GEN-LAST:event_hideGraphsMIActionPerformed
594:
595: private void enableHighlight3DModeMIActionPerformed(
596: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableHighlight3DModeMIActionPerformed
597: // Add your handling code here:
598: highlight3DMI.setEnabled(enableHighlight3DModeMI.isSelected());
599: sceneGraphControl
600: .setHighlight3DModeEnable(enableHighlight3DModeMI
601: .isSelected());
602: }//GEN-LAST:event_enableHighlight3DModeMIActionPerformed
603:
604: private void highlight3DMIActionPerformed(
605: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_highlight3DMIActionPerformed
606: // Add your handling code here:
607: if (highlightedNode != null)
608: sceneGraphControl.setHighlight3D(highlightedNode, false);
609:
610: highlightedNode = editControl.getCurrentNode();
611: sceneGraphControl.setHighlight3D(highlightedNode, true);
612: }//GEN-LAST:event_highlight3DMIActionPerformed
613:
614: private void showOneChildLevelMIActionPerformed(
615: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showOneChildLevelMIActionPerformed
616: // Add your handling code here:
617: SGGroup grp = (SGGroup) editControl.getCurrentNode();
618: grp.hideChildren(false);
619:
620: for (int i = 0; i < grp.numChildren(); i++) {
621: SGObject child = grp.getChild(i);
622: if (child instanceof SGGroup)
623: ((SGGroup) child).hideChildren(true);
624: }
625:
626: treePanel.layoutTree();
627:
628: }//GEN-LAST:event_showOneChildLevelMIActionPerformed
629:
630: private void zoomActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zoomActionPerformed
631: // Add your handling code here:
632: if (evt.getSource() == zoomInMI)
633: setZoom(ZOOM_IN);
634: else if (evt.getSource() == zoomOutMI)
635: setZoom(ZOOM_OUT);
636: else if (evt.getSource() == zoomShowAllMI)
637: setZoom(ZOOM_SHOW_ALL);
638: else if (evt.getSource() == zoomResetMI)
639: setZoom(ZOOM_RESET);
640: }//GEN-LAST:event_zoomActionPerformed
641:
642: /**
643: * Allow the user to select the target for the currently selected
644: * Behavior node
645: */
646: private void setBehaviorTargetActionPerformed(
647: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_setBehaviorTargetActionPerformed
648: // Add your handling code here:
649: // Draw a rubber band line to show we are in this mode
650: treePanel.setTargetBehaviorSelection(true,
651: (SGBehavior) editControl.getCurrentNode());
652: }//GEN-LAST:event_setBehaviorTargetActionPerformed
653:
654: public void setZoom(int zoom) {
655: switch (zoom) {
656: case ZOOM_IN:
657: treePanel.zoomIn(mousePosForPopup);
658: break;
659: case ZOOM_OUT:
660: treePanel.zoomOut(mousePosForPopup);
661: break;
662: case ZOOM_SHOW_ALL:
663: treePanel.zoomShowAll();
664: break;
665: case ZOOM_RESET:
666: treePanel.zoomReset();
667: break;
668: }
669: if (treePanel.getCurrentZoom() < 1.0f)
670: zoomInMI.setEnabled(true);
671: else
672: zoomInMI.setEnabled(false);
673: }
674:
675: private void hideChildrenCBActionPerformed(
676: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_hideChildrenCBActionPerformed
677: // Add your handling code here:
678: ((SGGroup) editControl.getCurrentNode())
679: .hideChildren(hideChildrenCB.getState());
680: treePanel.layoutTree();
681: }//GEN-LAST:event_hideChildrenCBActionPerformed
682:
683: private void showBoundsCBActionPerformed(
684: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showBoundsCBActionPerformed
685: // Add your handling code here:
686: if (showBoundsVisualTool == null) {
687: showBoundsVisualTool = new ShowBoundsVisualTool();
688: VisualToolManager.getManager()
689: .addTool(showBoundsVisualTool);
690: }
691:
692: showBoundsVisualTool.showBounds(showBoundsCB.getState(),
693: editControl.getCurrentNode());
694:
695: editControl.getCurrentNode().setBoundsVisible(
696: showBoundsCB.getState());
697: }//GEN-LAST:event_showBoundsCBActionPerformed
698:
699: public void setTreeLayout(int treeLayout) {
700: treePanel.setTreeLayout(treeLayout);
701: }
702:
703: public void deleteNode() {
704: editControl.deleteCurrentNode();
705: treePanel.layoutTree();
706: }
707:
708: public void pasteNode() {
709: editControl.pasteNode();
710: treePanel.layoutTree();
711: }
712:
713: public void copyNode() {
714: editControl.copyCurrentNode();
715: }
716:
717: public void cutNode() {
718: editControl.cutCurrentNode();
719: treePanel.layoutTree();
720: }
721:
722: /**
723: * Node creation listener interface.
724: */
725: public void nodeCreated(javax.media.j3d.Node node, boolean autoName) {
726: addChild(node, autoName);
727: }
728:
729: /**
730: * Add child to the currently selected node and update the
731: * display.
732: *
733: * @param child The new child node
734: * @param autoName Flag indicating if the child should be automatically named
735: */
736: public void addChild(Node child, boolean autoName) {
737: SGGroup treeNode = (SGGroup) editControl.getCurrentNode();
738: treeNode.setLive(false);
739:
740: Group node = (Group) treeNode.getJ3dNode();
741: sceneGraphControl.addChild(treeNode, child, autoName);
742: node.addChild(child);
743: treePanel.layoutTree();
744: treeNode.setLive(true);
745: }
746:
747: /**
748: * User request to edit the parameters of a node
749: */
750: private void editMActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editMActionPerformed
751: // Add your handling code here:
752: editControl.editCurrentNode();
753: }//GEN-LAST:event_editMActionPerformed
754:
755: private void treePanelMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treePanelMouseReleased
756: // Add your handling code here:
757: showPopup(evt);
758: }//GEN-LAST:event_treePanelMouseReleased
759:
760: private void treePanelMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treePanelMousePressed
761: // Add your handling code here:
762: doSelection(evt);
763: showPopup(evt);
764: }//GEN-LAST:event_treePanelMousePressed
765:
766: private void treePanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_treePanelMouseClicked
767:
768: treePanel.test(evt);
769:
770: // If we are in the process of selecing a Target for a behavior
771: // then ignore this event. It will be handled by J3dTreePanel
772: if (treePanel.selectingBehaviorTarget())
773: return;
774:
775: doSelection(evt);
776:
777: showPopup(evt);
778: }//GEN-LAST:event_treePanelMouseClicked
779:
780: private void doSelection(java.awt.event.MouseEvent evt) {
781: TVObject pickedNode = (TVObject) treePanel.pickNode(evt.getX(),
782: evt.getY());
783: //System.out.println("Picked "+pickedNode+" "+evt.getClickCount());
784: if (pickedNode != null)
785: editControl.selectNode(pickedNode.getSGObject());
786: else
787: editControl.selectNode(null);
788:
789: if (highlightedNode != null)
790: sceneGraphControl.setHighlight3D(highlightedNode, false);
791:
792: if (pickedNode == null) {
793: cutEnabled = false;
794: copyEnabled = false;
795: pasteEnabled = false;
796: deleteEnabled = false;
797: ActionManager.getAction(CutAction.class).setEnabled(
798: cutEnabled);
799: ActionManager.getAction(CopyAction.class).setEnabled(
800: copyEnabled);
801: ActionManager.getAction(PasteAction.class).setEnabled(
802: pasteEnabled);
803: ActionManager.getAction(DeleteAction.class).setEnabled(
804: deleteEnabled);
805: enableAddChild(false);
806: return;
807: } else {
808: cutEnabled = true;
809: copyEnabled = true;
810: deleteEnabled = true;
811:
812: ActionManager.getAction(CutAction.class).setEnabled(
813: cutEnabled);
814: ActionManager.getAction(CopyAction.class).setEnabled(
815: copyEnabled);
816: ActionManager.getAction(DeleteAction.class).setEnabled(
817: deleteEnabled);
818: }
819:
820: if (evt.getClickCount() > 1)
821: editControl.editCurrentNode();
822:
823: pasteEnabled = editControl.isCurrentNodeGroup()
824: & !editControl.isPasteBufferNull();
825: ActionManager.getAction(PasteAction.class).setEnabled(
826: pasteEnabled);
827: enableAddChild(editControl.isCurrentNodeGroup());
828: }
829:
830: private boolean showPopup(final java.awt.event.MouseEvent evt) {
831: if (nodePopupMenu.getComponent(0) != addChildMenu)
832: nodePopupMenu.insert(addChildMenu, 0);
833: if (evt.isPopupTrigger()) {
834: TVObject tvObject = (TVObject) treePanel.pickNode(evt
835: .getX(), evt.getY());
836:
837: if (tvObject == null) {
838: /* Point viewOrigin = jScrollPane1.getViewport().getViewPosition();
839: backgroundPopupMenu.show( treePanel, evt.getX() - viewOrigin.x,
840: evt.getY() - viewOrigin.y );
841: */
842: mousePosForPopup = evt.getPoint();
843: backgroundPopupMenu.show(treePanel, evt.getX(), evt
844: .getY());
845: return true;
846: }
847:
848: SGObject pickedNode = tvObject.getSGObject();
849:
850: // Never show the menu if the node is the dummy Locale Node
851: if (pickedNode instanceof SGLocale)
852: return false;
853:
854: if (pickedNode != null
855: && pickedNode != editControl.getCurrentNode())
856: editControl.selectNode((SGObject) pickedNode);
857:
858: if (editControl.getCurrentNode() != null) {
859: if (readOnly || editControl.isCurrentNodeReadOnly()) {
860: enableAddChild(false);
861: setTargetPM.setEnabled(false);
862: if (editControl.isCurrentNodeGroup())
863: hideChildrenCB.setEnabled(true);
864: else
865: hideChildrenCB.setEnabled(false);
866:
867: } else {
868: showOneChildLevelMI.setEnabled(false);
869: if (editControl.isCurrentNodeGroup()) {
870: enableAddChild(true);
871: hideChildrenCB.setEnabled(true);
872: hideChildrenCB.setState(((SGGroup) editControl
873: .getCurrentNode()).childrenHidden());
874: if (hideChildrenCB.isSelected())
875: showOneChildLevelMI.setEnabled(true);
876: } else {
877: enableAddChild(false);
878: hideChildrenCB.setEnabled(false);
879: hideChildrenCB.setState(false);
880: }
881:
882: if (editControl.isCurrentNodeBehavior()) {
883: setTargetPM.setEnabled(true);
884: } else {
885: setTargetPM.setEnabled(false);
886: }
887: }
888:
889: showBoundsCB.setState(editControl.getCurrentNode()
890: .getBoundsVisible());
891:
892: /* Point viewOrigin = jScrollPane1.getViewport().getViewPosition();
893: nodePopupMenu.show( treePanel, evt.getX() - viewOrigin.x,
894: evt.getY() - viewOrigin.y );
895: */
896: javax.swing.SwingUtilities.invokeLater(new Thread() {
897: public void run() {
898: nodePopupMenu.show(treePanel, evt.getX(), evt
899: .getY());
900: }
901: });
902: return true;
903: }
904: }
905:
906: return false;
907: }
908:
909: private void enableAddChild(boolean enable) {
910: addChildMenu.setEnabled(enable);
911: if (groupSelectionListener != null)
912: groupSelectionListener.groupSelected(enable);
913: }
914:
915: /**
916: * Called by EventProcessor when an event occurs for which this
917: * listener has registered interest
918: */
919: public void processFlyEvent(
920: final org.jdesktop.j3dfly.event.FlyEvent evt) {
921: if (evt instanceof NamedObjectSelectionEvent)
922: processNamedObjectSelectionEvent((NamedObjectSelectionEvent) evt);
923: else if (evt instanceof FileLoadEvent) {
924: // TODO This event is asynchronous and so is the window event which
925: // will cause a layout so we should check that they arrive in the
926: // correct order.
927: setZoom(ZOOM_SHOW_ALL);
928: }
929: }
930:
931: private void processNamedObjectSelectionEvent(
932: NamedObjectSelectionEvent evt) {
933: SGObject treeNode = sceneGraphControl
934: .getTreeNode((SceneGraphObject) context
935: .getNameControl().getNamedObject(evt.getName()));
936: treePanel.showNode((TVObject) treeNode.getTreeViewObject());
937: editControl.selectNode(treeNode);
938: editControl.editCurrentNode();
939: }
940:
941: /**
942: * Called by the Callback action with which this is
943: * registered whenever the action receives an ActionEvent
944: *
945: * @param action The CallbackAction originating this callback
946: * @param actionEvent The event that triggered the callback
947: */
948: public void actionCallback(CallbackAction action,
949: java.awt.event.ActionEvent actionEvent) {
950: if (action instanceof CutAction)
951: cutNode();
952: else if (action instanceof CopyAction)
953: copyNode();
954: else if (action instanceof PasteAction)
955: pasteNode();
956: else if (action instanceof DeleteAction)
957: deleteNode();
958: }
959:
960: // Variables declaration - do not modify//GEN-BEGIN:variables
961: private javax.swing.JPopupMenu backgroundPopupMenu;
962: private javax.swing.JMenuItem circularLayoutMI;
963: private javax.swing.JPopupMenu dummyMenu;
964: private javax.swing.JMenuItem editM;
965: private javax.swing.JCheckBoxMenuItem enableHighlight3DModeMI;
966: private javax.swing.JCheckBoxMenuItem hideChildrenCB;
967: private javax.swing.JMenuItem hideGraphsMI;
968: private javax.swing.JMenuItem highlight3DMI;
969: private javax.swing.JScrollPane jScrollPane1;
970: private javax.swing.JSeparator jSeparator1;
971: private javax.swing.JPopupMenu nodePopupMenu;
972: private javax.swing.JMenuItem setTargetPM;
973: private javax.swing.JMenu sgViewMenu;
974: private javax.swing.JCheckBoxMenuItem showBoundsCB;
975: private javax.swing.JMenu showM;
976: private javax.swing.JMenuItem showNegX;
977: private javax.swing.JMenuItem showNegY;
978: private javax.swing.JMenuItem showNegZ;
979: private javax.swing.JMenuItem showOneChildLevelMI;
980: private javax.swing.JMenuItem showPosX;
981: private javax.swing.JMenuItem showPosY;
982: private javax.swing.JMenuItem showPosZ;
983: private javax.swing.JMenuItem simpleLayoutMI;
984: private org.jdesktop.j3dedit.scenegrapheditor.J3dTreePanel treePanel;
985: private javax.swing.JMenuItem zoomInMI;
986: private javax.swing.JMenuItem zoomOutMI;
987: private javax.swing.JMenuItem zoomResetMI;
988: private javax.swing.JMenuItem zoomShowAllMI;
989: // End of variables declaration//GEN-END:variables
990:
991: }
|