package EDU.neu.ccs.demeter.tools.apstudio.graphedit;
import java.awt.*;
import java.io.*;
import java.util.*;
import EDU.neu.ccs.demeter.*;
import EDU.neu.ccs.demeter.common.tg.*;


import EDU.neu.ccs.demeter.*;
class SelectMarkedVisitor extends UniversalVisitor {
  protected boolean bflag;
  public boolean get_bflag() { return bflag; }
  public void set_bflag(boolean new_bflag)
    { bflag = new_bflag; }
  protected boolean cflag;
  public boolean get_cflag() { return cflag; }
  public void set_cflag(boolean new_cflag)
    { cflag = new_cflag; }
  protected boolean anyEdgeflag;
  public boolean get_anyEdgeflag() { return anyEdgeflag; }
  public void set_anyEdgeflag(boolean new_anyEdgeflag)
    { anyEdgeflag = new_anyEdgeflag; }
  protected String graphString;
  public String get_graphString() { return graphString; }
  public void set_graphString(String new_graphString)
    { graphString = new_graphString; }
  protected String ioeString;
  public String get_ioeString() { return ioeString; }
  public void set_ioeString(String new_ioeString)
    { ioeString = new_ioeString; }
  SelectMarkedVisitor() { super(); }
  public SelectMarkedVisitor(boolean bflag, boolean cflag, boolean anyEdgeflag, String graphString, String ioeString) {
    super();
    set_bflag(bflag);
    set_cflag(cflag);
    set_anyEdgeflag(anyEdgeflag);
    set_graphString(graphString);
    set_ioeString(ioeString);
  }

		Hashtable vtable;
		Hashtable etable;
	  public void before(UGraph host) {
		host.idToVertexTable = new Hashtable();
		host.idToEdgeTable = new Hashtable();
		host.hashinit(host.idToVertexTable , host.idToEdgeTable);
//		System.out.println("in getCdString");
		vtable = host.idToVertexTable ;
		etable = host.idToEdgeTable ;
	
		 graphString  = graphString + "#Class #Dictionary #Graph\n"; 
	}
  public void before(Package host) { graphString  = graphString + "\npackage "; }
  public void before(PackageName host) { graphString  = graphString + host.toString();}
  public void before(Name host) { graphString  = graphString + host.toString();}
  public void before(Import host) { graphString  = graphString + "import ";}
  public void after(Import host) { graphString  = graphString + ";\n";}
  public void before(ImportAllClasses host) { graphString  = graphString + ".*";}
  public void after(Package host) { graphString  = graphString + ";\n" ; }
  public void before(JavaCode host) { graphString  = graphString + "\n(@" + host.get_code() + "@" + ")\n"; }
  public void before(UVertex_List host) { graphString = graphString  + "#Vertex #List\n"; }
  public void around(AroundContinuation subtraversal, UVertex host) { subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UConstVertex host) { 		if(host.isMarked())
			{
			graphString = graphString +"\n#ConstVertex "; 
			subtraversal.apply();
			}
	}
  public void around(AroundContinuation subtraversal, UBefore host) { graphString = graphString + "#Before \"" + host.get_syntax() + "\" "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UAfter host) { graphString = graphString + "#After \"" + host.get_syntax() + "\" "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UAltVertex host) { graphString = graphString + "\n#AltVertex "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, PublicIdentifier host) { graphString = graphString + "#public "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, FinalIdentifier host) { graphString = graphString + "#final "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, YaParse host) { graphString = graphString + "#parse "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, NopParse host) { graphString = graphString + "#noparse "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UInterface host) { graphString = graphString + "\n#Interface "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, PublicModifier host) { graphString = graphString + "#public "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UTermConstVertex host) { graphString = graphString +"\n#TermConstVertex "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UTermInterface host) { graphString = graphString +"\n#TermInterface "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UVertexName host) { graphString = graphString + host.get_name() +" "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, Coordinates host) { graphString = graphString + " { "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, X host) { graphString = graphString + host.get_x() +" "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, Y host) { graphString = graphString + host.get_y() +" "; subtraversal.apply();}
  public void after(Coordinates host) { graphString = graphString + "} "; }
  public void before(IEdge_List host) { 
		bflag = true;		//in either I/OEdge_List
		cflag = false;		//dont put a comma
		anyEdgeflag = false;	//not a single edge yet
		ioeString = " ";
	}
  public void before(OEdge_List host) { 
		bflag = true;		//in either I/OEdge_List
		cflag = false;		//dont put a comma
		anyEdgeflag = false;	//not a single edge yet
		ioeString = " ";
	}
  public void after(IEdge_List host) { 
		bflag = false;
		if(anyEdgeflag)
		{
			ioeString = "#Incoming " + ioeString;
			graphString = graphString + ioeString; 
		}
	}
  public void after(OEdge_List host) { 
		bflag = false;	
		if(anyEdgeflag)
		{
			ioeString = "#Outgoing " + ioeString;
			graphString = graphString + ioeString; 
		}
	}
  public void around(AroundContinuation subtraversal, UID host) {
		if (!bflag)
		{
			graphString = graphString + host.get_id() + " " ; 
			subtraversal.apply();
		}
		else	//in either I/OEdge_List
			if( ((UEdge)etable.get(host)).isMarked() )
			{
				if(cflag)
				{
					ioeString = ioeString +" , "+ host.get_id() + " " ;
				}
				else
				{
					ioeString = ioeString + host.get_id() + " " ;
				}
			cflag = true;		//put a comma from now on
			anyEdgeflag = true;	//now atleast one edge in list
			subtraversal.apply();
			}
	}
  public void around(AroundContinuation subtraversal, UEdge_List host) {graphString  = graphString + "\n#Edge #List\n"; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UEdge host) { subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UAltEdge host) { graphString = graphString + "\n#AltEdge "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UExtendEdge host) { graphString = graphString + "\n#ExtendEdge "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UImplEdge host) { graphString = graphString + "\n#ImplEdge "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, UConstEdge host) { 		if(host.isMarked())
			{
			graphString = graphString + "\n#ConstEdge "; 
			subtraversal.apply();
			}
	}
  public void around(AroundContinuation subtraversal, UEdgeName host) { graphString = graphString + host.get_name() +" "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, Cardinality host) { graphString = graphString + "#Cardinality "; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, Lower host) { graphString = graphString + host.get_l(); subtraversal.apply();}
  public void around(AroundContinuation subtraversal, Upper host) { graphString = graphString + "..\"" + host.get_u() + "\" "; subtraversal.apply();}
  public void after(Cardinality host) { graphString = graphString + " "; }
  public void around(AroundContinuation subtraversal, FinalMod host) { graphString = graphString + "#final"; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, StaticMod host) { graphString = graphString + "#static"; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, ReadOnlyMod host) { graphString = graphString + "#read-only"; subtraversal.apply();}
  public void around(AroundContinuation subtraversal, PrivateMod host) { graphString = graphString + "#private"; subtraversal.apply();}
  void universal_trv0_bef(UniversalVisitor _v_) {
    super.universal_trv0_bef(_v_);
  }
  void universal_trv0_aft(UniversalVisitor _v_) {
    super.universal_trv0_aft(_v_);
  }
  void universal_trv0(UniversalVisitor _v_) {
    universal_trv0_bef(_v_);
    super.universal_trv0(_v_);
    universal_trv0_aft(_v_);
  }
}

