package formulator;

import java.util.HashMap;
import java.util.Vector;

import javax.swing.SwingUtilities;

public class GraphControl {
	
	public Vector<GraphFunction> graphlist = new Vector<GraphFunction>();
	public HashMap<String, FormulaElement> formulas;
	public GraphControl(Vector<GraphFunction> graphs, HashMap<String, FormulaElement> map){
		graphlist = graphs;
		formulas = map;
		System.out.println("Running graph...");
		//doGraph(graphlist);
	}
	
	public void doGraph(final Vector<GraphFunction> graphlist2) {
	//public static void main(String args[]) {

		  SwingUtilities.invokeLater(new Runnable() {
		 
		//public Vector<GraphFunction> graphlist = graphlist2;
	  

		@Override
		   public void run() {
			   	//String str = "cos(x)";
			   	String str = "x(4/3)";
				//String str = "sin(x)";
				//String str = "(x+2)(x-(y^7)+cos(2^x))";
				FormulaElement result = (FormulaElement.parseFormula(str, formulas));
				//Pass in the root node of the formula to the CartesianFrame constructor
				double min =-5;
				double max =5;
				double incre = 1;
				Vector<GraphFunction> graphs = new Vector<GraphFunction>();
				GraphFunction test = new GraphFunction(result, "x", min, max, incre);
				graphs.add(test);
			   	String str2 = "cos(x)";
			   	String str3 = "x(2/3)";

				FormulaElement result2 = (FormulaElement.parseFormula(str2, formulas));
				FormulaElement result3 = (FormulaElement.parseFormula(str3, formulas));

				GraphFunction test2 = new GraphFunction(result2, "x", min, max, incre);
				GraphFunction test3 = new GraphFunction(result3, "x", min, max, incre);
				graphs.add(test2);
				graphs.add(test3);

				CartesianFrame frame = new CartesianFrame(graphs, false, true, true);
				frame.showUI();
		   }
		  });
		 }
}

@@ -426,18 +426,16 @@
 ..%22);%0A%09%09
-//
 doGraph(
@@ -710,16 +710,18 @@
 run() %7B%0A
+//
 %09%09%09   %09/
@@ -736,32 +736,34 @@
 str = %22cos(x)%22;%0A
+//
 %09%09%09   %09String st
@@ -772,24 +772,26 @@
 = %22x(4/3)%22;%0A
+//
 %09%09%09%09//String
@@ -803,24 +803,26 @@
 = %22sin(x)%22;%0A
+//
 %09%09%09%09//String
@@ -855,16 +855,18 @@
 2%5Ex))%22;%0A
+//
 %09%09%09%09Form
@@ -927,24 +927,26 @@
 formulas));%0A
+//
 %09%09%09%09//Pass i
@@ -1010,16 +1010,18 @@
 tructor%0A
+//
 %09%09%09%09doub
@@ -1032,16 +1032,18 @@
 in =-5;%0A
+//
 %09%09%09%09doub
@@ -1053,16 +1053,18 @@
 max =5;%0A
+//
 %09%09%09%09doub
@@ -1077,16 +1077,18 @@
 re = 1;%0A
+//
 %09%09%09%09Vect
@@ -1143,16 +1143,18 @@
 ion%3E();%0A
+//
 %09%09%09%09Grap
@@ -1211,32 +1211,34 @@
 n, max, incre);%0A
+//
 %09%09%09%09graphs.add(t
@@ -1243,16 +1243,18 @@
 (test);%0A
+//
 %09%09%09   %09S
@@ -1276,16 +1276,18 @@
 os(x)%22;%0A
+//
 %09%09%09   %09S
@@ -1309,17 +1309,21 @@
 (2/3)%22;%0A
-%0A
+//%0A//
 %09%09%09%09Form
@@ -1390,16 +1390,18 @@
 ulas));%0A
+//
 %09%09%09%09Form
@@ -1468,17 +1468,21 @@
 ulas));%0A
-%0A
+//%0A//
 %09%09%09%09Grap
@@ -1545,24 +1545,26 @@
 ax, incre);%0A
+//
 %09%09%09%09GraphFun
@@ -1623,24 +1623,26 @@
 ax, incre);%0A
+//
 %09%09%09%09graphs.a
@@ -1652,16 +1652,18 @@
 test2);%0A
+//
 %09%09%09%09grap
@@ -1729,17 +1729,20 @@
 me(graph
-s
+list
 , false,

remove test code again