diff --git a/src/main/java/chart/Chart.java b/src/main/java/chart/Chart.java index 2e18980..5f1176e 100644 --- a/src/main/java/chart/Chart.java +++ b/src/main/java/chart/Chart.java @@ -10,7 +10,7 @@ import sesim.OHLCData; import java.awt.*; import sesim.Exchange.*; import sesim.Quote; -import gui.MainWin; +import gui.Globals; import java.awt.geom.Rectangle2D; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -29,11 +29,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { */ public Chart() { initComponents(); - if (MainWin.se == null) { + if (Globals.se == null) { return; } - MainWin.se.addQuoteReceiver(this); + Globals.se.addQuoteReceiver(this); //Graphics g = this.getGraphics(); //g.drawString("Hello world", 0, 0); diff --git a/src/main/java/gui/AskBook.java b/src/main/java/gui/AskBook.java index 060360b..6533601 100644 --- a/src/main/java/gui/AskBook.java +++ b/src/main/java/gui/AskBook.java @@ -36,7 +36,7 @@ public class AskBook extends OrderBook { @Override ArrayList getOrderBook() { - return MainWin.se.getOrderBook(OrderType.ASK,40); + return Globals.se.getOrderBook(OrderType.ASK,40); } @Override @@ -45,10 +45,10 @@ public class AskBook extends OrderBook { } public AskBook(){ - if (MainWin.se == null) { + if (Globals.se == null) { return; } - MainWin.se.addBookReceiver(OrderType.ASK, this); + Globals.se.addBookReceiver(OrderType.ASK, this); } diff --git a/src/main/java/gui/BidBook.java b/src/main/java/gui/BidBook.java index ffddbe2..fde7e35 100644 --- a/src/main/java/gui/BidBook.java +++ b/src/main/java/gui/BidBook.java @@ -35,14 +35,14 @@ import sesim.Exchange.*; public class BidBook extends OrderBook { @Override - ArrayList getOrderBook() { - return MainWin.se.getOrderBook(OrderType.BID, 40); + ArrayList getOrderBook() { + return Globals.se.getOrderBook(OrderType.BID, 40); } public BidBook() { - if (MainWin.se == null) { + if (Globals.se == null) { return; } - MainWin.se.addBookReceiver(OrderType.BID, this); + Globals.se.addBookReceiver(OrderType.BID, this); } } diff --git a/src/main/java/gui/Chart.java b/src/main/java/gui/Chart.java index 7d195e4..85736bc 100644 --- a/src/main/java/gui/Chart.java +++ b/src/main/java/gui/Chart.java @@ -188,7 +188,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { long start = (ct - 60)/step*step; - SortedSet h = MainWin.se.getQuoteHistory(start); + SortedSet h = Globals.se.getQuoteHistory(start); for (long i = start * 1000; i < ct * 1000; i += step * 1000) { OHLCDataItem d = getOhlcData(i, i + step * 1000, h); @@ -293,7 +293,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver { ); long start = (ct - 60)/5*5; - SortedSet h = MainWin.se.getQuoteHistory(start); + SortedSet h = Globals.se.getQuoteHistory(start); System.out.print("Number of quotes" + start + ":" + ct + "\n"); System.out.print("Number of quotes:" + h.size() + "\n"); diff --git a/src/main/java/gui/Globals.java b/src/main/java/gui/Globals.java new file mode 100644 index 0000000..f627542 --- /dev/null +++ b/src/main/java/gui/Globals.java @@ -0,0 +1,36 @@ +/* + * 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 Globals { + + static public sesim.Exchange se; + +} diff --git a/src/main/java/gui/MainWin.java b/src/main/java/gui/MainWin.java index 95452d4..f574602 100644 --- a/src/main/java/gui/MainWin.java +++ b/src/main/java/gui/MainWin.java @@ -39,7 +39,7 @@ import traders.*; public class MainWin extends javax.swing.JFrame { static MainWin instance; - static public sesim.Exchange se; + //static public sesim.Exchange se; //static sesim.Account_old myAccount; @@ -52,8 +52,8 @@ public class MainWin extends javax.swing.JFrame { this.setLocationRelativeTo(this); - double aid1 = se.createAccount(100, 100); - double aid2 = se.createAccount(1000, 100); + double aid1 = Globals.se.createAccount(100, 100); + double aid2 = Globals.se.createAccount(1000, 100); /* AccountData a1 = se.getAccountData(aid1); AccountData a2 = se.getAccountData(aid2); @@ -209,7 +209,7 @@ public class MainWin extends javax.swing.JFrame { }//GEN-LAST:event_jButton1ActionPerformed private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed - se.timer.start(); + Globals.se.timer.start(); }//GEN-LAST:event_FileRunActionPerformed private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed @@ -232,7 +232,7 @@ public class MainWin extends javax.swing.JFrame { */ public static void main(String args[]) { - se = new Exchange(); + Globals.se = new Exchange(); //se.timer.start(); @@ -246,8 +246,8 @@ public class MainWin extends javax.swing.JFrame { // rcfg1.sell_limit[0]=-1; // rcfg1.sell_limit[1]=1; - AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 1000000); - se.traders.add(rt1); + AutoTrader rt1 = rcfg1.createTrader(Globals.se, 1000000, 1000000); + Globals.se.traders.add(rt1); rt1.setName("Alice"); rt1.start(); @@ -260,9 +260,9 @@ public class MainWin extends javax.swing.JFrame { RandomTraderConfig cfg= new RandomTraderConfig(); for (int i=0; i<30; i++){ - AutoTrader randt = cfg.createTrader(se, 100000, 100000); + AutoTrader randt = cfg.createTrader(Globals.se, 100000, 100000); - se.traders.add(randt); + Globals.se.traders.add(randt); randt.setName("Bob"); randt.start(); } diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form index 86552c2..43626c6 100644 --- a/src/main/java/gui/NewMDIApplication.form +++ b/src/main/java/gui/NewMDIApplication.form @@ -118,39 +118,13 @@ - - - - - - - + - - - - - - - - - + - - - - - - - - - - - - diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java index d7de99c..60a9bff 100644 --- a/src/main/java/gui/NewMDIApplication.java +++ b/src/main/java/gui/NewMDIApplication.java @@ -47,9 +47,6 @@ public class NewMDIApplication extends javax.swing.JFrame { // //GEN-BEGIN:initComponents private void initComponents() { - bidBook1 = new gui.BidBook(); - desktopPane = new javax.swing.JDesktopPane(); - orderBookPanel1 = new gui.OrderBookPanel(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); openMenuItem = new javax.swing.JMenuItem(); @@ -134,22 +131,11 @@ public class NewMDIApplication extends javax.swing.JFrame { getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() - .addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 226, Short.MAX_VALUE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(bidBook1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) - .addContainerGap()) - .addComponent(desktopPane) + .addGap(0, 913, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(desktopPane, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE) - .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 310, javax.swing.GroupLayout.PREFERRED_SIZE) - .addComponent(bidBook1, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)) - .addContainerGap()) + .addGap(0, 554, Short.MAX_VALUE) ); pack(); @@ -196,19 +182,16 @@ public class NewMDIApplication extends javax.swing.JFrame { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem aboutMenuItem; - private gui.BidBook bidBook1; private javax.swing.JMenuItem contentMenuItem; private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem cutMenuItem; private javax.swing.JMenuItem deleteMenuItem; - private javax.swing.JDesktopPane desktopPane; private javax.swing.JMenu editMenu; private javax.swing.JMenuItem exitMenuItem; private javax.swing.JMenu fileMenu; private javax.swing.JMenu helpMenu; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem openMenuItem; - private gui.OrderBookPanel orderBookPanel1; private javax.swing.JMenuItem pasteMenuItem; private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveMenuItem; diff --git a/src/main/java/gui/OrderBook.java b/src/main/java/gui/OrderBook.java index 2bb97b5..e1939ad 100644 --- a/src/main/java/gui/OrderBook.java +++ b/src/main/java/gui/OrderBook.java @@ -180,7 +180,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B this.setBorder(BorderFactory.createEmptyBorder()); this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0)); - if (MainWin.se == null) { + if (Globals.se == null) { return; } diff --git a/src/main/java/gui/OrderBookPanel.java b/src/main/java/gui/OrderBookPanel.java index da9fe9f..db5b3b0 100644 --- a/src/main/java/gui/OrderBookPanel.java +++ b/src/main/java/gui/OrderBookPanel.java @@ -42,7 +42,7 @@ public class OrderBookPanel extends javax.swing.JPanel { sesim.Exchange se; public OrderBookPanel() { - this.se = MainWin.se; + this.se = Globals.se; initComponents(); diff --git a/src/main/java/gui/QuotePanel.java b/src/main/java/gui/QuotePanel.java index 91c8aeb..372d5ef 100644 --- a/src/main/java/gui/QuotePanel.java +++ b/src/main/java/gui/QuotePanel.java @@ -41,9 +41,9 @@ public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.Quo */ public QuotePanel() { initComponents(); - if (MainWin.se==null) + if (Globals.se==null) return; - MainWin.se.addQuoteReceiver(this); + Globals.se.addQuoteReceiver(this); } /** diff --git a/src/main/java/gui/TraderListPanel.java b/src/main/java/gui/TraderListPanel.java index 8063485..5718f9a 100644 --- a/src/main/java/gui/TraderListPanel.java +++ b/src/main/java/gui/TraderListPanel.java @@ -57,7 +57,7 @@ public class TraderListPanel extends javax.swing.JPanel this.setBorder(BorderFactory.createEmptyBorder()); // this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0)); - if (MainWin.se == null) { + if (Globals.se == null) { return; } @@ -70,8 +70,8 @@ public class TraderListPanel extends javax.swing.JPanel // h.setBackground(Color.BLUE); // h.setForeground(Color.green); - if (MainWin.se != null) { - this.se = MainWin.se; + if (Globals.se != null) { + this.se = Globals.se; this.list = this.getTraderList(); se.timer.startTimerEvent(this, 1000); }