Work on manual trading, orderbook etc...

This commit is contained in:
7u83 2017-02-13 09:02:40 +01:00
parent 6039c95d6a
commit 273dac9d26
25 changed files with 619 additions and 438 deletions

View File

@ -43,6 +43,11 @@
<artifactId>beansbinding</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -39,8 +39,11 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="cancelButton" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jDevleopmentFeaturesCheckBox" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="godmodeCheckBox" min="-2" max="-2" attributes="0"/>
<Component id="jDevleopmentFeaturesCheckBox" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
@ -56,9 +59,11 @@
<Component id="lafComboBox" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace pref="178" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="godmodeCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jDevleopmentFeaturesCheckBox" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="40" max="-2" attributes="0"/>
<EmptySpace pref="188" max="32767" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="cancelButton" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="applyButton" alignment="3" min="-2" max="-2" attributes="0"/>
@ -125,5 +130,10 @@
<Property name="text" type="java.lang.String" value="Develeopment"/>
</Properties>
</Component>
<Component class="javax.swing.JCheckBox" name="godmodeCheckBox">
<Properties>
<Property name="text" type="java.lang.String" value="Godmode"/>
</Properties>
</Component>
</SubComponents>
</Form>

View File

@ -42,9 +42,9 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
UIManager.LookAndFeelInfo[] lafInfo;
LookAndFeel old_laf;
LookAndFeel new_laf;
LookAndFeel old_laf;
LookAndFeel new_laf;
/**
* Creates new form EditPreferencesDialog
*/
@ -52,20 +52,25 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
super(parent, modal);
initComponents();
this.setLocationRelativeTo(this.getParent());
old_laf = UIManager.getLookAndFeel();
lafInfo = UIManager.getInstalledLookAndFeels();
lafComboBox.removeAllItems();
for (UIManager.LookAndFeelInfo lafInfo1 : lafInfo) {
lafComboBox.addItem(lafInfo1.getName());
}
lafComboBox.setSelectedItem(Globals.prefs.get("laf", "Nimbus"));
String selstr = Globals.prefs.get(Globals.DEVELSTATUS,"false");
String selstr;
selstr = Globals.prefs.get(Globals.DEVELSTATUS, "false");
this.jDevleopmentFeaturesCheckBox.setSelected(selstr.equals("true"));
selstr = Globals.prefs.get(Globals.GODMODE, "false");
this.godmodeCheckBox.setSelected(selstr.equals("true"));
}
/**
@ -83,6 +88,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
okButton = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jDevleopmentFeaturesCheckBox = new javax.swing.JCheckBox();
godmodeCheckBox = new javax.swing.JCheckBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
@ -121,6 +127,8 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
jDevleopmentFeaturesCheckBox.setText("Develeopment");
godmodeCheckBox.setText("Godmode");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
@ -140,7 +148,9 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cancelButton))
.addGroup(layout.createSequentialGroup()
.addComponent(jDevleopmentFeaturesCheckBox)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(godmodeCheckBox)
.addComponent(jDevleopmentFeaturesCheckBox))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
@ -151,9 +161,11 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lafComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 178, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(godmodeCheckBox)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jDevleopmentFeaturesCheckBox)
.addGap(40, 40, 40)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 188, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cancelButton)
.addComponent(applyButton)
@ -169,7 +181,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
}//GEN-LAST:event_lafComboBoxActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
if (old_laf!=new_laf){
if (old_laf != new_laf) {
try {
UIManager.setLookAndFeel(old_laf);
} catch (UnsupportedLookAndFeelException ex) {
@ -180,22 +192,24 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
this.dispose();
}//GEN-LAST:event_cancelButtonActionPerformed
void resetUI(){
for (Window w : Window.getWindows()) {
void resetUI() {
for (Window w : Window.getWindows()) {
System.out.print("Setting frame\n");
SwingUtilities.updateComponentTreeUI(w);
w.pack();
}
}
}
private void applyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_applyButtonActionPerformed
String selected = (String) this.lafComboBox.getSelectedItem();
Globals.setLookAndFeel(selected);
new_laf=UIManager.getLookAndFeel();
new_laf = UIManager.getLookAndFeel();
resetUI();
}//GEN-LAST:event_applyButtonActionPerformed
@ -203,8 +217,12 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
this.applyButtonActionPerformed(evt);
String selected = (String) this.lafComboBox.getSelectedItem();
Globals.prefs.put("laf", selected);
String sel = this.jDevleopmentFeaturesCheckBox.isSelected() == true ? "true" : "false";
Globals.prefs.put(Globals.DEVELSTATUS,sel);
String sel;
sel = this.jDevleopmentFeaturesCheckBox.isSelected() == true ? "true" : "false";
Globals.prefs.put(Globals.DEVELSTATUS, sel);
sel = this.godmodeCheckBox.isSelected() == true ? "true" : "false";
Globals.prefs.put(Globals.GODMODE, sel);
Globals.notifyCfgListeners();
this.dispose();
}//GEN-LAST:event_okButtonActionPerformed
@ -253,6 +271,7 @@ public class EditPreferencesDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton applyButton;
private javax.swing.JButton cancelButton;
private javax.swing.JCheckBox godmodeCheckBox;
private javax.swing.JCheckBox jDevleopmentFeaturesCheckBox;
private javax.swing.JLabel jLabel1;
private javax.swing.JComboBox<String> lafComboBox;

View File

@ -28,6 +28,7 @@ package gui;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.logging.Level;
@ -46,12 +47,28 @@ import sesim.AutoTraderLoader;
*/
public class Globals {
public interface CfgListener{
void cfgChanged();
}
static ArrayList <CfgListener> cfg_listeners = new ArrayList<>();
public static void notifyCfgListeners(){
for (CfgListener l : cfg_listeners){
l.cfgChanged();
}
}
public static void addCfgListener(CfgListener l){
cfg_listeners.add(l);
}
public static JFrame frame;
static final String STRATEGYPREFS = "Strategies";
static final String TRADERPREFS = "Traders";
static final String DEVELSTATUS = "devel_status";
static final String GODMODE = "godmode";
static public sesim.Exchange se;

View File

@ -23,12 +23,22 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" pref="400" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" pref="586" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="63" max="-2" attributes="0"/>
<Component id="orderBookNew1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="300" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jScrollPane1" min="-2" pref="160" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="orderBookNew1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="9" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
@ -49,5 +59,7 @@
</Component>
</SubComponents>
</Container>
<Component class="gui.OrderBookNew" name="orderBookNew1">
</Component>
</SubComponents>
</Form>

View File

@ -85,6 +85,7 @@ public class LoggerDialog extends javax.swing.JDialog {
jScrollPane1 = new javax.swing.JScrollPane();
logArea = new javax.swing.JTextArea();
orderBookNew1 = new gui.OrderBookNew();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
@ -97,11 +98,19 @@ public class LoggerDialog extends javax.swing.JDialog {
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 586, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(63, 63, 63)
.addComponent(orderBookNew1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(orderBookNew1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 9, Short.MAX_VALUE))
);
pack();
@ -152,5 +161,6 @@ public class LoggerDialog extends javax.swing.JDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea logArea;
private gui.OrderBookNew orderBookNew1;
// End of variables declaration//GEN-END:variables
}

View File

@ -243,7 +243,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel" min="-2" pref="233" max="-2" attributes="0"/>
<Component id="oderBookPanelNew1" min="-2" pref="220" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jChartScrollPane" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@ -259,7 +259,10 @@
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jChartScrollPane" max="32767" attributes="0"/>
<Component id="orderBookPanel" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="oderBookPanelNew1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -267,8 +270,6 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.OrderBookPanel" name="orderBookPanel">
</Component>
<Container class="javax.swing.JScrollPane" name="jChartScrollPane">
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
@ -419,5 +420,7 @@
</Component>
</SubComponents>
</Container>
<Component class="gui.OderBookPanelNew" name="oderBookPanelNew1">
</Component>
</SubComponents>
</Form>

View File

@ -142,7 +142,6 @@ public class NewMDIApplication extends javax.swing.JFrame {
jScrollPane2 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
orderBookPanel = new gui.OrderBookPanel();
jChartScrollPane = new javax.swing.JScrollPane();
chart = new chart.Chart();
jPanel2 = new javax.swing.JPanel();
@ -152,6 +151,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
accelSpinner = new javax.swing.JSpinner();
clock = new gui.Clock();
jComboBox1 = new javax.swing.JComboBox<>();
oderBookPanelNew1 = new gui.OderBookPanelNew();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
@ -458,7 +458,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(oderBookPanelNew1, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jChartScrollPane)
.addContainerGap())
@ -472,7 +472,9 @@ public class NewMDIApplication extends javax.swing.JFrame {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jChartScrollPane)
.addComponent(orderBookPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(oderBookPanelNew1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
@ -503,8 +505,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
this.stopButton.setEnabled(true);
this.orderBookPanel.invalidate();
this.orderBookPanel.repaint();
// this.orderBookPanel.invalidate();
// this.orderBookPanel.repaint();
this.clock.invalidate();
this.clock.repaint();
@ -529,8 +531,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
chart.initChart();
chart.invalidate();
chart.repaint();
this.orderBookPanel.invalidate();
this.orderBookPanel.repaint();
// this.orderBookPanel.invalidate();
// this.orderBookPanel.repaint();
}
@ -705,8 +707,8 @@ public class NewMDIApplication extends javax.swing.JFrame {
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JMenuBar menuBar;
private gui.OderBookPanelNew oderBookPanelNew1;
private javax.swing.JMenuItem openMenuItem;
private gui.OrderBookPanel orderBookPanel;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JButton runButton;
private javax.swing.JMenuItem saveAsMenuItem;

View File

@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Component id="filler1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="quotePanel1" max="32767" attributes="0"/>
</Group>
<Component id="orderBookNew3" alignment="1" pref="585" max="32767" attributes="0"/>
<Component id="orderBookNew4" alignment="0" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookNew3" min="-2" pref="156" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="70" max="-2" attributes="0"/>
<Component id="filler1" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace min="-2" pref="30" max="-2" attributes="0"/>
<Component id="quotePanel1" min="-2" pref="91" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="32767" attributes="0"/>
<Component id="orderBookNew4" min="-2" pref="176" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.QuotePanel" name="quotePanel1">
</Component>
<Component class="gui.OrderBookNew" name="orderBookNew3">
</Component>
<Component class="gui.OrderBookNew" name="orderBookNew4">
</Component>
<Component class="javax.swing.Box$Filler" name="filler1">
<Properties>
<Property name="maximumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[0, 32767]"/>
</Property>
</Properties>
<AuxValues>
<AuxValue name="classDetails" type="java.lang.String" value="Box.Filler.VerticalGlue"/>
</AuxValues>
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,95 @@
/*
* 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 OderBookPanelNew extends javax.swing.JPanel {
/**
* Creates new form OderBookPanelNew
*/
public OderBookPanelNew() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
quotePanel1 = new gui.QuotePanel();
orderBookNew3 = new gui.OrderBookNew();
orderBookNew4 = new gui.OrderBookNew();
filler1 = new javax.swing.Box.Filler(new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 0), new java.awt.Dimension(0, 32767));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(quotePanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(orderBookNew3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 585, Short.MAX_VALUE)
.addComponent(orderBookNew4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookNew3, javax.swing.GroupLayout.PREFERRED_SIZE, 156, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(70, 70, 70)
.addComponent(filler1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(30, 30, 30)
.addComponent(quotePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(orderBookNew4, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.Box.Filler filler1;
private gui.OrderBookNew orderBookNew3;
private gui.OrderBookNew orderBookNew4;
private gui.QuotePanel quotePanel1;
// End of variables declaration//GEN-END:variables
}

View File

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.9" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties>
<Property name="defaultCloseOperation" type="int" value="2"/>
</Properties>
<SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/>
<SyntheticProperty name="generateCenter" type="boolean" value="false"/>
</SyntheticProperties>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,2,-118,0,0,1,-80"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignFlowLayout"/>
<SubComponents>
<Component class="gui.OrderBookNew" name="orderBookNew1">
</Component>
<Component class="gui.QuotePanel" name="quotePanel1">
</Component>
<Component class="gui.OrderBookNew" name="orderBookNew2">
</Component>
</SubComponents>
</Form>

View File

@ -0,0 +1,111 @@
/*
* 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 OrderBookDialog extends javax.swing.JDialog {
/**
* Creates new form OrderBookDialog
*/
public OrderBookDialog(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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
orderBookNew1 = new gui.OrderBookNew();
quotePanel1 = new gui.QuotePanel();
orderBookNew2 = new gui.OrderBookNew();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(new java.awt.FlowLayout());
getContentPane().add(orderBookNew1);
getContentPane().add(quotePanel1);
getContentPane().add(orderBookNew2);
pack();
}// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(OrderBookDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(OrderBookDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(OrderBookDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(OrderBookDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
OrderBookDialog dialog = new OrderBookDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private gui.OrderBookNew orderBookNew1;
private gui.OrderBookNew orderBookNew2;
private gui.QuotePanel quotePanel1;
// End of variables declaration//GEN-END:variables
}

View File

@ -16,12 +16,12 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="1" pref="537" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jScrollPane1" alignment="0" pref="300" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
@ -35,20 +35,14 @@
<SubComponents>
<Component class="javax.swing.JTable" name="list">
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="5" rowCount="5">
<Column editable="false" title="ID" type="java.lang.Long"/>
<Column editable="false" title="Name" type="java.lang.String"/>
<Column editable="false" title="Money" type="java.lang.Double"/>
<Column editable="false" title="Shares" type="java.lang.Double"/>
<Column editable="false" title="Wealth" type="java.lang.Double"/>
<Table columnCount="3" rowCount="4">
<Column editable="false" title="Trader" type="java.lang.String"/>
<Column editable="false" title="Price" type="java.lang.Double"/>
<Column editable="false" title="Volume" type="java.lang.Double"/>
</Table>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseClicked"/>
</Events>
</Component>
</SubComponents>
</Container>

View File

@ -25,75 +25,81 @@
*/
package gui;
import gui.Globals.CfgListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import sesim.AutoTraderInterface;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import sesim.Exchange;
import sesim.Exchange.Account;
import sesim.Exchange.Order;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class TraderListPanel2 extends javax.swing.JPanel {
public class OrderBookNew extends javax.swing.JPanel implements Exchange.BookReceiver, CfgListener {
DefaultTableModel model;
TableColumn trader_column = null;
final void updateModel() {
if (Globals.se == null) {
public void setGodMode(boolean on) {
TableColumnModel tcm = list.getColumnModel();
if (on){
if (list.getColumnCount()==3){
return;
}
tcm.addColumn(trader_column);
tcm.moveColumn(2, 0);
return;
}
if (Globals.se.traders == null) {
return;
else{
if (list.getColumnCount()==2){
return;
}
tcm.removeColumn(tcm.getColumn(0));
}
sesim.Quote q = Globals.se.getLastQuoete();
double price = q == null ? 0 : q.price;
int size = Globals.se.traders.size();
model.setRowCount(size);
for (int i = 0; i < size; i++) {
AutoTraderInterface at = Globals.se.traders.get(i);
Account a = at.getAccount();
model.setValueAt(i, i, 0);
model.setValueAt(at.getName(), i, 1);
model.setValueAt(a.getMoney(), i, 2);
model.setValueAt(a.getShares(), i, 3);
double wealth = a.getShares() * price + a.getMoney();
model.setValueAt(wealth, i, 4);
}
list.getRowSorter().allRowsChanged();
}
TimerTask updater;
@Override
public void cfgChanged() {
boolean gm = Globals.prefs.get(Globals.GODMODE, "false").equals("true");
System.out.printf("GM %s\n",gm?"true":"false");
setGodMode(gm);
list.invalidate();
list.repaint();
}
/**
* Creates new form TraderListPanel2
* Creates new form OrderBookNew
*/
public TraderListPanel2() {
public OrderBookNew() {
initComponents();
model = (DefaultTableModel) list.getModel();
updateModel();
if (Globals.se==null)
return;
model = (DefaultTableModel) this.list.getModel();
trader_column = list.getColumnModel().getColumn(0);
cfgChanged();
Globals.se.addBookReceiver(Exchange.OrderType.BUYLIMIT, this);
Globals.addCfgListener(this);
}
Timer timer = new Timer();
updater = new TimerTask() {
@Override
public void run() {
updateModel();
}
};
timer.schedule(updater, 0, 1000);
@Override
public void UpdateOrderBook() {
ArrayList<Order> ob = Globals.se.getOrderBook(Exchange.OrderType.SELLLIMIT, 40);
model.setRowCount(ob.size());
int row = 0;
for (Order ob1 : ob) {
model.setValueAt(ob1.getAccount().getOwner().getName(), row, 0);
model.setValueAt(ob1.getLimit(), row, 1);
model.setValueAt(ob1.getVolume(), row, 2);
row++;
}
}
@ -109,24 +115,22 @@ public class TraderListPanel2 extends javax.swing.JPanel {
jScrollPane1 = new javax.swing.JScrollPane();
list = new javax.swing.JTable();
list.setAutoCreateRowSorter(true);
list.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"ID", "Name", "Money", "Shares", "Wealth"
"Trader", "Price", "Volume"
}
) {
Class[] types = new Class [] {
java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
java.lang.String.class, java.lang.Double.class, java.lang.Double.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false
false, false, false
};
public Class getColumnClass(int columnIndex) {
@ -137,45 +141,25 @@ public class TraderListPanel2 extends javax.swing.JPanel {
return canEdit [columnIndex];
}
});
list.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
listMouseClicked(evt);
}
});
jScrollPane1.setViewportView(list);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
if (evt.getClickCount() == 2) {
int index = list.rowAtPoint(evt.getPoint());
index = list.getRowSorter().convertRowIndexToModel(index);
Integer tid = (Integer)model.getValueAt(index, 0);
System.out.printf("Trader ID %d\n", tid);
JDialog console = Globals.se.traders.get(tid).getGuiConsole();
if (console == null)
return;
console.setVisible(true);
}
}//GEN-LAST:event_listMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable list;
// End of variables declaration//GEN-END:variables
}

View File

@ -40,7 +40,7 @@
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="5" rowCount="4">
<Table columnCount="5" rowCount="3">
<Column editable="false" title="ID" type="java.lang.Long"/>
<Column editable="false" title="Type" type="java.lang.String"/>
<Column editable="false" title="Limit" type="java.lang.Double"/>

View File

@ -92,7 +92,6 @@ public class OrdersList extends javax.swing.JPanel {
order_table.setAutoCreateRowSorter(true);
order_table.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}

View File

@ -125,7 +125,7 @@ public class QuotePanel extends javax.swing.JPanel implements sesim.Exchange.Quo
u.text = String.format("%.2f\n(%.0f)", q.price,q.volume);
u.text = String.format("%.8f\n(%.0f)", q.price,q.volume);
SwingUtilities.invokeLater(u);

View File

@ -1,28 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View File

@ -1,65 +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 TestPanel extends TraderListPanel {
/**
* Creates new form TestPanel
*/
public TestPanel() {
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")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View File

@ -34,7 +34,7 @@
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="gui.TraderListPanel2" name="traderListPanel22">
<Component class="gui.TraderListPanel" name="traderListPanel22">
</Component>
</SubComponents>
</Form>
</Form>

View File

@ -52,7 +52,7 @@ public class TraderListDialog extends javax.swing.JDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
traderListPanel22 = new gui.TraderListPanel2();
traderListPanel22 = new gui.TraderListPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Trader List");
@ -115,6 +115,6 @@ public class TraderListDialog extends javax.swing.JDialog {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private gui.TraderListPanel2 traderListPanel22;
private gui.TraderListPanel traderListPanel22;
// End of variables declaration//GEN-END:variables
}

View File

@ -16,37 +16,38 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="traderListScroller" alignment="1" pref="400" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="1" pref="537" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="traderListScroller" alignment="0" pref="300" max="32767" attributes="0"/>
<Component id="jScrollPane1" alignment="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Container class="javax.swing.JScrollPane" name="traderListScroller">
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
<AuxValues>
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
</AuxValues>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
<SubComponents>
<Component class="javax.swing.JTable" name="traderList">
<Component class="javax.swing.JTable" name="list">
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="4" rowCount="4">
<Column editable="true" title="Title 1" type="java.lang.Object"/>
<Column editable="true" title="Title 2" type="java.lang.Object"/>
<Column editable="true" title="Title 3" type="java.lang.Object"/>
<Column editable="true" title="Title 4" type="java.lang.Object"/>
<Table columnCount="5" rowCount="5">
<Column editable="false" title="ID" type="java.lang.Long"/>
<Column editable="false" title="Name" type="java.lang.String"/>
<Column editable="false" title="Money" type="java.lang.Double"/>
<Column editable="false" title="Shares" type="java.lang.Double"/>
<Column editable="false" title="Wealth" type="java.lang.Double"/>
</Table>
</Property>
</Properties>
<Events>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="traderListMouseClicked"/>
<EventHandler event="mouseClicked" listener="java.awt.event.MouseListener" parameters="java.awt.event.MouseEvent" handler="listMouseClicked"/>
</Events>
</Component>
</SubComponents>

View File

@ -25,21 +25,18 @@
*/
package gui;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Formatter;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.BorderFactory;
import javax.swing.ListModel;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import sesim.AutoTraderInterface;
import sesim.Exchange;
import sesim.Scheduler;
import sesim.Exchange.Account;
/**
*
@ -47,179 +44,56 @@ import sesim.Scheduler;
*/
public class TraderListPanel extends javax.swing.JPanel {
Exchange se;
TraderListModel model;
TimerTask updater;
/**
* Creates new form TraderListPanel
*/
public TraderListPanel() {
initComponents();
this.setBorder(BorderFactory.createEmptyBorder());
// this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
DefaultTableModel model;
final void updateModel() {
if (Globals.se == null) {
return;
}
this.model = new TraderListModel();
this.traderList.setModel(this.model);
traderList.setBorder(BorderFactory.createEmptyBorder());
JTableHeader h = this.traderList.getTableHeader();
// h.setBackground(Color.BLUE);
// h.setForeground(Color.green);
if (Globals.se != null) {
this.se = Globals.se;
this.list = this.getTraderList();
// se.timer.startTimerEvent(this, 1000);
Timer timer = new Timer();
updater = new TimerTask() {
@Override
public void run() {
timerTask();
}
};
timer.schedule(updater, 0, 1000);
if (Globals.se.traders == null) {
return;
}
}
final ArrayList<TraderListItem> getTraderList() {
if (se.traders == null) {
return new ArrayList<>();
}
sesim.Quote q = se.getLastQuoete();
sesim.Quote q = Globals.se.getLastQuoete();
double price = q == null ? 0 : q.price;
Iterator<AutoTraderInterface> it = se.traders.iterator();
ArrayList<TraderListItem> tlist = new ArrayList<>();
while (it.hasNext()) {
AutoTraderInterface at = it.next();
Exchange.Account a = at.getAccount();
TraderListItem ti = new TraderListItem();
ti.name = at.getName();
ti.shares = a.getShares();
ti.money = a.getMoney();
ti.welth = price == 0 ? 0 : ti.shares * price + ti.money;
tlist.add(ti);
int size = Globals.se.traders.size();
model.setRowCount(size);
for (int i = 0; i < size; i++) {
AutoTraderInterface at = Globals.se.traders.get(i);
Account a = at.getAccount();
model.setValueAt(i, i, 0);
model.setValueAt(at.getName(), i, 1);
model.setValueAt(a.getMoney(), i, 2);
model.setValueAt(a.getShares(), i, 3);
double wealth = a.getShares() * price + a.getMoney();
model.setValueAt(wealth, i, 4);
}
return tlist;
list.getRowSorter().allRowsChanged();
}
public long timerTask() {
class Updater implements Runnable {
TimerTask updater;
TraderListModel model;
ArrayList<TraderListItem> newlist;
/**
* Creates new form TraderListPanel2
*/
public TraderListPanel() {
initComponents();
model = (DefaultTableModel) list.getModel();
updateModel();
Timer timer = new Timer();
updater = new TimerTask() {
@Override
public void run() {
model.update(this.newlist);
updateModel();
}
};
Updater(TraderListModel model, ArrayList newlist) {
this.model = model;
this.newlist = newlist;
}
}
//System.out.print("TimerTaskUpdater\n");
ArrayList<TraderListItem> newlist = getTraderList();
SwingUtilities.invokeLater(new Updater(this.model, newlist));
return 2000;
// throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
class TraderListItem {
public String name;
public double shares;
public double money;
public double welth;
}
private ArrayList<TraderListItem> list = new ArrayList<>();
protected class TraderListModel extends AbstractTableModel {
//private final boolean desc = false;
public TraderListModel() {
}
public void update(ArrayList newlist) {
list = newlist; //getOrderBook();
this.fireTableDataChanged();
}
@Override
public String getColumnName(int c) {
switch (c) {
case 0:
return "ID";
case 1:
return "Name";
case 2:
return "Money";
case 3:
return "Shares";
case 4:
return "Wealth";
}
return "";
}
@Override
public int getRowCount() {
int rc = list.size();
//System.out.print("Size" + rc + "\n");
return list.size();
}
@Override
public int getColumnCount() {
return 5;
}
@Override
public Object getValueAt(int r, int c) {
TraderListItem ti;
ti = list.get(r);
int s = list.size();
Formatter f = new Formatter();
switch (c) {
case 0:
return String.format("#%06x", 0);
case 1:
return String.format("%s", ti.name);
case 2:
return String.format("%.2f", ti.money);
case 3:
return String.format("%.2f", ti.shares);
case 4:
return ti.welth; //String.format("%.2f", ti.welth);
}
return "x";
}
timer.schedule(updater, 0, 1000);
}
@ -232,47 +106,77 @@ public class TraderListPanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
traderListScroller = new javax.swing.JScrollPane();
traderList = new javax.swing.JTable();
jScrollPane1 = new javax.swing.JScrollPane();
list = new javax.swing.JTable();
traderList.setAutoCreateRowSorter(true);
traderList.setModel(new javax.swing.table.DefaultTableModel(
list.setAutoCreateRowSorter(true);
list.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null},
{null, null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
"ID", "Name", "Money", "Shares", "Wealth"
}
));
traderList.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
traderListMouseClicked(evt);
) {
Class[] types = new Class [] {
java.lang.Long.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
};
boolean[] canEdit = new boolean [] {
false, false, false, false, false
};
public Class getColumnClass(int columnIndex) {
return types [columnIndex];
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
traderListScroller.setViewportView(traderList);
list.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
listMouseClicked(evt);
}
});
jScrollPane1.setViewportView(list);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(traderListScroller, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 537, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(traderListScroller, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
private void traderListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_traderListMouseClicked
}//GEN-LAST:event_traderListMouseClicked
private void listMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked
if (evt.getClickCount() == 2) {
int index = list.rowAtPoint(evt.getPoint());
index = list.getRowSorter().convertRowIndexToModel(index);
Integer tid = (Integer) model.getValueAt(index, 0);
System.out.printf("Trader ID %d\n", tid);
JDialog console = Globals.se.traders.get(tid).getGuiConsole();
if (console == null) {
return;
}
console.setVisible(true);
}
}//GEN-LAST:event_listMouseClicked
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable traderList;
private javax.swing.JScrollPane traderListScroller;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable list;
// End of variables declaration//GEN-END:variables
}

View File

@ -74,7 +74,7 @@ public class AutoTraderLoader {
}
Class<AutoTraderInterface> loadClass(String filename, String classname) {
Class<AutoTraderInterface> loadAutoTraderClass(String filename, String classname) {
String clnam = classname.substring(1, classname.length() - 6).replace('/', '.');
File f = new File(filename);
@ -95,20 +95,24 @@ public class AutoTraderLoader {
Class<?> cls = cl.loadClass(clnam);
System.out.printf("Check Class: %s\n",cls.getCanonicalName());
if (isAutoTrader(cls)){
System.out.printf("AT: %s\n",cls.getCanonicalName());
return (Class<AutoTraderInterface>) cls;
}
} catch (ClassNotFoundException ex) {
System.out.printf("Outch\n");
// something wnet wrong, but we ignore it
}
return null;
}
ArrayList<Class<AutoTraderInterface>> traders_cache=null;
public ArrayList<Class<AutoTraderInterface>> getTraders() {
if (traders_cache!=null){
return traders_cache;
}
int curlen = 0;
@ -122,7 +126,7 @@ public class AutoTraderLoader {
public void accept(Object t) {
String fn = ((Path) t).toString();
if (fn.toLowerCase().endsWith(".class")) {
Class<AutoTraderInterface> cls = loadClass(fn, fn.substring(classpathEntry.length()));
Class<AutoTraderInterface> cls = loadAutoTraderClass(fn, fn.substring(classpathEntry.length()));
if (cls == null) {
return;
}
@ -165,7 +169,7 @@ public class AutoTraderLoader {
}
}
traders_cache=traders;
return traders;
}

View File

@ -210,10 +210,7 @@ public class Scheduler extends Thread {
return 0;
} else {
//return 0;
long n =(t - currentTimeMillis())/(long)this.acceleration;
System.out.printf("Return wait %d\n",n);
return n;
return(t - currentTimeMillis())/(long)this.acceleration;
}
}