some impürovements

This commit is contained in:
7u83 2017-02-06 08:14:05 +01:00
parent 002c2add2b
commit 5de1ca26c7
12 changed files with 246 additions and 141 deletions

View File

@ -28,6 +28,11 @@
<artifactId>jlfgr</artifactId>
<version>1_0</version>
</dependency>
<dependency>
<groupId>com.github.arnabk</groupId>
<artifactId>pgslookandfeel</artifactId>
<version>1.1.4</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -18,7 +18,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" pref="154" max="32767" attributes="0"/>
<Component id="jLabel1" pref="153" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -27,7 +27,7 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" pref="42" max="-2" attributes="0"/>
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
@ -41,7 +41,7 @@
<Font bold="true" component="jLabel1" property="font" relativeSize="true" size="6"/>
</FontInfo>
</Property>
<Property name="horizontalAlignment" type="int" value="0"/>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="text" type="java.lang.String" value="00:00:00"/>
</Properties>
</Component>

View File

@ -80,7 +80,7 @@ public class Clock extends javax.swing.JPanel {
jLabel1 = new javax.swing.JLabel();
jLabel1.setFont(jLabel1.getFont().deriveFont(jLabel1.getFont().getStyle() | java.awt.Font.BOLD, jLabel1.getFont().getSize()+6));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel1.setText("00:00:00");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
@ -89,14 +89,14 @@ public class Clock extends javax.swing.JPanel {
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 154, Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 153, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents

View File

@ -69,13 +69,11 @@ public class EditAutoTraderList extends javax.swing.JPanel {
JSONObject jo = new JSONObject();
for (int x = 0; x < model.getColumnCount(); x++) {
Object cw = model.getValueAt(i, x);
System.out.printf("CWSaver: %s\n",cw.getClass().toString());
//System.out.printf("CWSaver: %s\n",cw.getClass().toString());
if (cw != null) {
jo.put((String) th.getColumnModel().getColumn(x).getHeaderValue(), cw.toString());
}
//ja.put(Integer.toString(i),jo);
}
ja.put(jo);
@ -83,7 +81,6 @@ public class EditAutoTraderList extends javax.swing.JPanel {
Globals.prefs.put("Traders", ja.toString());
// System.out.printf("Arlist: %s\n", ja.toString());
}
final void load() {
@ -91,13 +88,20 @@ public class EditAutoTraderList extends javax.swing.JPanel {
JSONArray traders = Globals.getTraders();
DefaultTableModel model = (DefaultTableModel) list.getModel();
model.setRowCount(traders.length());
for (int row = 0; row < traders.length(); row++) {
JSONObject rowobj = traders.getJSONObject(row);
for (int col = 0; col < list.getColumnCount(); col++) {
String h = this.getColumnHeader(col);
System.out.printf("Doing stuff for %s\n", h);
String val = rowobj.getString(h);
String val = null;
try {
val = rowobj.getString(h);
} catch (Exception e) {
continue;
}
System.out.printf("Want to set (%d,%d): %s\n", row, col, val);
//list.getModel().setValueAt(val, row, col);
@ -116,8 +120,8 @@ public class EditAutoTraderList extends javax.swing.JPanel {
if (cl == Boolean.class) {
cv = rowobj.getBoolean(h);
}
if (cl == Object.class){
cv=rowobj.getString(h);
if (cl == Object.class) {
cv = rowobj.getString(h);
}
list.getModel().setValueAt(cv, row, col);
@ -132,16 +136,16 @@ public class EditAutoTraderList extends javax.swing.JPanel {
*/
public EditAutoTraderList() {
initComponents();
if (Globals.se==null)
if (Globals.se == null) {
return;
}
this.load();
JComboBox comboBox = new JComboBox();
Globals.getStrategiesIntoComboBox(comboBox);
Globals.getStrategiesIntoComboBox(comboBox);
DefaultTableModel model = (DefaultTableModel) list.getModel();
list.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
@ -149,34 +153,32 @@ public class EditAutoTraderList extends javax.swing.JPanel {
// model.setRowCount(3);
list.setRowHeight(30);
list.getModel().addTableModelListener((TableModelEvent e) -> {
System.out.printf("Table has changed\n", "");
// if (summary==null)
// return;
Double money=0.0;
Double shares=0.0;
for (int r = 0; r < model.getRowCount(); r++) {
money+=(Double)list.getValueAt( r, list.getColumn("Money").getModelIndex());
shares+=(Double)list.getValueAt( r, list.getColumn("Shares").getModelIndex());
System.out.printf("Row: %d %f %f\n",r,money,shares);
// return;
Double money = 0.0;
Double shares = 0.0;
for (int r = 0; r < model.getRowCount(); r++) {
// money += (Double) list.getValueAt(r, list.getColumn("Money").getModelIndex());
// shares += (Double) list.getValueAt(r, list.getColumn("Shares").getModelIndex());
System.out.printf("Row: %d %f %f\n", r, money, shares);
}
this.summary.setText(String.format("Fair Value: %.5f", money/shares));
this.summary.setText(String.format("Fair Value: %.5f", money / shares));
});
}
void add(){
DefaultTableModel model = (DefaultTableModel) list.getModel();
model.setRowCount(model.getRowCount()+1);
void add() {
DefaultTableModel model = (DefaultTableModel) list.getModel();
model.setRowCount(model.getRowCount() + 1);
}
JLabel summary=null;
JLabel summary = null;
/**
* This method is called from within the constructor to initialize the form.

View File

@ -262,7 +262,7 @@
<Component id="jPanel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jChartScrollPane" max="32767" attributes="0"/>
<Component id="jChartScrollPane" pref="301" max="32767" attributes="0"/>
<Component id="orderBookPanel" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
@ -300,39 +300,50 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jRunButton" min="-2" pref="86" max="-2" attributes="0"/>
<Component id="runButton" min="-2" pref="86" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton2" min="-2" pref="67" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" pref="63" max="-2" attributes="0"/>
<Component id="stopButton" min="-2" pref="63" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="clock1" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="17" max="-2" attributes="0"/>
<Component id="accelSpinner" min="-2" pref="90" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="clock" alignment="1" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="accelSpinner" min="-2" pref="100" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jRunButton" alignment="0" max="32767" attributes="0"/>
<Component id="runButton" alignment="0" max="32767" attributes="0"/>
<Component id="jButton2" alignment="0" max="32767" attributes="0"/>
<Component id="jButton1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="accelSpinner" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="clock1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="9" max="32767" attributes="0"/>
<Component id="stopButton" alignment="0" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="-2" pref="3" max="-2" attributes="0"/>
<Component id="clock" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="accelSpinner" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="jComboBox1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JButton" name="jButton1">
<Component class="javax.swing.JButton" name="stopButton">
<Properties>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
<Image iconType="3" name="/toolbarButtonGraphics/general/Stop24.gif"/>
@ -343,14 +354,14 @@
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="stopButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jRunButton">
<Component class="javax.swing.JButton" name="runButton">
<Properties>
<Property name="font" type="java.awt.Font" editor="org.netbeans.modules.form.editors2.FontEditor">
<FontInfo relative="true">
<Font component="jRunButton" property="font" relativeSize="true" size="0"/>
<Font component="runButton" property="font" relativeSize="true" size="0"/>
</FontInfo>
</Property>
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
@ -363,7 +374,7 @@
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jRunButtonActionPerformed"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="runButtonActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton2">
@ -390,7 +401,25 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="accelSpinnerStateChanged"/>
</Events>
</Component>
<Component class="gui.Clock" name="clock1">
<Component class="gui.Clock" name="clock">
</Component>
<Component class="javax.swing.JComboBox" name="jComboBox1">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="7">
<StringItem index="0" value="1x"/>
<StringItem index="1" value="2x"/>
<StringItem index="2" value="4x"/>
<StringItem index="3" value="10x"/>
<StringItem index="4" value="100x"/>
<StringItem index="5" value="1000x"/>
<StringItem index="6" value="max."/>
</StringArray>
</Property>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_TypeParameters" type="java.lang.String" value="&lt;String&gt;"/>
</AuxValues>
</Component>
</SubComponents>
</Container>

View File

@ -79,6 +79,10 @@ public class NewMDIApplication extends javax.swing.JFrame {
Double shares = t.getDouble("Shares");
Double money = t.getDouble("Money");
Boolean enabled = t.getBoolean("Enabled");
if (!enabled)
continue;
System.out.printf("Count: %d Shares: %f Money %f\n", count,shares,money);
@ -98,7 +102,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
Globals.se.fairValue=moneyTotal/sharesTotal;
Globals.se.fairValue=1.0;
Globals.se.fairValue=15.0;
for (int i=0; i<Globals.se.traders.size(); i++){
Globals.se.traders.get(i).start();
@ -122,11 +126,12 @@ public class NewMDIApplication extends javax.swing.JFrame {
jChartScrollPane = new javax.swing.JScrollPane();
chart = new chart.Chart();
jPanel2 = new javax.swing.JPanel();
jButton1 = new javax.swing.JButton();
jRunButton = new javax.swing.JButton();
stopButton = new javax.swing.JButton();
runButton = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
accelSpinner = new javax.swing.JSpinner();
clock1 = new gui.Clock();
clock = new gui.Clock();
jComboBox1 = new javax.swing.JComboBox<>();
menuBar = new javax.swing.JMenuBar();
fileMenu = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
@ -175,27 +180,27 @@ public class NewMDIApplication extends javax.swing.JFrame {
jChartScrollPane.setViewportView(chart);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Stop24.gif"))); // NOI18N
jButton1.setText("Stop");
jButton1.setFocusable(false);
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton1.addActionListener(new java.awt.event.ActionListener() {
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() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
stopButtonActionPerformed(evt);
}
});
jRunButton.setFont(jRunButton.getFont());
jRunButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/run.gif"))); // NOI18N
jRunButton.setText("Run sim!");
jRunButton.setToolTipText("Run the simmulation");
jRunButton.setFocusable(false);
jRunButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jRunButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jRunButton.addActionListener(new java.awt.event.ActionListener() {
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() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRunButtonActionPerformed(evt);
runButtonActionPerformed(evt);
}
});
@ -217,35 +222,44 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
});
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "1x", "2x", "4x", "10x", "100x", "1000x", "max." }));
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jRunButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(runButton, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.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)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(stopButton, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clock1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(17, 17, 17)
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.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)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRunButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(runButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(accelSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addComponent(stopButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addComponent(clock1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(9, Short.MAX_VALUE))
.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())))
);
fileMenu.setMnemonic('f');
@ -439,7 +453,7 @@ public class NewMDIApplication extends javax.swing.JFrame {
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jChartScrollPane)
.addComponent(jChartScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
.addComponent(orderBookPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
@ -463,16 +477,23 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
void startSim(){
resetSim();
this.stopButton.setEnabled(true);
this.startTraders();
Globals.se.timer.setAcceleration((Double)this.accelSpinner.getValue());
Globals.se.timer.setPause(false);
Globals.se.timer.start();
Globals.se.timer.setAcceleration((Double)this.accelSpinner.getValue());
this.clock.invalidate();
this.clock.repaint();
}
void stopSim(){
Globals.se.timer.terminate();
this.stopButton.setEnabled(false);
}
void resetSim(){
@ -487,10 +508,6 @@ public class NewMDIApplication extends javax.swing.JFrame {
}
private void jRunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRunButtonActionPerformed
startSim();
}//GEN-LAST:event_jRunButtonActionPerformed
private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed
Globals.LOGGER.info("Edit prefs...");
@ -503,10 +520,6 @@ startSim();
d.setVisible(rootPaneCheckingEnabled);
}//GEN-LAST:event_jMenuItem2ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Globals.se.timer.pause();
}//GEN-LAST:event_jButton2ActionPerformed
private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed
EditAutoTraderListDialog ed = new EditAutoTraderListDialog(this, true);
ed.setVisible(rootPaneCheckingEnabled);
@ -584,11 +597,6 @@ startSim();
}//GEN-LAST:event_viewClockActionPerformed
private void accelSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_accelSpinnerStateChanged
Double val = (Double)this.accelSpinner.getValue();
Globals.se.timer.setAcceleration(val);
}//GEN-LAST:event_accelSpinnerStateChanged
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jMenuItem1ActionPerformed
@ -597,10 +605,6 @@ startSim();
startSim();
}//GEN-LAST:event_simMenuStartActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
stopSim();
}//GEN-LAST:event_jButton1ActionPerformed
private void simMenuPauseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_simMenuPauseActionPerformed
pauseSim();
}//GEN-LAST:event_simMenuPauseActionPerformed
@ -609,6 +613,23 @@ startSim();
stopSim();
}//GEN-LAST:event_simMenuStopActionPerformed
private void accelSpinnerStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_accelSpinnerStateChanged
Double val = (Double)this.accelSpinner.getValue();
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
/**
* @param args the command line arguments
* @throws java.lang.IllegalAccessException
@ -667,7 +688,7 @@ startSim();
private javax.swing.JMenuItem aboutMenuItem;
private javax.swing.JSpinner accelSpinner;
private chart.Chart chart;
private gui.Clock clock1;
private gui.Clock clock;
private javax.swing.JMenuItem contentMenuItem;
private javax.swing.JMenuItem deleteMenuItem;
private javax.swing.JMenuItem editExchangeMenuItem;
@ -676,14 +697,13 @@ startSim();
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenu helpMenu;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jChartScrollPane;
private javax.swing.JComboBox<String> jComboBox1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel2;
private javax.swing.JButton jRunButton;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
@ -692,12 +712,14 @@ startSim();
private javax.swing.JMenuItem openMenuItem;
private gui.OrderBookPanel orderBookPanel;
private javax.swing.JMenuItem pasteMenuItem;
private javax.swing.JButton runButton;
private javax.swing.JMenuItem saveAsMenuItem;
private javax.swing.JMenuItem saveMenuItem;
private javax.swing.JMenu simMenu;
private javax.swing.JMenuItem simMenuPause;
private javax.swing.JMenuItem simMenuStart;
private javax.swing.JMenuItem simMenuStop;
private javax.swing.JButton stopButton;
private javax.swing.JMenuItem viewClock;
private javax.swing.JMenu viewMenu;
// End of variables declaration//GEN-END:variables

View File

@ -35,6 +35,12 @@
<SubComponents>
<Component class="javax.swing.JTable" name="orderBookList">
<Properties>
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.MatteColorBorderInfo">
<MatteColorBorder/>
</Border>
</Property>
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
<Table columnCount="3" rowCount="30">
<Column editable="false" title="id" type="java.lang.Object">
@ -73,8 +79,8 @@
<Column editable="false" title="Title 3" type="java.lang.Object"/>
</Table>
</Property>
<Property name="doubleBuffered" type="boolean" value="true"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>

View File

@ -51,21 +51,23 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
abstract ArrayList <Order> getOrderBook();
private Color hdr_color = Color.LIGHT_GRAY;
// private Color hdr_color = Color.LIGHT_GRAY;
private class OrderBookCellRenderer extends DefaultTableCellRenderer {
@Override
/* @Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus,
int row, int column) {
DefaultTableCellRenderer renderer
= (DefaultTableCellRenderer) super.getTableCellRendererComponent(
table, value, isSelected, hasFocus, row, column);
renderer.setBackground(hdr_color);
// renderer.setBackground(hdr_color);
return renderer;
}
*/
}
@Override
public void UpdateOrderBook() {
@ -169,7 +171,11 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
// Formatter f = new Formatter();
switch (c) {
case 0:
return String.format("#%06x", o.getID());
// o.getAccount().getID();
return o.getAccount().getOwner().getName();
//return String.format("#%06x", o.getID());
case 1:
//return String.format("%.f",o.getLimit());
@ -196,8 +202,8 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
//System.out.print("init Orderbook]\n");
initComponents();
this.setBorder(BorderFactory.createEmptyBorder());
this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
// this.setBorder(BorderFactory.createEmptyBorder());
// this.orderBookScroller.setBorder(BorderFactory.createBevelBorder(0));
if (Globals.se == null) {
return;
@ -206,12 +212,12 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
this.model = new OrderBookListModel();
this.orderBookList.setModel(model);
orderBookList.setBorder(BorderFactory.createEmptyBorder());
// orderBookList.setBorder(BorderFactory.createEmptyBorder());
JTableHeader h = this.orderBookList.getTableHeader();
h.setBackground(hdr_color);
h.setForeground(Color.green);
h.setDefaultRenderer(new OrderBookCellRenderer());
// h.setBackground(hdr_color);
// h.setForeground(Color.green);
// h.setDefaultRenderer(new OrderBookCellRenderer());
}
@ -227,6 +233,8 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
orderBookScroller = new javax.swing.JScrollPane();
orderBookList = new javax.swing.JTable();
orderBookList.setAutoCreateRowSorter(true);
orderBookList.setBorder(new javax.swing.border.MatteBorder(null));
orderBookList.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{"1", null, null},
@ -272,8 +280,8 @@ public abstract class OrderBook extends javax.swing.JPanel implements Exchange.B
return canEdit [columnIndex];
}
});
orderBookList.setDoubleBuffered(true);
orderBookList.setFocusable(false);
orderBookList.setOpaque(false);
orderBookScroller.setViewportView(orderBookList);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

View File

@ -25,6 +25,8 @@
*/
package sesim;
import sesim.Exchange.Account;
/**
*
* @author 7u83
@ -39,6 +41,10 @@ public abstract class AutoTrader implements Scheduler.TimerTask {
public AutoTrader(Exchange se, long id, String name, double money, double shares, AutoTraderConfig config) {
account_id = se.createAccount(money, shares);
Account a = se.getAccount(account_id);
a.owner=this;
this.se = se;
this.config = config;
this.name = name;

View File

@ -68,6 +68,7 @@ public class Exchange {
private final double id;
private double shares;
private double money;
protected AutoTrader owner;
private final HashMap<Long, Order> orders;
@ -95,6 +96,10 @@ public class Exchange {
public double getMoney() {
return money;
}
public AutoTrader getOwner(){
return owner;
}
}

View File

@ -110,7 +110,7 @@ public class Scheduler extends Thread {
long diff = System.currentTimeMillis() - last_time_millis;
// diff = 12199999L;
// diff = 12199999L;
last_time_millis += diff;
if (pause) {
@ -215,7 +215,7 @@ public class Scheduler extends Thread {
} else {
return 0;
//return (t - currentTimeMillis1())/(long)this.multiplier;
//return (t - currentTimeMillis())/(long)this.acceleration;
}
}

View File

@ -157,8 +157,12 @@ public class RandomTrader extends AutoTrader {
return n;
}
public long doBuy() {
RandomTraderConfig myconfig = (RandomTraderConfig) this.config;
AccountData ad = this.se.getAccountData(account_id);
@ -171,26 +175,44 @@ public class RandomTrader extends AutoTrader {
}
//System.out.printf("%s: calling rand for money\n", this.getName());
// how much money we ant to envest?
// how much money we ant to invest?
double money = getRandomAmmount(ad.money, myconfig.buy_volume);
Quote q = se.getCurrentPrice();
double lp = q == null ? getStart() : q.price;
double limit;
limit = lp + getRandomAmmount(lp, myconfig.buy_limit);
// 10
// 24 13
// System.out.printf("MyLimit: %f\n",limit);
long volume = (long) (money / (limit * 1));
long volume = (long) (money / limit);
if (volume <= 0) {
return 0;
volume=1;
limit = money;
}
// double volume = (money / (limit * 1));
if (volume <= 0) {
return 0;
}
// if (volume <= 0) {
// return 0;
// }
//System.out.printf("%s: create order %s %f\n", this.getName(),type.toString(),limit);
@ -220,7 +242,7 @@ public class RandomTrader extends AutoTrader {
// long volume = (long) (money / (limit * 1));
if (volume <= 0) {
// System.out.print("SellVolume 0\n");
return 0;
return 5000;
}
// System.out.print("Volume is:"+volume+"\n");