Skip to content

Commit

Permalink
Create AsterMain instance
Browse files Browse the repository at this point in the history
That will help us to smoothly initialize other instances
in the feature.
  • Loading branch information
walkingice committed Dec 12, 2012
1 parent 16c0722 commit 712ea80
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions src/org/zeroxlab/aster/AsterMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,24 @@
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

import org.zeroxlab.aster.CmdConnection.SnapshotDrawer;
import org.zeroxlab.aster.cmds.AsterCommandManager;
import org.zeroxlab.aster.cmds.AsterCommand.ExecutionResult;

public class AsterMain {

public static void main(String[] args) {
if (args.length > 0) {
try {
if ("-run".equals(args[0])) {
startCLI(args[1]);
}
} catch(ArrayIndexOutOfBoundsException e) {
usage();
}
} else {
startGUI();
}
private AsterCommandManager mCmdMgr;
private CmdConnection mCmdConn;

public AsterMain() {
mCmdMgr = new AsterCommandManager();

}

public static void startCLI(String script) {
public void startCLI(String script) {
ExecutionResult result = null;
try {
result = (new AsterCommandManager()).run(script);
result = mCmdMgr.run(script);
} catch(IOException e) {
System.err.printf(e.toString());
System.exit(1);
Expand All @@ -60,15 +55,22 @@ public static void startCLI(String script) {
}
}

public static void startGUI() {
public void startGUI() {
mCmdConn = new CmdConnection(mCmdMgr);

trySetupLookFeel();
JFrame f = new JFrame("Aster");
AsterMainPanel p = new AsterMainPanel();
AsterMainPanel p = new AsterMainPanel(mCmdMgr, mCmdConn);
f.setContentPane(p);
f.setJMenuBar(p.createMenuBar());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);

SnapshotDrawer drawer = p.getSnapshotDrawer();
mCmdConn.setDrawer(drawer);
Thread thread = new Thread(mCmdConn);
thread.start();
}

private static void trySetupLookFeel() {
Expand All @@ -92,4 +94,20 @@ private static void trySetupLookFeel() {
private static void usage() {
System.out.printf("Usage: aster [-run TEST.ast]\n\n");
}

public static void main(String[] args) {
AsterMain aster = new AsterMain();
if (args.length > 0) {
try {
if ("-run".equals(args[0])) {
aster.startCLI(args[1]);
}
} catch(ArrayIndexOutOfBoundsException e) {
aster.usage();
}
} else {
aster.startGUI();
}
}

}

0 comments on commit 712ea80

Please sign in to comment.