Menu

[r47]: / GraphScript / trunk / ls / graph / Main.java  Maximize  Restore  History

Download this file

136 lines (121 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
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 start()
{
Graph g = initGraph();
ScriptableGraph sg = new ScriptableGraph(g);
GraphScriptEngine eng = new GraphScriptEngine(sg);
String defScript = getDefaultScriptText();
MainWindow mainWindow = new MainWindow(eng,g,eng.getScriptUIUtils(),defScript);
mainWindow.setExtendedState(JFrame.MAXIMIZED_BOTH);
mainWindow.setVisible(true);
}
private String getDefaultScriptText()
{
String defFilename = getProperty("DEFAULT_SCRIPT",null);
if (defFilename != null)
{
File f = new File(defFilename);
if (!f.isAbsolute())
{
String dir = getProperty("SCRIPTS_DIR",null);
if (dir == null) return null;
f = new File(dir + File.separator + defFilename);
}
BufferedReader br = null;
StringBuffer sb = new StringBuffer();
try
{
br = new BufferedReader(new FileReader(f));
String line = br.readLine();
while (line != null)
{
sb.append(line).append('\n');
line = br.readLine();
}
}
catch (IOException exn)
{
Utils.exn(exn);
return null;
}
finally
{
try {if (br != null) br.close(); }
catch (IOException exn) { Utils.exn(exn); }
}
return sb.toString();
}
return null;
}
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(15,42);
Graph graph = (Graph)gGen.generateGraph();
return graph;
}
/**
* @param args
*/
public static void main(String[] args)
{
Main m = new Main();
m.start();
}
}
MongoDB Logo MongoDB