Improvements on EventListener Event ...
This commit is contained in:
@ -37,6 +37,7 @@ import java.io.File;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Scanner;
|
||||
import java.util.Set;
|
||||
import javax.swing.JDialog;
|
||||
@ -64,6 +65,7 @@ import opensesim.world.Order;
|
||||
import opensesim.world.Trader;
|
||||
import opensesim.world.TradingAPI;
|
||||
import opensesim.world.World;
|
||||
import opensesim.world.scheduler.FiringEvent;
|
||||
|
||||
import opensesim.world.scheduler.EventListener;
|
||||
|
||||
@ -616,7 +618,7 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
|
||||
for (Order o: ob){
|
||||
double v = o.getVolume();
|
||||
System.out.printf("Volume: %d\n",o.getVolume());
|
||||
System.out.printf("Volume: %f\n",o.getVolume());
|
||||
}
|
||||
|
||||
|
||||
@ -907,10 +909,29 @@ public class SeSimApplication extends javax.swing.JFrame {
|
||||
stopSim();
|
||||
}//GEN-LAST:event_stopButtonActionPerformed
|
||||
|
||||
public class GodWorldEvent extends FiringEvent{
|
||||
public GodWorld goworld;
|
||||
public GodWorldEvent(EventListener listener) {
|
||||
super(listener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
HashSet <EventListener> gwlisteners = new HashSet<>();
|
||||
|
||||
void updateGodWorld(GodWorld godworld){
|
||||
GodWorldEvent e = new GodWorldEvent(null);
|
||||
for (EventListener el : gwlisteners){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void jCheckBoxMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxMenuItem1ActionPerformed
|
||||
// JDialog jd = new opensesim.gui.orderbook.OrderBookDialog(this, false);
|
||||
// jd.setVisible(rootPaneCheckingEnabled);
|
||||
opensesim.gui.orderbook.OrderBookDialog.runDialog(this, godworld);
|
||||
EventListener e = opensesim.gui.orderbook.OrderBookDialog.runDialog(this, godworld);
|
||||
gwlisteners.add(e);
|
||||
|
||||
|
||||
}//GEN-LAST:event_jCheckBoxMenuItem1ActionPerformed
|
||||
|
||||
|
@ -23,9 +23,9 @@
|
||||
<Layout>
|
||||
<DimensionLayout dim="0">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="orderBookPanel1" pref="418" max="32767" attributes="0"/>
|
||||
<Component id="orderBookPanel1" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
@ -34,17 +34,14 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="orderBookPanel1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="orderBookPanel1" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
</Layout>
|
||||
<SubComponents>
|
||||
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="orderBookPanel1">
|
||||
<AuxValues>
|
||||
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new opensesim.gui.orderbook.OrderBookPanel(godworld)"/>
|
||||
</AuxValues>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Form>
|
||||
|
@ -26,14 +26,16 @@
|
||||
package opensesim.gui.orderbook;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
import opensesim.world.GodWorld;
|
||||
import opensesim.world.scheduler.Event;
|
||||
import opensesim.world.scheduler.FiringEvent;
|
||||
import opensesim.world.scheduler.EventListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author 7u83 <7u83@mail.ru>
|
||||
*/
|
||||
public class OrderBookDialog extends javax.swing.JDialog {
|
||||
public class OrderBookDialog extends javax.swing.JDialog implements EventListener{
|
||||
|
||||
/**
|
||||
* Creates new form OrderBookDialog
|
||||
@ -47,13 +49,13 @@ public class OrderBookDialog extends javax.swing.JDialog {
|
||||
GodWorld godworld;
|
||||
|
||||
|
||||
static public void runDialog(Frame parent, GodWorld godworld){
|
||||
static public EventListener runDialog(Frame parent, GodWorld godworld){
|
||||
OrderBookDialog d = new OrderBookDialog(parent,false);
|
||||
d.godworld=godworld;
|
||||
d.setVisible(true);
|
||||
// d.dispose();
|
||||
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -65,7 +67,7 @@ public class OrderBookDialog extends javax.swing.JDialog {
|
||||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
orderBookPanel1 = new opensesim.gui.orderbook.OrderBookPanel(godworld);
|
||||
orderBookPanel1 = new opensesim.gui.orderbook.OrderBookPanel();
|
||||
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
@ -73,17 +75,17 @@ public class OrderBookDialog extends javax.swing.JDialog {
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE)
|
||||
.addComponent(orderBookPanel1, 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(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
@ -134,4 +136,10 @@ public class OrderBookDialog extends javax.swing.JDialog {
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private opensesim.gui.orderbook.OrderBookPanel orderBookPanel1;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
@Override
|
||||
public long receive(Event task) {
|
||||
this.orderBookPanel1.setGodWorld(godworld);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ import opensesim.gui.Globals;
|
||||
import opensesim.gui.util.NummericCellRenderer;
|
||||
import java.awt.Component;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
@ -39,12 +38,14 @@ import javax.swing.table.DefaultTableCellRenderer;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
import opensesim.world.AssetPair;
|
||||
import opensesim.world.Exchange;
|
||||
import opensesim.world.GodWorld;
|
||||
import opensesim.world.Order;
|
||||
|
||||
|
||||
import opensesim.world.TradingAPI;
|
||||
import opensesim.world.scheduler.Event;
|
||||
import opensesim.world.scheduler.FiringEvent;
|
||||
import opensesim.world.scheduler.EventListener;
|
||||
|
||||
/**
|
||||
@ -55,12 +56,14 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
|
||||
|
||||
DefaultTableModel model;
|
||||
TableColumn trader_column = null;
|
||||
|
||||
TradingAPI api=null;
|
||||
|
||||
TradingAPI api = null;
|
||||
|
||||
@Override
|
||||
public long receive(Event task) {
|
||||
synchronized (this) {
|
||||
System.out.printf("There is an o event \n");
|
||||
|
||||
synchronized (this) {
|
||||
if (oupdate) {
|
||||
new_oupdate = true;
|
||||
return 0;
|
||||
@ -120,35 +123,59 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
|
||||
/**
|
||||
* Bla
|
||||
*/
|
||||
/* @Override
|
||||
/* @Override
|
||||
public final void cfgChanged() {
|
||||
boolean gm = Globals.prefs.get(Globals.CfgStrings.GODMODE, "false").equals("true");
|
||||
setGodMode(gm);
|
||||
list.invalidate();
|
||||
list.repaint();
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
/*
|
||||
/*
|
||||
public void setType(OrderType type) {
|
||||
this.type = type;
|
||||
Globals.se.addBookReceiver(type, this);
|
||||
}
|
||||
*/
|
||||
|
||||
*/
|
||||
public OrderBookPanel() {
|
||||
initComponents();
|
||||
}
|
||||
|
||||
GodWorld godworld;
|
||||
|
||||
public void setGodWorld(GodWorld godworld) {
|
||||
// is our world alread the godworld to set?
|
||||
if (this.godworld == godworld) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.godworld = godworld;
|
||||
Exchange ex = godworld.getDefaultExchange();
|
||||
AssetPair ap = godworld.getDefaultAssetPair();
|
||||
api = ex.getAPI(ap);
|
||||
api.addOrderBookListener(this);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new form OrderBookNew
|
||||
*/
|
||||
public OrderBookPanel(GodWorld godworld) {
|
||||
|
||||
initComponents();
|
||||
|
||||
if (Globals.world == null) {
|
||||
return;
|
||||
// return;
|
||||
}
|
||||
|
||||
|
||||
this.godworld = godworld;
|
||||
|
||||
|
||||
Exchange ex = godworld.getDefaultExchange();
|
||||
AssetPair ap = godworld.getDefaultAssetPair();
|
||||
api = ex.getAPI(ap);
|
||||
api.addOrderBookListener(this);
|
||||
|
||||
model = (DefaultTableModel) this.list.getModel();
|
||||
trader_column = list.getColumnModel().getColumn(0);
|
||||
list.getColumnModel().getColumn(1).setCellRenderer(new NummericCellRenderer(3));
|
||||
@ -156,15 +183,15 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
|
||||
// cfgChanged();
|
||||
// Globals.se.addBookReceiver(Exchange.OrderType.BUYLIMIT, this);
|
||||
// Globals.addCfgListener(this);
|
||||
|
||||
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
// System.out.printf("Update order book\n");
|
||||
// UpdateOrderBook();
|
||||
// System.out.printf("Update order book\n");
|
||||
// UpdateOrderBook();
|
||||
}
|
||||
}, 1000, 1000);
|
||||
|
||||
|
||||
}
|
||||
|
||||
boolean oupdate = false;
|
||||
@ -175,7 +202,7 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
|
||||
void oupdater() {
|
||||
// ArrayList<Order> ob = Globals.se.getOrderBook(type, depth);
|
||||
|
||||
Collection <Order> ob = api.getOrderBook(Order.Type.BUY);
|
||||
Collection<Order> ob = api.getOrderBook(Order.Type.BUY);
|
||||
|
||||
model.setRowCount(ob.size());
|
||||
int row = 0;
|
||||
|
Reference in New Issue
Block a user