//
//      SceneComposite.java
//
//------------------------------------------------------------------------
//
//      Portions Copyright (c) 2000 SURVICE Engineering Company.
//      All Rights Reserved.
//      This file contains Original Code and/or Modifications of Original
//      Code as defined in and that are subject to the SURVICE Public
//      Source License (Version 1.2, dated December 14, 1999)
//
//      A copy of this license can be found in the doc directory
//------------------------------------------------------------------------
//
//      Developed by QUADRA Enterprises, Inc. (www.quadra-inc.com)
//      January 27, 2000
//
//      Authors:
//              John P. Williams
//              Robb P. Bush
//------------------------------------------------------------------------
package com.quadra.OpenCanvas3D;

import javax.media.j3d.*;
import javax.vecmath.*;
import java.util.*;
import javax.swing.tree.*;

/**Part of the SceneComponent Composite Structural Pattern...
*/
public class SceneComposite extends SceneComponent
{
//BranchGroup thisBranch;
Vector compList;

        public SceneComposite()
                {
                super();
                compList = new Vector();
                }

        public void AddComponent(SceneComponent sc)
                {
                compSwitch.addChild(sc.GetRootNode());
                compList.addElement(sc);
                }

        public void RemoveComponent(SceneComponent sc)
                {
                //Later
                }

        public void SetColor(float r, float g, float b)
                {
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        ((SceneComponent)e.nextElement()).SetColor(r,g,b);
                }

        public void SetTransparency(float val)
                {
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        ((SceneComponent)e.nextElement()).SetTransparency(val);
                }

        public void SolidShade()
                {
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        ((SceneComponent)e.nextElement()).SolidShade();
                }
        public void LineDrawing()
                {
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        ((SceneComponent)e.nextElement()).LineDrawing();
                }

        public SceneComponent GetCompByName(String name)
                {
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        {
                        SceneComponent thisComp = (SceneComponent)e.nextElement();
                        if (thisComp.GetName().equals(name))
                                return thisComp;
                        }
                return null;
                }

        public DefaultMutableTreeNode GetTreeNode()
                {
                //first add the top node
                DefaultMutableTreeNode thisNode = new DefaultMutableTreeNode(this);
                for (Enumeration e=compList.elements(); e.hasMoreElements();)
                        {
                        DefaultMutableTreeNode aChildNode =
                             ((SceneComponent)e.nextElement()).GetTreeNode();
                        thisNode.add(aChildNode);
                        }
                return thisNode;
                }                        

}


