package ls.graph;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import javax.swing.JFrame;
import ls.graph.script.GraphScriptEngine;
import ls.graph.script.ScriptableGraph;
import ls.graph.ui.MainWindow;
import ls.util.Utils;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.random.generators.GraphGenerator;
import edu.uci.ics.jung.random.generators.SimpleRandomGenerator;
public class Main
{
// private SwingEngine swingEngine;
// private JSplitPane spltMain;
// private ScriptPanel scriptPanel;
private static Properties initProps = new Properties();
static
{
BufferedReader br = null;
try
{
File f = new File("graphscript.ini");
br = new BufferedReader(new FileReader(f));
initProps.load(br);
}
catch (IOException exn)
{
Utils.err("while loading ini file: " + exn.getMessage());
}
finally
{
try { if (br != null) br.close(); }
catch (IOException exn) { Utils.exn(exn); }
}
}
private void show()
{
// ConfigurableScriptEngine eng = new ConfigurableScriptEngine();
Graph g = initGraph();
ScriptableGraph sg = new ScriptableGraph(g);
// ScriptUIUtils suu =
// new ScriptUIUtils(
// g,
// new ScriptableVertexPaintFunction(Color.RED),
// new ScriptableVertexStringer());
GraphScriptEngine eng = new GraphScriptEngine(sg);
//for now, set simple bindings
// Map<String, Object> bindings = new HashMap<String, Object>();
// bindings.put("Graph", g);
//
// bindings.put("GraphUI", suu);
// bindings.put("VC_BLACK", VertexColors.BLACK);
// bindings.put("VC_RED", VertexColors.RED);
// bindings.put("VC_GREY", VertexColors.GREY);
// bindings.put("VC_WHITE", VertexColors.WHITE);
// eng.setBindings(bindings);
// eng.packageImport("edu.uci.ics.jung.graph");
// //eng.javaImport("edu.uci.ics.jung.graph.visualization");
// eng.packageImport("ls.graph.ui"); //For ScriptUIUtils, VertexColors
// eng.classImport("ls.graph.ui.VertexColors");
MainWindow mainWindow = new MainWindow(eng,g,eng.getScriptUIUtils());
mainWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
mainWindow.setVisible(true);
}
public static String getProperty(String key)
{
String val = initProps.getProperty(key);
return val;
}
public static List<String> getPropertyValues(String key)
{
String sValues = getProperty(key,"");
if ("".equals(sValues) || sValues == null)
return Arrays.asList(new String[] {}); //return empty list
return Arrays.asList(sValues.split(","));
}
public static String getProperty(String key, String defVal)
{
String ret = getProperty(key);
return ret == null ? defVal : ret;
}
private Graph initGraph()
{
GraphGenerator gGen = new SimpleRandomGenerator(5,4);
Graph graph = (Graph)gGen.generateGraph();
return graph;
}
/**
* @param args
*/
public static void main(String[] args)
{
Main m = new Main();
m.show();
}
}