001: /*
002: * $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/VisualToolManager.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 javax.media.j3d.*;
021: import org.jdesktop.j3dedit.scenegrapheditor.visualtools.ShowBoundsBehavior;
022: import org.jdesktop.j3dedit.scenegrapheditor.visualtools.VisualTool;
023:
024: /**
025: * Maintains all the 3D tools for this world
026: */
027: public class VisualToolManager extends BranchGroup {
028:
029: private static VisualToolManager manager = null;
030:
031: private Switch toolSwitch;
032:
033: /** Creates new VisualTools */
034: public VisualToolManager() {
035: super ();
036: toolSwitch = new Switch();
037: toolSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);
038: toolSwitch.setCapability(Switch.ALLOW_CHILDREN_READ);
039: toolSwitch.setCapability(Switch.ALLOW_CHILDREN_WRITE);
040: toolSwitch.setCapability(Switch.ALLOW_CHILDREN_EXTEND);
041: toolSwitch.setWhichChild(Switch.CHILD_ALL);
042: this .setCapability(BranchGroup.ALLOW_CHILDREN_READ);
043: this .setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
044: this .setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
045:
046: this .addChild(toolSwitch);
047:
048: manager = this ;
049: }
050:
051: /**
052: * Enable/Disable all the tools
053: *
054: * Default is enabled
055: */
056: public void enableTools(boolean enabled) {
057: if (enabled)
058: toolSwitch.setWhichChild(Switch.CHILD_ALL);
059: else
060: toolSwitch.setWhichChild(Switch.CHILD_NONE);
061: }
062:
063: /**
064: * Register a new VisualTool
065: */
066: public void addTool(VisualTool tool) {
067: toolSwitch.addChild(tool);
068:
069: System.out.println("Added Tool " + tool);
070: System.out.println("Live " + tool.isLive());
071: }
072:
073: /**
074: * Remove the tool from the manager
075: */
076: public void removeTool(VisualTool tool) {
077: for (int i = 0; i < toolSwitch.numChildren(); i++)
078: if (toolSwitch.getChild(i) == tool) {
079: toolSwitch.removeChild(i);
080: break;
081: }
082: }
083:
084: /**
085: * Returns the visualTool with the give class
086: * null if tool is not present
087: */
088: public VisualTool getVisualTool(Class toolClass) {
089: VisualTool ret = null;
090:
091: for (int i = 0; i < toolSwitch.numChildren() && ret == null; i++) {
092: if (toolSwitch.getChild(i).getClass() == toolClass)
093: ret = (VisualTool) toolSwitch.getChild(i);
094: }
095:
096: return ret;
097: }
098:
099: /**
100: * Resets all the tools, used when a new SceneGraph is displayed
101: */
102: public void resetTools() {
103: java.util.Enumeration e = toolSwitch.getAllChildren();
104: while (e.hasMoreElements())
105: ((VisualTool) e.nextElement()).reset();
106: }
107:
108: /**
109: * Return the visual tool manager it it exists, if not null is returned.
110: */
111: public static VisualToolManager getManager() {
112: return manager;
113: }
114: }
|