@@ -38,6 +38,7 @@ public class Main {
3838 private static Double _dtime = null ;
3939 private static String _inFile = null ;
4040 private static String _outFile = null ;
41+ private static String _mode = null ;
4142 private static JSONObject _forceLawsInfo = null ;
4243
4344 // factories
@@ -71,8 +72,8 @@ private static void parseArgs(String[] args) {
7172 parseDeltaTimeOption (line );
7273 parseForceLawsOption (line );
7374 parseHelpOption (line , cmdLineOptions );
74- //parseInFileOption(line);
7575 parseModeOption (line );
76+ parseInFileOption (line );
7677 parseOutFileOption (line );
7778 parseStepOption (line );
7879
@@ -159,17 +160,20 @@ private static void parseHelpOption(CommandLine line, Options cmdLineOptions) {
159160 }
160161 }
161162
163+ private static void parseModeOption (CommandLine line ) throws ParseException {
164+ _mode = line .getOptionValue ("m" );
165+ if (_mode == null )
166+ _mode = "gui" ;
167+ else if (!_mode .equalsIgnoreCase ("gui" ) && !_mode .equalsIgnoreCase ("batch" ))
168+ throw new ParseException ("Illegal mode argument" );
169+ }
170+
162171 private static void parseInFileOption (CommandLine line ) throws ParseException {
163172 _inFile = line .getOptionValue ("i" );
164- if (_inFile == null ) {
173+ if (_mode . equalsIgnoreCase ( "batch" ) && _inFile == null ) {
165174 throw new ParseException ("In batch mode an input file of bodies is required" );
166175 }
167176 }
168-
169- private static void parseModeOption (CommandLine line ) throws ParseException {
170- String mode = line .getOptionValue ("m" );
171-
172- }
173177
174178 private static void parseOutFileOption (CommandLine line ) throws ParseException {
175179 _outFile = line .getOptionValue ("o" );
@@ -258,21 +262,20 @@ private static void startBatchMode() throws Exception {
258262
259263 private static void startGUIMode () throws Exception {
260264 PhysicsSimulator ps = new PhysicsSimulator (_forceLawsFactory .createInstance (_forceLawsInfo ), _dtime );
261- //InputStream in = new FileInputStream(_inFile);
262- OutputStream out = _outFile == null ? System .out : new FileOutputStream (_outFile );
263265 Controller ctrl = new Controller (ps , _forceLawsFactory , _bodyFactory );
264266
265- //ctrl.loadData(in);
267+ if (_inFile != null )
268+ ctrl .loadData (new FileInputStream (_inFile ));
266269
267270 SwingUtilities .invokeAndWait (() -> new MainWindow (ctrl ));
268-
269- if (_outFile != null )
270- out .close ();
271271 }
272272
273273 private static void start (String [] args ) throws Exception {
274274 parseArgs (args );
275- startGUIMode ();
275+ if (_mode .equalsIgnoreCase ("gui" ))
276+ startGUIMode ();
277+ else
278+ startBatchMode ();
276279 }
277280
278281 public static void main (String [] args ) {
0 commit comments