package cl.jtv;
/*
 * ContextoSubmaquina.java
 *
 * Created on 13 de octubre de 2002, 06:50 PM
 */

/**
 *
 * @author  Administrador
 * @version 
 */
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.*;
import javax.swing.JTree;
import java.util.*;


public class ContextoSubmaquina {
    
    NodeTreeTrace rootTreeTrace;
    Cinta[] arrayOfTapes0;
    Hashtable parametros;
    Hashtable variables;
    ContextoSubmaquina contextoSubmaquinaPadre;
    /** Creates new ContextoSubmaquina */
    public ContextoSubmaquina(String nombre) {
        
        rootTreeTrace = new NodeTreeTrace(nombre);
    }
    
    
    public boolean accion(Cinta[] _arrayOfTapes){
       
        
        
        if(this.rootTreeTrace.estado==Maquina.ESTADO_ND && rootTreeTrace.choosedNodeND!=null){
            
            Vector pathVector = NodeTreeTrace.getCompletePathVector(rootTreeTrace.choosedNodeND);
            Enumeration en = pathVector.elements();
            while(en.hasMoreElements()){                
                NodeTreeTrace auxNode2 = (NodeTreeTrace)en.nextElement();
                int iconValue = ((NodeTreeTrace)auxNode2).getIconValue();
                if(!auxNode2.isRoot() && iconValue != JTV.MyRenderer.ICONO_STOP && iconValue != JTV.MyRenderer.ICONO_WARNING && iconValue != JTV.MyRenderer.ICONO_EXPANDIR && iconValue != JTV.MyRenderer.ICONO_RECHAZA)
                
                if(!(auxNode2.getMachine() instanceof Submaquina)){
                    
                    auxNode2.getMachine().accion(_arrayOfTapes,this.rootTreeTrace.dicMetavalores);
                }else{                                        
                   auxNode2.contextoSubmaquina.rootTreeTrace.arrayOfTapes[0] = _arrayOfTapes[auxNode2.getMachine().getIndiceCinta()];             
                   for(int j=1;j<auxNode2.contextoSubmaquina.rootTreeTrace.arrayOfTapes.length;j++)
                        auxNode2.contextoSubmaquina.rootTreeTrace.arrayOfTapes[j]=new Cinta(auxNode2.contextoSubmaquina.rootTreeTrace.arrayOfTapes0[j]);
                   auxNode2.contextoSubmaquina.accion(auxNode2.contextoSubmaquina.rootTreeTrace.arrayOfTapes);              
                }
            }            
            return true;
        }
        
        
        
        NodeTreeTrace auxNode = this.rootTreeTrace;
        
        for(int i=1;i<=this.rootTreeTrace.getChildCount();i++){
            int iconValue = ((NodeTreeTrace)auxNode).getIconValue();
            if(!auxNode.isRoot() && iconValue != JTV.MyRenderer.ICONO_STOP && iconValue != JTV.MyRenderer.ICONO_WARNING && iconValue != JTV.MyRenderer.ICONO_EXPANDIR && iconValue != JTV.MyRenderer.ICONO_RECHAZA)
                
                if(!(auxNode.getMachine() instanceof Submaquina)){
                    
                    auxNode.getMachine().accion(_arrayOfTapes,this.rootTreeTrace.dicMetavalores);
                }else{
                                        
                   auxNode.contextoSubmaquina.rootTreeTrace.arrayOfTapes[0] = _arrayOfTapes[auxNode.getMachine().getIndiceCinta()];             
                   for(int j=1;j<auxNode.contextoSubmaquina.rootTreeTrace.arrayOfTapes.length;j++)
                        auxNode.contextoSubmaquina.rootTreeTrace.arrayOfTapes[j]=new Cinta(auxNode.contextoSubmaquina.rootTreeTrace.arrayOfTapes0[j]);
                   auxNode.contextoSubmaquina.accion(auxNode.contextoSubmaquina.rootTreeTrace.arrayOfTapes);              
                }
                auxNode = (NodeTreeTrace)auxNode.getNextNode();
                
        }
        return true;
   } 

}
