OpenSeSim/src/main/java/gui/NewMDIApplication.java

753 lines
30 KiB
Java
Raw Normal View History

2017-01-15 18:15:22 +01:00
/*
* 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;
2017-01-22 21:41:45 +01:00
import java.awt.Dialog;
2017-01-31 08:04:11 +01:00
import java.awt.Frame;
import java.io.File;
2017-02-02 18:39:55 +01:00
import java.lang.reflect.Modifier;
2017-01-25 00:24:53 +01:00
import java.util.ArrayList;
2017-01-28 15:34:24 +01:00
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
2017-01-25 02:52:49 +01:00
import java.util.prefs.Preferences;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
2017-01-25 02:52:49 +01:00
import javax.swing.UIManager;
2017-01-31 08:04:11 +01:00
import javax.swing.filechooser.FileNameExtensionFilter;
2017-01-30 22:18:10 +01:00
import org.json.JSONArray;
import org.json.JSONObject;
2017-02-13 00:07:50 +01:00
2017-01-22 21:41:45 +01:00
import sesim.AutoTraderConfig;
2017-02-11 08:36:45 +01:00
import sesim.AutoTraderInterface;
2017-01-22 21:41:45 +01:00
import sesim.Exchange;
import traders.RandomTraderConfig;
2017-01-15 18:15:22 +01:00
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class NewMDIApplication extends javax.swing.JFrame {
/**
* Creates new form NewMDIApplication
*/
public NewMDIApplication() {
initComponents();
2017-02-07 01:53:43 +01:00
Globals.frame=this;
2017-01-22 21:41:45 +01:00
this.setLocationRelativeTo(this);
this.setTitle("SeSim - Stock Exchange Simmulator");
}
2017-02-11 08:36:45 +01:00
AutoTraderInterface createTraderNew(Exchange se,long id,String name, double money, double shares, JSONObject cfg) {
2017-02-07 01:53:43 +01:00
System.out.printf("!!!! creating new\n");
String base = cfg.getString("base");
2017-02-11 08:36:45 +01:00
AutoTraderInterface ac = Globals.tloader.getStrategyBase(base);
2017-02-13 18:26:32 +01:00
if (ac==null)
return null;
2017-02-11 08:36:45 +01:00
ac.putConfig(cfg);
2017-02-07 01:53:43 +01:00
ac.init(se, id, name, money, shares, cfg);
2017-02-11 13:12:02 +01:00
2017-02-07 01:53:43 +01:00
return ac;
}
2017-01-22 21:41:45 +01:00
public void startTraders() {
2017-02-13 00:07:50 +01:00
// Globals.se.setMoneyDecimals(8);
// Globals.se.setSharesDecimals(0);
2017-02-11 13:12:02 +01:00
2017-01-30 22:18:10 +01:00
JSONArray tlist = Globals.getTraders();
2017-02-07 01:53:43 +01:00
Double moneyTotal = 0.0;
Double sharesTotal = 0.0;
long id = 0;
for (int i = 0; i < tlist.length(); i++) {
JSONObject t = tlist.getJSONObject(i);
2017-01-30 22:18:10 +01:00
String strategy_name = t.getString("Strategy");
JSONObject strategy = Globals.getStrategy(strategy_name);
String base = strategy.getString("base");
2017-02-11 08:36:45 +01:00
AutoTraderInterface ac = Globals.tloader.getStrategyBase(base);
2017-02-07 01:53:43 +01:00
System.out.printf("Load Strat: %s\n", strategy_name);
2017-01-30 22:18:10 +01:00
System.out.printf("Base %s\n", base);
2017-02-07 01:53:43 +01:00
Integer count = t.getInt("Count");
2017-01-30 22:18:10 +01:00
Double shares = t.getDouble("Shares");
Double money = t.getDouble("Money");
2017-02-07 01:53:43 +01:00
2017-02-06 08:14:05 +01:00
Boolean enabled = t.getBoolean("Enabled");
2017-02-07 01:53:43 +01:00
if (!enabled) {
2017-02-06 08:14:05 +01:00
continue;
2017-02-07 01:53:43 +01:00
}
System.out.printf("Count: %d Shares: %f Money %f\n", count, shares, money);
for (int i1 = 0; i1 < count; i1++) {
2017-02-11 08:36:45 +01:00
AutoTraderInterface trader;
// AutoTrader trader = ac.createTrader(Globals.se, strategy, id++, t.getString("Name") + i1, money, shares);
// if (trader == null) {
2017-02-07 01:53:43 +01:00
System.out.printf("shoudl create new\n");
trader = this.createTraderNew(Globals.se, id, t.getString("Name") + i1, money, shares, strategy);
2017-02-11 08:36:45 +01:00
// }
2017-02-07 01:53:43 +01:00
2017-01-30 22:18:10 +01:00
Globals.se.traders.add(trader);
// trader.setName(t.getString("Name")+i1);
2017-02-07 01:53:43 +01:00
moneyTotal += money;
sharesTotal += shares;
// trader.start();
2017-01-30 22:18:10 +01:00
}
2017-02-07 01:53:43 +01:00
2017-02-02 18:39:55 +01:00
}
2017-02-07 01:53:43 +01:00
Globals.se.fairValue = moneyTotal / sharesTotal;
2017-02-11 08:36:45 +01:00
Globals.se.fairValue = 1.0;
2017-02-07 01:53:43 +01:00
for (int i = 0; i < Globals.se.traders.size(); i++) {
2017-02-02 18:39:55 +01:00
Globals.se.traders.get(i).start();
2017-01-30 22:18:10 +01:00
}
2017-02-07 01:53:43 +01:00
2017-01-15 18:15:22 +01:00
}
/**
* 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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
2017-01-28 15:34:24 +01:00
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
2017-02-18 08:17:07 +01:00
jSplitPane1 = new javax.swing.JSplitPane();
jSplitPane2 = new javax.swing.JSplitPane();
orderBookNew1 = new gui.orderbook.OrderBook();
traderListPanel1 = new gui.TraderListPanel();
2017-02-03 01:56:41 +01:00
jPanel2 = new javax.swing.JPanel();
2017-02-06 08:14:05 +01:00
stopButton = new javax.swing.JButton();
runButton = new javax.swing.JButton();
2017-02-03 01:56:41 +01:00
jButton2 = new javax.swing.JButton();
2017-02-05 10:01:13 +01:00
accelSpinner = new javax.swing.JSpinner();
2017-02-06 08:14:05 +01:00
clock = new gui.Clock();
jComboBox1 = new javax.swing.JComboBox<>();
2017-02-18 08:17:07 +01:00
jSplitPane3 = new javax.swing.JSplitPane();
jSplitPane4 = new javax.swing.JSplitPane();
orderBooksHorizontal1 = new gui.orderbook.OrderBooksHorizontal();
2017-02-13 18:26:32 +01:00
jChartScrollPane = new javax.swing.JScrollPane();
chart = new chart.Chart();
quoteVertical1 = new gui.orderbook.QuoteVertical();
2017-01-15 18:15:22 +01:00
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
2017-02-04 16:29:45 +01:00
jMenuItem1 = new javax.swing.JMenuItem();
2017-01-15 18:15:22 +01:00
openMenuItem = new javax.swing.JMenuItem();
saveMenuItem = new javax.swing.JMenuItem();
saveAsMenuItem = new javax.swing.JMenuItem();
exitMenuItem = new javax.swing.JMenuItem();
editMenu = new javax.swing.JMenu();
2017-01-31 08:04:11 +01:00
editExchangeMenuItem = new javax.swing.JMenuItem();
2017-01-28 15:34:24 +01:00
jSeparator1 = new javax.swing.JPopupMenu.Separator();
2017-01-15 18:15:22 +01:00
pasteMenuItem = new javax.swing.JMenuItem();
deleteMenuItem = new javax.swing.JMenuItem();
2017-01-28 15:34:24 +01:00
jSeparator2 = new javax.swing.JPopupMenu.Separator();
2017-01-22 21:41:45 +01:00
editPreferences = new javax.swing.JMenuItem();
2017-02-04 18:57:18 +01:00
simMenu = new javax.swing.JMenu();
simMenuStart = new javax.swing.JMenuItem();
simMenuPause = new javax.swing.JMenuItem();
2017-02-05 10:31:52 +01:00
simMenuStop = new javax.swing.JMenuItem();
2017-02-02 18:39:55 +01:00
viewMenu = new javax.swing.JMenu();
2017-01-22 21:41:45 +01:00
jMenuItem2 = new javax.swing.JMenuItem();
2017-02-02 18:39:55 +01:00
viewClock = new javax.swing.JMenuItem();
2017-02-13 18:26:32 +01:00
jMenuItem3 = new javax.swing.JMenuItem();
jCheckBoxMenuItem1 = new javax.swing.JCheckBoxMenuItem();
2017-01-15 18:15:22 +01:00
helpMenu = new javax.swing.JMenu();
contentMenuItem = new javax.swing.JMenuItem();
aboutMenuItem = new javax.swing.JMenuItem();
2017-01-28 15:34:24 +01:00
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jTextArea1.setText("Hakke");
jScrollPane2.setViewportView(jTextArea1);
2017-02-18 08:17:07 +01:00
jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jSplitPane2.setLeftComponent(orderBookNew1);
jSplitPane1.setTopComponent(jSplitPane2);
jSplitPane1.setRightComponent(traderListPanel1);
2017-01-15 18:15:22 +01:00
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
2017-01-22 21:41:45 +01:00
setMinimumSize(new java.awt.Dimension(640, 480));
2017-02-03 01:56:41 +01:00
2017-02-06 08:14:05 +01:00
stopButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Stop24.gif"))); // NOI18N
stopButton.setText("Stop");
stopButton.setFocusable(false);
stopButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
stopButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
stopButton.addActionListener(new java.awt.event.ActionListener() {
2017-02-04 16:29:45 +01:00
public void actionPerformed(java.awt.event.ActionEvent evt) {
2017-02-06 08:14:05 +01:00
stopButtonActionPerformed(evt);
2017-02-04 16:29:45 +01:00
}
});
2017-01-22 21:41:45 +01:00
2017-02-06 08:14:05 +01:00
runButton.setFont(runButton.getFont());
runButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/run.gif"))); // NOI18N
runButton.setText("Run sim!");
runButton.setToolTipText("Run the simmulation");
runButton.setFocusable(false);
runButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
runButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
runButton.addActionListener(new java.awt.event.ActionListener() {
2017-01-22 21:41:45 +01:00
public void actionPerformed(java.awt.event.ActionEvent evt) {
2017-02-06 08:14:05 +01:00
runButtonActionPerformed(evt);
2017-01-22 21:41:45 +01:00
}
});
jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pause.gif"))); // NOI18N
jButton2.setText("Pause");
jButton2.setFocusable(false);
jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
2017-02-05 10:01:13 +01:00
accelSpinner.setModel(new javax.swing.SpinnerNumberModel(1.0d, 0.0d, null, 100.0d));
accelSpinner.addChangeListener(new javax.swing.event.ChangeListener() {
2017-02-03 01:56:41 +01:00
public void stateChanged(javax.swing.event.ChangeEvent evt) {
2017-02-05 10:01:13 +01:00
accelSpinnerStateChanged(evt);
2017-02-03 01:56:41 +01:00
}
});
2017-02-06 08:14:05 +01:00
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1x", "2x", "4x", "10x", "100x", "1000x", "max." }));
2017-02-03 01:56:41 +01:00
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
2017-02-06 08:14:05 +01:00
.addComponent(runButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
2017-02-03 01:56:41 +01:00
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
2017-02-06 08:14:05 +01:00
.addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
2017-02-18 17:44:25 +01:00
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 545, Short.MAX_VALUE)
2017-02-06 08:14:05 +01:00
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(clock, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
2017-02-03 01:56:41 +01:00
.addContainerGap())
2017-01-22 21:41:45 +01:00
);
2017-02-03 01:56:41 +01:00
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
2017-02-06 08:14:05 +01:00
.addComponent(runButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
2017-02-03 01:56:41 +01:00
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
2017-02-06 08:14:05 +01:00
.addComponent(stopButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
2017-02-03 01:56:41 +01:00
.addGroup(jPanel2Layout.createSequentialGroup()
2017-02-06 08:14:05 +01:00
.addGap(3, 3, 3)
.addComponent(clock, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())))
2017-01-22 21:41:45 +01:00
);
2017-02-13 18:26:32 +01:00
getContentPane().add(jPanel2, java.awt.BorderLayout.PAGE_START);
2017-02-18 08:17:07 +01:00
jSplitPane4.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
jSplitPane4.setBottomComponent(orderBooksHorizontal1);
2017-02-13 18:26:32 +01:00
2017-02-18 17:44:25 +01:00
chart.setPreferredSize(new java.awt.Dimension(892, 410));
2017-02-13 18:26:32 +01:00
javax.swing.GroupLayout chartLayout = new javax.swing.GroupLayout(chart);
chart.setLayout(chartLayout);
chartLayout.setHorizontalGroup(
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
2017-02-18 17:44:25 +01:00
.addGap(0, 892, Short.MAX_VALUE)
2017-02-13 18:26:32 +01:00
);
chartLayout.setVerticalGroup(
chartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
2017-02-18 17:44:25 +01:00
.addGap(0, 410, Short.MAX_VALUE)
2017-02-13 18:26:32 +01:00
);
jChartScrollPane.setViewportView(chart);
2017-02-18 08:17:07 +01:00
jSplitPane4.setLeftComponent(jChartScrollPane);
2017-02-13 18:26:32 +01:00
2017-02-18 08:17:07 +01:00
jSplitPane3.setRightComponent(jSplitPane4);
jSplitPane3.setLeftComponent(quoteVertical1);
2017-02-13 18:26:32 +01:00
2017-02-18 08:17:07 +01:00
getContentPane().add(jSplitPane3, java.awt.BorderLayout.CENTER);
2017-02-13 18:26:32 +01:00
2017-01-15 18:15:22 +01:00
fileMenu.setMnemonic('f');
fileMenu.setText("File");
2017-02-04 16:29:45 +01:00
jMenuItem1.setMnemonic('n');
jMenuItem1.setText("New");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
fileMenu.add(jMenuItem1);
2017-01-15 18:15:22 +01:00
openMenuItem.setMnemonic('o');
openMenuItem.setText("Open");
2017-01-31 08:04:11 +01:00
openMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
openMenuItemActionPerformed(evt);
}
});
2017-01-15 18:15:22 +01:00
fileMenu.add(openMenuItem);
saveMenuItem.setMnemonic('s');
saveMenuItem.setText("Save");
fileMenu.add(saveMenuItem);
saveAsMenuItem.setMnemonic('a');
saveAsMenuItem.setText("Save As ...");
saveAsMenuItem.setDisplayedMnemonicIndex(5);
2017-01-31 08:04:11 +01:00
saveAsMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
saveAsMenuItemActionPerformed(evt);
}
});
2017-01-15 18:15:22 +01:00
fileMenu.add(saveAsMenuItem);
exitMenuItem.setMnemonic('x');
exitMenuItem.setText("Exit");
exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitMenuItemActionPerformed(evt);
}
});
fileMenu.add(exitMenuItem);
menuBar.add(fileMenu);
editMenu.setMnemonic('e');
editMenu.setText("Edit");
2017-01-31 08:04:11 +01:00
editExchangeMenuItem.setMnemonic('y');
editExchangeMenuItem.setText("Exchange ...");
editExchangeMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editExchangeMenuItemActionPerformed(evt);
}
});
editMenu.add(editExchangeMenuItem);
2017-01-28 15:34:24 +01:00
editMenu.add(jSeparator1);
2017-01-15 18:15:22 +01:00
2017-01-26 01:52:03 +01:00
pasteMenuItem.setMnemonic('s');
pasteMenuItem.setText("Strategies ...");
pasteMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pasteMenuItemActionPerformed(evt);
}
});
2017-01-15 18:15:22 +01:00
editMenu.add(pasteMenuItem);
deleteMenuItem.setMnemonic('d');
deleteMenuItem.setText("Traders ...");
deleteMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteMenuItemActionPerformed(evt);
}
});
2017-01-15 18:15:22 +01:00
editMenu.add(deleteMenuItem);
2017-01-28 15:34:24 +01:00
editMenu.add(jSeparator2);
2017-01-15 18:15:22 +01:00
2017-01-22 21:41:45 +01:00
editPreferences.setMnemonic('p');
editPreferences.setText("Preferences ...");
editPreferences.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
editPreferencesActionPerformed(evt);
}
});
editMenu.add(editPreferences);
2017-01-15 18:15:22 +01:00
menuBar.add(editMenu);
simMenu.setMnemonic('s');
2017-02-04 18:57:18 +01:00
simMenu.setText("Sim");
2017-02-04 16:29:45 +01:00
2017-02-05 10:31:52 +01:00
simMenuStart.setMnemonic('s');
2017-02-04 18:57:18 +01:00
simMenuStart.setText("Start");
simMenuStart.addActionListener(new java.awt.event.ActionListener() {
2017-02-04 16:29:45 +01:00
public void actionPerformed(java.awt.event.ActionEvent evt) {
2017-02-04 18:57:18 +01:00
simMenuStartActionPerformed(evt);
2017-02-04 16:29:45 +01:00
}
});
2017-02-04 18:57:18 +01:00
simMenu.add(simMenuStart);
2017-02-05 10:31:52 +01:00
simMenuPause.setMnemonic('p');
2017-02-04 18:57:18 +01:00
simMenuPause.setText("Pause");
simMenuPause.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
simMenuPauseActionPerformed(evt);
}
});
simMenu.add(simMenuPause);
2017-02-04 16:29:45 +01:00
2017-02-05 10:31:52 +01:00
simMenuStop.setMnemonic('t');
simMenuStop.setText("Stop");
simMenuStop.addActionListener(new java.awt.event.ActionListener() {
2017-02-04 16:29:45 +01:00
public void actionPerformed(java.awt.event.ActionEvent evt) {
2017-02-05 10:31:52 +01:00
simMenuStopActionPerformed(evt);
2017-02-04 16:29:45 +01:00
}
});
2017-02-05 10:31:52 +01:00
simMenu.add(simMenuStop);
2017-02-04 16:29:45 +01:00
2017-02-04 18:57:18 +01:00
menuBar.add(simMenu);
2017-02-04 16:29:45 +01:00
viewMenu.setMnemonic('v');
2017-02-02 18:39:55 +01:00
viewMenu.setText("View");
2017-01-22 21:41:45 +01:00
jMenuItem2.setText("Traders");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
2017-02-02 18:39:55 +01:00
viewMenu.add(jMenuItem2);
2017-01-22 21:41:45 +01:00
2017-02-13 18:26:32 +01:00
viewClock.setText("Clock");
viewClock.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
viewClockActionPerformed(evt);
}
});
viewMenu.add(viewClock);
2017-01-28 15:34:24 +01:00
jMenuItem3.setText("LogWindow");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
2017-02-02 18:39:55 +01:00
viewMenu.add(jMenuItem3);
2017-01-28 15:34:24 +01:00
2017-02-13 18:26:32 +01:00
jCheckBoxMenuItem1.setSelected(true);
jCheckBoxMenuItem1.setText("jCheckBoxMenuItem1");
jCheckBoxMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jCheckBoxMenuItem1ActionPerformed(evt);
}
});
2017-02-13 18:26:32 +01:00
viewMenu.add(jCheckBoxMenuItem1);
2017-02-02 18:39:55 +01:00
menuBar.add(viewMenu);
2017-01-22 21:41:45 +01:00
2017-01-15 18:15:22 +01:00
helpMenu.setMnemonic('h');
helpMenu.setText("Help");
contentMenuItem.setMnemonic('c');
contentMenuItem.setText("Contents");
helpMenu.add(contentMenuItem);
aboutMenuItem.setMnemonic('a');
aboutMenuItem.setText("About");
2017-01-22 21:41:45 +01:00
aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
aboutMenuItemActionPerformed(evt);
}
});
2017-01-15 18:15:22 +01:00
helpMenu.add(aboutMenuItem);
menuBar.add(helpMenu);
setJMenuBar(menuBar);
pack();
}// </editor-fold>//GEN-END:initComponents
private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
System.exit(0);
}//GEN-LAST:event_exitMenuItemActionPerformed
2017-01-22 21:41:45 +01:00
private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed
Dialog d = new gui.AboutDialog(this, rootPaneCheckingEnabled);
d.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_aboutMenuItemActionPerformed
2017-02-07 01:53:43 +01:00
void pauseSim() {
2017-02-05 10:24:18 +01:00
Globals.se.timer.pause();
2017-02-04 18:57:18 +01:00
}
2017-02-07 01:53:43 +01:00
void startSim() {
2017-02-13 00:07:50 +01:00
2017-02-04 16:29:45 +01:00
resetSim();
2017-02-13 00:07:50 +01:00
JSONObject jo = new JSONObject(Globals.prefs.get("Exchange", "{}"));
Globals.se.putConfig(jo);
2017-02-07 01:53:43 +01:00
this.stopButton.setEnabled(true);
2017-02-11 13:12:02 +01:00
// this.orderBookPanel.invalidate();
// this.orderBookPanel.repaint();
2017-02-11 13:12:02 +01:00
this.clock.invalidate();
this.clock.repaint();
2017-01-22 21:41:45 +01:00
this.startTraders();
2017-02-07 01:53:43 +01:00
2017-02-05 10:24:18 +01:00
Globals.se.timer.setPause(false);
2017-01-22 21:41:45 +01:00
Globals.se.timer.start();
2017-02-07 01:53:43 +01:00
Globals.se.timer.setAcceleration((Double) this.accelSpinner.getValue());
2017-02-11 13:12:02 +01:00
2017-02-06 08:14:05 +01:00
2017-02-04 16:29:45 +01:00
}
2017-02-07 01:53:43 +01:00
void stopSim() {
2017-02-04 16:29:45 +01:00
Globals.se.timer.terminate();
2017-02-06 08:14:05 +01:00
this.stopButton.setEnabled(false);
2017-02-04 16:29:45 +01:00
}
2017-02-07 01:53:43 +01:00
void resetSim() {
2017-02-04 16:29:45 +01:00
Globals.se.terminate();
Globals.se.reset();
2017-02-07 01:53:43 +01:00
chart.initChart();
chart.invalidate();
chart.repaint();
// this.orderBookPanel.invalidate();
// this.orderBookPanel.repaint();
2017-02-07 01:53:43 +01:00
2017-02-04 16:29:45 +01:00
}
2017-02-07 01:53:43 +01:00
2017-01-22 21:41:45 +01:00
private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed
2017-01-28 15:34:24 +01:00
Globals.LOGGER.info("Edit prefs...");
2017-01-22 21:41:45 +01:00
Dialog d = new gui.EditPreferencesDialog(this, rootPaneCheckingEnabled);
d.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_editPreferencesActionPerformed
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
2017-01-23 18:56:09 +01:00
TraderListDialog d = new TraderListDialog(this, false);
2017-01-22 21:41:45 +01:00
d.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_jMenuItem2ActionPerformed
private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed
2017-01-28 15:34:24 +01:00
EditAutoTraderListDialog ed = new EditAutoTraderListDialog(this, true);
2017-01-25 00:24:53 +01:00
ed.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_deleteMenuItemActionPerformed
2017-01-26 01:52:03 +01:00
private void pasteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteMenuItemActionPerformed
2017-01-28 15:34:24 +01:00
EditStrategies s = new EditStrategies(this, true);
2017-01-26 01:52:03 +01:00
s.setVisible(rootPaneCheckingEnabled);
2017-02-07 01:53:43 +01:00
2017-01-26 01:52:03 +01:00
}//GEN-LAST:event_pasteMenuItemActionPerformed
2017-02-07 01:53:43 +01:00
private final LoggerDialog log_d = new LoggerDialog(this, false);
2017-01-28 15:34:24 +01:00
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
log_d.setVisible(!log_d.isShowing());
2017-02-07 01:53:43 +01:00
2017-01-28 15:34:24 +01:00
}//GEN-LAST:event_jMenuItem3ActionPerformed
2017-01-31 08:04:11 +01:00
private void openMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openMenuItemActionPerformed
2017-02-07 01:53:43 +01:00
2017-01-31 08:04:11 +01:00
}//GEN-LAST:event_openMenuItemActionPerformed
private void saveAsMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsMenuItemActionPerformed
JFileChooser fc = new JFileChooser();
2017-02-07 01:53:43 +01:00
FileNameExtensionFilter filter = new FileNameExtensionFilter("SeSim Files", "sesim");
2017-01-31 08:04:11 +01:00
fc.setFileFilter(filter);
2017-02-07 01:53:43 +01:00
if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
2017-01-31 08:04:11 +01:00
return;
}
2017-02-07 01:53:43 +01:00
2017-01-31 08:04:11 +01:00
File f = fc.getSelectedFile();
2017-02-07 01:53:43 +01:00
String[] e = ((FileNameExtensionFilter) fc.getFileFilter()).getExtensions();
2017-01-31 08:04:11 +01:00
System.out.printf("Abs: %s\n", f.getAbsoluteFile());
2017-02-07 01:53:43 +01:00
String fn = f.getAbsolutePath();
if (!f.getAbsolutePath().endsWith(e[0])) {
f = new File(f.getAbsolutePath() + "." + e[0]);
2017-01-31 08:04:11 +01:00
}
Globals.saveFile(f);
2017-02-07 01:53:43 +01:00
System.out.printf("Sel File: %s \n", f.getAbsolutePath());
2017-01-31 08:04:11 +01:00
}//GEN-LAST:event_saveAsMenuItemActionPerformed
private void editExchangeMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editExchangeMenuItemActionPerformed
2017-02-07 01:53:43 +01:00
EditExchangeDialog ed = new EditExchangeDialog((Frame) this.getParent(), true);
2017-01-31 08:04:11 +01:00
int rc = ed.showdialog();
2017-02-07 01:53:43 +01:00
// System.out.printf("EDRET: %d\n",rc);
2017-01-31 08:04:11 +01:00
}//GEN-LAST:event_editExchangeMenuItemActionPerformed
2017-02-02 18:39:55 +01:00
private void viewClockActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewClockActionPerformed
2017-02-07 01:53:43 +01:00
ClockDialog cd = new ClockDialog(this, true);
2017-02-02 18:39:55 +01:00
cd.setVisible(rootPaneCheckingEnabled);
2017-02-07 01:53:43 +01:00
2017-02-02 18:39:55 +01:00
}//GEN-LAST:event_viewClockActionPerformed
2017-02-04 16:29:45 +01:00
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem1ActionPerformed
2017-02-04 18:57:18 +01:00
private void simMenuStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simMenuStartActionPerformed
2017-02-04 16:29:45 +01:00
startSim();
2017-02-04 18:57:18 +01:00
}//GEN-LAST:event_simMenuStartActionPerformed
2017-02-04 16:29:45 +01:00
2017-02-04 18:57:18 +01:00
private void simMenuPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simMenuPauseActionPerformed
2017-02-05 10:31:52 +01:00
pauseSim();
2017-02-04 18:57:18 +01:00
}//GEN-LAST:event_simMenuPauseActionPerformed
2017-02-05 10:31:52 +01:00
private void simMenuStopActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simMenuStopActionPerformed
stopSim();
}//GEN-LAST:event_simMenuStopActionPerformed
2017-02-06 08:14:05 +01:00
private void accelSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_accelSpinnerStateChanged
2017-02-07 01:53:43 +01:00
Double val = (Double) this.accelSpinner.getValue();
2017-02-06 08:14:05 +01:00
Globals.se.timer.setAcceleration(val);
}//GEN-LAST:event_accelSpinnerStateChanged
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Globals.se.timer.pause();
}//GEN-LAST:event_jButton2ActionPerformed
private void runButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_runButtonActionPerformed
startSim();
}//GEN-LAST:event_runButtonActionPerformed
private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
stopSim();
}//GEN-LAST:event_stopButtonActionPerformed
private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed
JDialog jd = new gui.orderbook.OrderBookDialog(this, false);
jd.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed
2017-01-15 18:15:22 +01:00
/**
* @param args the command line arguments
2017-01-25 00:24:53 +01:00
* @throws java.lang.IllegalAccessException
* @throws java.lang.InstantiationException
2017-01-15 18:15:22 +01:00
*/
2017-01-25 00:24:53 +01:00
public static void main(String args[]) throws IllegalAccessException, InstantiationException {
2017-02-11 08:36:45 +01:00
sesim.AutoTraderLoader tl = new sesim.AutoTraderLoader();
tl.getTraders();
//System.exit(0);
2017-01-22 21:41:45 +01:00
Globals.se = new Exchange();
2017-01-28 15:34:24 +01:00
2017-02-11 08:36:45 +01:00
2017-01-28 15:34:24 +01:00
2017-01-25 02:52:49 +01:00
Class<?> c = sesim.Exchange.class;
2017-01-28 15:34:24 +01:00
Globals.prefs = Preferences.userNodeForPackage(c);
2017-01-25 02:52:49 +01:00
Globals.setLookAndFeel(Globals.prefs.get("laf", "Nimbus"));
2017-01-28 15:34:24 +01:00
2017-01-15 18:15:22 +01:00
java.awt.EventQueue.invokeLater(new Runnable() {
2017-02-11 08:36:45 +01:00
@Override
2017-01-15 18:15:22 +01:00
public void run() {
new NewMDIApplication().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JMenuItem aboutMenuItem;
2017-02-05 10:01:13 +01:00
private javax.swing.JSpinner accelSpinner;
2017-02-04 16:29:45 +01:00
private chart.Chart chart;
2017-02-06 08:14:05 +01:00
private gui.Clock clock;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenuItem contentMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
2017-01-31 08:04:11 +01:00
private javax.swing.JMenuItem editExchangeMenuItem;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenu editMenu;
2017-01-22 21:41:45 +01:00
private javax.swing.JMenuItem editPreferences;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
2017-01-22 21:41:45 +01:00
private javax.swing.JButton jButton2;
2017-02-04 16:29:45 +01:00
private javax.swing.JScrollPane jChartScrollPane;
2017-02-13 18:26:32 +01:00
private javax.swing.JCheckBoxMenuItem jCheckBoxMenuItem1;
2017-02-06 08:14:05 +01:00
private javax.swing.JComboBox<String> jComboBox1;
2017-02-04 16:29:45 +01:00
private javax.swing.JMenuItem jMenuItem1;
2017-01-22 21:41:45 +01:00
private javax.swing.JMenuItem jMenuItem2;
2017-01-28 15:34:24 +01:00
private javax.swing.JMenuItem jMenuItem3;
2017-02-03 01:56:41 +01:00
private javax.swing.JPanel jPanel2;
2017-01-28 15:34:24 +01:00
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
2017-02-13 18:26:32 +01:00
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JSplitPane jSplitPane2;
2017-02-18 08:17:07 +01:00
private javax.swing.JSplitPane jSplitPane3;
private javax.swing.JSplitPane jSplitPane4;
2017-01-28 15:34:24 +01:00
private javax.swing.JTextArea jTextArea1;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem openMenuItem;
private gui.orderbook.OrderBook orderBookNew1;
2017-02-13 18:26:32 +01:00
private gui.orderbook.OrderBooksHorizontal orderBooksHorizontal1;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenuItem pasteMenuItem;
private gui.orderbook.QuoteVertical quoteVertical1;
2017-02-06 08:14:05 +01:00
private javax.swing.JButton runButton;
2017-01-15 18:15:22 +01:00
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
2017-02-04 18:57:18 +01:00
private javax.swing.JMenu simMenu;
private javax.swing.JMenuItem simMenuPause;
private javax.swing.JMenuItem simMenuStart;
2017-02-05 10:31:52 +01:00
private javax.swing.JMenuItem simMenuStop;
2017-02-06 08:14:05 +01:00
private javax.swing.JButton stopButton;
2017-02-13 18:26:32 +01:00
private gui.TraderListPanel traderListPanel1;
2017-02-02 18:39:55 +01:00
private javax.swing.JMenuItem viewClock;
private javax.swing.JMenu viewMenu;
2017-01-15 18:15:22 +01:00
// End of variables declaration//GEN-END:variables
}