Orderbook updates are synchronized now.
No "Out of Index Exeptions" aynmore
This commit is contained in:
parent
6719f9a7f5
commit
0603bbc0d3
@ -28,6 +28,7 @@ package gui.orderbook;
|
||||
import gui.Globals;
|
||||
import gui.Globals.CfgListener;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import javax.swing.table.TableColumn;
|
||||
import javax.swing.table.TableColumnModel;
|
||||
@ -45,20 +46,19 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
TableColumn trader_column = null;
|
||||
|
||||
OrderType type = OrderType.BUYLIMIT;
|
||||
int depth=40;
|
||||
int depth = 40;
|
||||
|
||||
public void setGodMode(boolean on) {
|
||||
TableColumnModel tcm = list.getColumnModel();
|
||||
if (on){
|
||||
if (list.getColumnCount()==3){
|
||||
if (on) {
|
||||
if (list.getColumnCount() == 3) {
|
||||
return;
|
||||
}
|
||||
tcm.addColumn(trader_column);
|
||||
tcm.moveColumn(2, 0);
|
||||
return;
|
||||
}
|
||||
else{
|
||||
if (list.getColumnCount()==2){
|
||||
} else {
|
||||
if (list.getColumnCount() == 2) {
|
||||
return;
|
||||
}
|
||||
tcm.removeColumn(tcm.getColumn(0));
|
||||
@ -71,14 +71,14 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
@Override
|
||||
public final void cfgChanged() {
|
||||
boolean gm = Globals.prefs.get(Globals.CfgStrings.GODMODE, "false").equals("true");
|
||||
System.out.printf("GM %s\n",gm?"true":"false");
|
||||
System.out.printf("GM %s\n", gm ? "true" : "false");
|
||||
setGodMode(gm);
|
||||
list.invalidate();
|
||||
list.repaint();
|
||||
}
|
||||
|
||||
public void setType(OrderType type){
|
||||
this.type=type;
|
||||
public void setType(OrderType type) {
|
||||
this.type = type;
|
||||
Globals.se.addBookReceiver(type, this);
|
||||
}
|
||||
|
||||
@ -87,8 +87,9 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
*/
|
||||
public OrderBook() {
|
||||
initComponents();
|
||||
if (Globals.se==null)
|
||||
if (Globals.se == null) {
|
||||
return;
|
||||
}
|
||||
model = (DefaultTableModel) this.list.getModel();
|
||||
trader_column = list.getColumnModel().getColumn(0);
|
||||
cfgChanged();
|
||||
@ -96,8 +97,17 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
Globals.addCfgListener(this);
|
||||
}
|
||||
|
||||
boolean oupdate = false;
|
||||
|
||||
@Override
|
||||
public void UpdateOrderBook() {
|
||||
public synchronized void UpdateOrderBook() {
|
||||
|
||||
if (oupdate) {
|
||||
return;
|
||||
}
|
||||
oupdate = true;
|
||||
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
ArrayList<Order> ob = Globals.se.getOrderBook(type, depth);
|
||||
model.setRowCount(ob.size());
|
||||
int row = 0;
|
||||
@ -108,6 +118,19 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
row++;
|
||||
}
|
||||
|
||||
oupdate = false;
|
||||
});
|
||||
|
||||
/* ArrayList<Order> ob = Globals.se.getOrderBook(type, depth);
|
||||
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++;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
@ -168,5 +191,4 @@ public class OrderBook extends javax.swing.JPanel implements Exchange.BookReceiv
|
||||
private javax.swing.JTable list;
|
||||
// End of variables declaration//GEN-END:variables
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user