Introduced Globals object

This commit is contained in:
7u83 2017-01-22 10:04:50 +01:00
parent d9c7dac38f
commit ea4795967a
12 changed files with 68 additions and 75 deletions

View File

@ -10,7 +10,7 @@ import sesim.OHLCData;
import java.awt.*; import java.awt.*;
import sesim.Exchange.*; import sesim.Exchange.*;
import sesim.Quote; import sesim.Quote;
import gui.MainWin; import gui.Globals;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -29,11 +29,11 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
*/ */
public Chart() { public Chart() {
initComponents(); initComponents();
if (MainWin.se == null) { if (Globals.se == null) {
return; return;
} }
MainWin.se.addQuoteReceiver(this); Globals.se.addQuoteReceiver(this);
//Graphics g = this.getGraphics(); //Graphics g = this.getGraphics();
//g.drawString("Hello world", 0, 0); //g.drawString("Hello world", 0, 0);

View File

@ -36,7 +36,7 @@ public class AskBook extends OrderBook {
@Override @Override
ArrayList <Order> getOrderBook() { ArrayList <Order> getOrderBook() {
return MainWin.se.getOrderBook(OrderType.ASK,40); return Globals.se.getOrderBook(OrderType.ASK,40);
} }
@Override @Override
@ -45,10 +45,10 @@ public class AskBook extends OrderBook {
} }
public AskBook(){ public AskBook(){
if (MainWin.se == null) { if (Globals.se == null) {
return; return;
} }
MainWin.se.addBookReceiver(OrderType.ASK, this); Globals.se.addBookReceiver(OrderType.ASK, this);
} }

View File

@ -36,13 +36,13 @@ public class BidBook extends OrderBook {
@Override @Override
ArrayList<Order> getOrderBook() { ArrayList<Order> getOrderBook() {
return MainWin.se.getOrderBook(OrderType.BID, 40); return Globals.se.getOrderBook(OrderType.BID, 40);
} }
public BidBook() { public BidBook() {
if (MainWin.se == null) { if (Globals.se == null) {
return; return;
} }
MainWin.se.addBookReceiver(OrderType.BID, this); Globals.se.addBookReceiver(OrderType.BID, this);
} }
} }

View File

@ -188,7 +188,7 @@ public class Chart extends javax.swing.JPanel implements QuoteReceiver {
long start = (ct - 60)/step*step; long start = (ct - 60)/step*step;
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start); SortedSet<Quote> h = Globals.se.getQuoteHistory(start);
for (long i = start * 1000; i < ct * 1000; i += step * 1000) { for (long i = start * 1000; i < ct * 1000; i += step * 1000) {
OHLCDataItem d = getOhlcData(i, i + step * 1000, h); 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; long start = (ct - 60)/5*5;
SortedSet<Quote> h = MainWin.se.getQuoteHistory(start); SortedSet<Quote> h = Globals.se.getQuoteHistory(start);
System.out.print("Number of quotes" + start + ":" + ct + "\n"); System.out.print("Number of quotes" + start + ":" + ct + "\n");
System.out.print("Number of quotes:" + h.size() + "\n"); System.out.print("Number of quotes:" + h.size() + "\n");

View File

@ -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;
}

View File

@ -39,7 +39,7 @@ import traders.*;
public class MainWin extends javax.swing.JFrame { public class MainWin extends javax.swing.JFrame {
static MainWin instance; static MainWin instance;
static public sesim.Exchange se; //static public sesim.Exchange se;
//static sesim.Account_old myAccount; //static sesim.Account_old myAccount;
@ -52,8 +52,8 @@ public class MainWin extends javax.swing.JFrame {
this.setLocationRelativeTo(this); this.setLocationRelativeTo(this);
double aid1 = se.createAccount(100, 100); double aid1 = Globals.se.createAccount(100, 100);
double aid2 = se.createAccount(1000, 100); double aid2 = Globals.se.createAccount(1000, 100);
/* AccountData a1 = se.getAccountData(aid1); /* AccountData a1 = se.getAccountData(aid1);
AccountData a2 = se.getAccountData(aid2); AccountData a2 = se.getAccountData(aid2);
@ -209,7 +209,7 @@ public class MainWin extends javax.swing.JFrame {
}//GEN-LAST:event_jButton1ActionPerformed }//GEN-LAST:event_jButton1ActionPerformed
private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed private void FileRunActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FileRunActionPerformed
se.timer.start(); Globals.se.timer.start();
}//GEN-LAST:event_FileRunActionPerformed }//GEN-LAST:event_FileRunActionPerformed
private void helpAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_helpAboutActionPerformed 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[]) { public static void main(String args[]) {
se = new Exchange(); Globals.se = new Exchange();
//se.timer.start(); //se.timer.start();
@ -246,8 +246,8 @@ public class MainWin extends javax.swing.JFrame {
// rcfg1.sell_limit[0]=-1; // rcfg1.sell_limit[0]=-1;
// rcfg1.sell_limit[1]=1; // rcfg1.sell_limit[1]=1;
AutoTrader rt1 = rcfg1.createTrader(se, 1000000, 1000000); AutoTrader rt1 = rcfg1.createTrader(Globals.se, 1000000, 1000000);
se.traders.add(rt1); Globals.se.traders.add(rt1);
rt1.setName("Alice"); rt1.setName("Alice");
rt1.start(); rt1.start();
@ -260,9 +260,9 @@ public class MainWin extends javax.swing.JFrame {
RandomTraderConfig cfg= new RandomTraderConfig(); RandomTraderConfig cfg= new RandomTraderConfig();
for (int i=0; i<30; i++){ 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.setName("Bob");
randt.start(); randt.start();
} }

View File

@ -118,39 +118,13 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <EmptySpace min="0" pref="913" max="32767" attributes="0"/>
<Component id="orderBookPanel1" pref="226" max="32767" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="bidBook1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="desktopPane" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <EmptySpace min="0" pref="554" max="32767" attributes="0"/>
<Component id="desktopPane" min="-2" pref="108" max="-2" attributes="0"/>
<EmptySpace pref="48" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="orderBookPanel1" min="-2" pref="310" max="-2" attributes="0"/>
<Component id="bidBook1" min="-2" pref="218" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents>
<Component class="gui.BidBook" name="bidBook1">
</Component>
<Container class="javax.swing.JDesktopPane" name="desktopPane">
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout">
<Property name="useNullLayout" type="boolean" value="true"/>
</Layout>
</Container>
<Component class="gui.OrderBookPanel" name="orderBookPanel1">
</Component>
</SubComponents>
</Form> </Form>

View File

@ -47,9 +47,6 @@ public class NewMDIApplication extends javax.swing.JFrame {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
bidBook1 = new gui.BidBook();
desktopPane = new javax.swing.JDesktopPane();
orderBookPanel1 = new gui.OrderBookPanel();
menuBar = new javax.swing.JMenuBar(); menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu(); fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem(); openMenuItem = new javax.swing.JMenuItem();
@ -134,22 +131,11 @@ public class NewMDIApplication extends javax.swing.JFrame {
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGap(0, 913, Short.MAX_VALUE)
.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)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGap(0, 554, Short.MAX_VALUE)
.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())
); );
pack(); pack();
@ -196,19 +182,16 @@ public class NewMDIApplication extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem aboutMenuItem; private javax.swing.JMenuItem aboutMenuItem;
private gui.BidBook bidBook1;
private javax.swing.JMenuItem contentMenuItem; private javax.swing.JMenuItem contentMenuItem;
private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem copyMenuItem;
private javax.swing.JMenuItem cutMenuItem; private javax.swing.JMenuItem cutMenuItem;
private javax.swing.JMenuItem deleteMenuItem; private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JDesktopPane desktopPane;
private javax.swing.JMenu editMenu; private javax.swing.JMenu editMenu;
private javax.swing.JMenuItem exitMenuItem; private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu; private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu; private javax.swing.JMenu helpMenu;
private javax.swing.JMenuBar menuBar; private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem; private javax.swing.JMenuItem openMenuItem;
private gui.OrderBookPanel orderBookPanel1;
private javax.swing.JMenuItem pasteMenuItem; private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem; private javax.swing.JMenuItem saveMenuItem;

View File

@ -180,7 +180,7 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
this.setBorder(BorderFactory.createEmptyBorder()); this.setBorder(BorderFactory.createEmptyBorder());
this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0)); this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
if (MainWin.se == null) { if (Globals.se == null) {
return; return;
} }

View File

@ -42,7 +42,7 @@ public class OrderBookPanel extends javax.swing.JPanel {
sesim.Exchange se; sesim.Exchange se;
public OrderBookPanel() { public OrderBookPanel() {
this.se = MainWin.se; this.se = Globals.se;
initComponents(); initComponents();

View File

@ -41,9 +41,9 @@ public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.Quo
*/ */
public QuotePanel() { public QuotePanel() {
initComponents(); initComponents();
if (MainWin.se==null) if (Globals.se==null)
return; return;
MainWin.se.addQuoteReceiver(this); Globals.se.addQuoteReceiver(this);
} }
/** /**

View File

@ -57,7 +57,7 @@ public class TraderListPanel extends javax.swing.JPanel
this.setBorder(BorderFactory.createEmptyBorder()); this.setBorder(BorderFactory.createEmptyBorder());
// this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0)); // this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
if (MainWin.se == null) { if (Globals.se == null) {
return; return;
} }
@ -70,8 +70,8 @@ public class TraderListPanel extends javax.swing.JPanel
// h.setBackground(Color.BLUE); // h.setBackground(Color.BLUE);
// h.setForeground(Color.green); // h.setForeground(Color.green);
if (MainWin.se != null) { if (Globals.se != null) {
this.se = MainWin.se; this.se = Globals.se;
this.list = this.getTraderList(); this.list = this.getTraderList();
se.timer.startTimerEvent(this, 1000); se.timer.startTimerEvent(this, 1000);
} }