diff --git a/nbproject/project.properties b/nbproject/project.properties index 1661fa6..10751bd 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,4 +1,4 @@ -#Sun, 16 Apr 2017 08:07:50 +0200 +#Sun, 16 Apr 2017 16:33:56 +0200 annotation.processing.enabled=true annotation.processing.enabled.in.editor=false annotation.processing.processors.list= diff --git a/src/gui/EditStrategies.java b/src/gui/EditStrategies.java index 8845f0c..9022840 100644 --- a/src/gui/EditStrategies.java +++ b/src/gui/EditStrategies.java @@ -284,7 +284,7 @@ public final class EditStrategies extends javax.swing.JDialog { Globals.LOGGER.info(String.format("Base %s\n", base)); - ac = Globals.tloader.getStrategyBase(base); + ac = Globals.tloader.getAutoTraderInterface(base); if (ac == null) { System.out.print("BASE IST NULL\n"); Globals.LOGGER.info(String.format("Can't load: %s\n", base)); @@ -401,7 +401,7 @@ System.out.printf("The big name: %s\n", ac.getClass().getCanonicalName()); if (sd.result==null) return; - AutoTraderInterface ac = Globals.tloader.getStrategyBase(sd.result.base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(sd.result.base); JSONObject cfg = ac.getConfig(); System.out.printf("Initial cfg %s\n", cfg.toString(2)); cfg.put("base", ac.getClass().getCanonicalName()); diff --git a/src/gui/Globals.java b/src/gui/Globals.java index 9d3b47c..7f46413 100644 --- a/src/gui/Globals.java +++ b/src/gui/Globals.java @@ -49,12 +49,11 @@ import sesim.AutoTraderLoader; * @author 7u83 <7u83@mail.ru> */ public class Globals { - + public static final String SESIM_FILEEXTENSION = "sesim"; public static final Double SESIM_FILEVERSION = 0.1; - + public static final String SESIM_APPTITLE = "SeSim - Stock Exchange Simulator"; - public interface CfgListener { @@ -75,9 +74,8 @@ public class Globals { public static JFrame frame; - // static final String STRATEGYPREFS = "Strategies"; - // static final String TRADERPREFS = "Traders"; - + // static final String STRATEGYPREFS = "Strategies"; + // static final String TRADERPREFS = "Traders"; static final String DEVELSTATUS = "devel_status"; public static final String GODMODE = "godmode"; @@ -86,19 +84,17 @@ public class Globals { /** * Defines keys for preferences */ - public static final class PrefKeys{ + public static final class PrefKeys { public static String WORKDIR = "workdir"; public static final String CURRENTFILE = "currentfile"; - + public static final String SESIMVERSION = "version"; public static final String STRATEGIES = "strategies"; public static final String TRADERS = "traders"; - - } - + static public Preferences prefs; public static class CfgStrings { @@ -140,20 +136,14 @@ public class Globals { static AutoTraderLoader tloader; static void initGlobals() { - String[] a = System.getProperty("java.class.path").split(System.getProperty("path.separator")); - ArrayList pathlist = new ArrayList<>(Arrays.asList(a)); - System.out.printf("Init tloader\n"); - - pathlist = new ArrayList<>(); - String dp = new java.io.File(SeSimApplication.class.getProtectionDomain() + ArrayList pathlist = new ArrayList<>(); + String default_path = new java.io.File(SeSimApplication.class.getProtectionDomain() .getCodeSource() .getLocation() .getPath()).toString(); - pathlist.add(dp); - LOGGER.info(String.format("Path %s", dp)); + pathlist.add(default_path); tloader = new AutoTraderLoader(pathlist); - } static public final Logger LOGGER = Logger.getLogger("com.cauwersin.sesim"); @@ -169,16 +159,15 @@ public class Globals { JSONObject cfgs = new JSONObject(cfglist); return cfgs; } - - static public final void putStrategies(JSONObject strategies){ + + static public final void putStrategies(JSONObject strategies) { Globals.prefs.put(Globals.PrefKeys.STRATEGIES, strategies.toString()); } - static public final void putTraders (JSONArray traders){ + static public final void putTraders(JSONArray traders) { Globals.prefs.put(Globals.PrefKeys.TRADERS, traders.toString()); } - static public JSONObject getStrategy(String name) { return getStrategies().getJSONObject(name); } @@ -213,9 +202,6 @@ public class Globals { prefs.put(PrefKeys.STRATEGIES, cfgs.toString()); } - - - public static void saveFile(File f) throws FileNotFoundException { JSONObject sobj = new JSONObject(); @@ -233,37 +219,36 @@ public class Globals { out.close(); } - - public static void loadString(String s) throws IOException{ + + public static void loadString(String s) throws IOException { JSONObject sobj = new JSONObject(s); - + Double version = sobj.getDouble(PrefKeys.SESIMVERSION); - if (version > SESIM_FILEVERSION){ + if (version > SESIM_FILEVERSION) { throw new IOException("File has wrong version."); } - + JSONArray traders = sobj.getJSONArray(PrefKeys.TRADERS); JSONObject strategies = sobj.getJSONObject(PrefKeys.STRATEGIES); - + putStrategies(strategies); putTraders(traders); - + } - - public static void clearAll(){ + public static void clearAll() { putStrategies(new JSONObject()); putTraders(new JSONArray()); } - + public static void loadFile(File f) throws IOException { - + f.getAbsoluteFile(); String s; s = new String(Files.readAllBytes(f.toPath())); - + loadString(s); - + } } diff --git a/src/gui/SeSimApplication.java b/src/gui/SeSimApplication.java index df58e92..d1b3a06 100644 --- a/src/gui/SeSimApplication.java +++ b/src/gui/SeSimApplication.java @@ -93,10 +93,10 @@ public class SeSimApplication extends javax.swing.JFrame { //this.setLocationRelativeTo(null); } - AutoTraderInterface createTraderNew(Exchange se, long id, String name, double money, double shares, JSONObject cfg) { + AutoTraderInterface createTrader(Exchange se, long id, String name, double money, double shares, JSONObject cfg) { String base = cfg.getString("base"); - AutoTraderInterface ac = Globals.tloader.getStrategyBase(base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(base); if (ac == null) { return null; } @@ -122,7 +122,7 @@ public class SeSimApplication extends javax.swing.JFrame { String strategy_name = t.getString("Strategy"); JSONObject strategy = Globals.getStrategy(strategy_name); String base = strategy.getString("base"); - AutoTraderInterface ac = Globals.tloader.getStrategyBase(base); + AutoTraderInterface ac = Globals.tloader.getAutoTraderInterface(base); System.out.printf("Load Strat: %s\n", strategy_name); System.out.printf("Base %s\n", base); @@ -140,7 +140,7 @@ public class SeSimApplication extends javax.swing.JFrame { for (int i1 = 0; i1 < count; i1++) { AutoTraderInterface trader; - trader = this.createTraderNew(Globals.se, id, t.getString("Name") + i1, money, shares, strategy); + trader = this.createTrader(Globals.se, id, t.getString("Name") + i1, money, shares, strategy); Globals.se.traders.add(trader); diff --git a/src/gui/StatisticsDialog.form b/src/gui/StatisticsDialog.form deleted file mode 100644 index bfea7a3..0000000 --- a/src/gui/StatisticsDialog.form +++ /dev/null @@ -1,60 +0,0 @@ - - -
diff --git a/src/gui/StatisticsDialog.java b/src/gui/StatisticsDialog.java deleted file mode 100644 index 9ad5a07..0000000 --- a/src/gui/StatisticsDialog.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2017, 7u83 <7u83@mail.ru> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -package gui; - -/** - * - * @author 7u83 <7u83@mail.ru> - */ -public class StatisticsDialog extends javax.swing.JDialog { - - /** - * Creates new form StatisticsDialog - */ - public StatisticsDialog(java.awt.Frame parent, boolean modal) { - super(parent, modal); - initComponents(); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - //