From 827e9991d50e5b347429a23fc10373fd8d38bdc9 Mon Sep 17 00:00:00 2001 From: Maik Merten Date: Sat, 26 Jul 2014 18:07:29 +0200 Subject: [PATCH] move main method into Main class in anticipation of changes that allow restarting the complete UI from within the Simulator menu system --- pom.xml | 2 +- src/main/java/com/loomcom/symon/Main.java | 93 +++++++++++++++++++ .../java/com/loomcom/symon/Simulator.java | 60 +----------- 3 files changed, 95 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/loomcom/symon/Main.java diff --git a/pom.xml b/pom.xml index 9724629..f07b74f 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ false - com.loomcom.symon.Simulator + com.loomcom.symon.Main diff --git a/src/main/java/com/loomcom/symon/Main.java b/src/main/java/com/loomcom/symon/Main.java new file mode 100644 index 0000000..78d7b59 --- /dev/null +++ b/src/main/java/com/loomcom/symon/Main.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2008-2013 Seth J. Morabito + * Maik Merten + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +package com.loomcom.symon; + +import com.loomcom.symon.machines.MulticompMachine; +import com.loomcom.symon.machines.SymonMachine; +import java.util.Locale; +import javax.swing.JOptionPane; +import javax.swing.SwingUtilities; +import javax.swing.UIManager; + +public class Main { + + /** + * Main entry point to the simulator. Creates a simulator and shows the main + * window. + * + * @param args + */ + public static void main(String args[]) { + + Class machineClass = null; + for(int i = 0; i < args.length; ++i) { + String arg = args[i].toLowerCase(Locale.ENGLISH); + if(arg.equals("-machine") && (i+1) < args.length) { + String machine = args[i+1].trim().toLowerCase(Locale.ENGLISH); + if(machine.equals("symon")) { + machineClass = SymonMachine.class; + } else if(machine.equals("multicomp")) { + machineClass = MulticompMachine.class; + } + } + } + + if(machineClass == null) { + Object[] possibilities = {"Symon", "Multicomp"}; + String s = (String)JOptionPane.showInputDialog( + null, + "Please choose the machine type to be emulated:", + "Machine selection", + JOptionPane.PLAIN_MESSAGE, + null, + possibilities, + "Symon"); + if(s.equals("Symon")) { + machineClass = SymonMachine.class; + } else { + machineClass = MulticompMachine.class; + } + } + + + final Class mClass = machineClass; + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + // Create the main UI window + Simulator simulator = new Simulator(mClass); + simulator.createAndShowUi(); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + + + } + +} diff --git a/src/main/java/com/loomcom/symon/Simulator.java b/src/main/java/com/loomcom/symon/Simulator.java index 05ee417..b064d5b 100644 --- a/src/main/java/com/loomcom/symon/Simulator.java +++ b/src/main/java/com/loomcom/symon/Simulator.java @@ -29,8 +29,6 @@ import com.loomcom.symon.exceptions.MemoryAccessException; import com.loomcom.symon.exceptions.MemoryRangeException; import com.loomcom.symon.exceptions.SymonException; import com.loomcom.symon.machines.Machine; -import com.loomcom.symon.machines.MulticompMachine; -import com.loomcom.symon.machines.SymonMachine; import com.loomcom.symon.ui.*; import com.loomcom.symon.ui.Console; @@ -39,8 +37,6 @@ import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.*; import java.io.*; -import java.util.ArrayList; -import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; @@ -232,6 +228,7 @@ public class Simulator { mainWindow.setVisible(true); console.requestFocus(); + handleReset(); } private void handleStart() { @@ -378,61 +375,6 @@ public class Simulator { }); } - /** - * Main entry point to the simulator. Creates a simulator and shows the main - * window. - * - * @param args - */ - public static void main(String args[]) { - - Class machineClass = null; - for(int i = 0; i < args.length; ++i) { - String arg = args[i].toLowerCase(Locale.ENGLISH); - if(arg.equals("-machine") && (i+1) < args.length) { - String machine = args[i+1].trim().toLowerCase(Locale.ENGLISH); - if(machine.equals("symon")) { - machineClass = SymonMachine.class; - } else if(machine.equals("multicomp")) { - machineClass = MulticompMachine.class; - } - } - } - - if(machineClass == null) { - Object[] possibilities = {"Symon", "Multicomp"}; - String s = (String)JOptionPane.showInputDialog( - null, - "Please choose the machine type to be emulated:", - "Machine selection", - JOptionPane.PLAIN_MESSAGE, - null, - possibilities, - "Symon"); - if(s.equals("Symon")) { - machineClass = SymonMachine.class; - } else { - machineClass = MulticompMachine.class; - } - } - - - final Class mClass = machineClass; - SwingUtilities.invokeLater(new Runnable() { - public void run() { - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - // Create the main UI window - Simulator simulator = new Simulator(mClass); - simulator.createAndShowUi(); - // Reset the simulator. - simulator.handleReset(); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } /** * The main run thread.