Refactoring

This commit is contained in:
7u83
2018-12-28 13:06:15 +01:00
parent c9721ac5f5
commit 370af3cf9e
27 changed files with 509 additions and 712 deletions

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2018, tohe
* 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 opensesim.gui;
/**
*
* @author tohe
*/
public interface AdmInterface {
}

View File

@ -48,6 +48,7 @@ import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;
import opensesim.gui.AssetPairEditor.NewJDialog;
import static opensesim.gui.Globals.getWorld;
import opensesim.gui.account.AccountDialog;
import opensesim.gui.exchangeeditor.ExchangeListDialog;
import org.json.JSONArray;
@ -65,10 +66,9 @@ import opensesim.world.Order;
import opensesim.world.Trader;
import opensesim.world.TradingAPI;
import opensesim.world.World;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.FiringEvent;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.FiringEvent;
import opensesim.util.scheduler.EventListener;
/**
*
@ -605,6 +605,8 @@ public class SeSimApplication extends javax.swing.JFrame {
+ "}");
Trader t = godworld.createTrader(cfg);
t.start();
AccountDialog.runDialog(this, t.getAccount());
updateGodWorld(godworld);
@ -614,7 +616,7 @@ public class SeSimApplication extends javax.swing.JFrame {
TradingAPI api = ex.getAPI(p);
opensesim.world.scheduler.Scheduler s = godworld.getScheduler();
opensesim.util.scheduler.Scheduler s = godworld.getScheduler();
class MyListener implements EventListener {
@ -625,7 +627,7 @@ public class SeSimApplication extends javax.swing.JFrame {
}
@Override
public long receive(opensesim.world.scheduler.Event task) {
public long receive(opensesim.util.scheduler.Event task) {
System.out.printf("Received an Event %d\n", Thread.currentThread().getId());
// e.count++;
@ -972,7 +974,7 @@ public class SeSimApplication extends javax.swing.JFrame {
private void clearMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearMenuItemActionPerformed
int dialogResult = JOptionPane.showConfirmDialog(this, "Are you sure?", "Warning", JOptionPane.YES_NO_OPTION);
int dialogResult = JOptionPane.showConfirmDialog(this, "Are you sure you want to clear all data?", "Warning", JOptionPane.YES_NO_OPTION);
if (dialogResult != JOptionPane.YES_OPTION) {
return;
}

View File

@ -23,9 +23,11 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" max="32767" attributes="0"/>
<Component id="bidbook" min="-2" pref="293" max="-2" attributes="0"/>
<EmptySpace pref="91" max="32767" attributes="0"/>
<Component id="askbook" min="-2" pref="315" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -34,14 +36,19 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="orderBookPanel1" max="32767" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="bidbook" pref="326" max="32767" attributes="0"/>
<Component id="askbook" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="orderBookPanel1">
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="bidbook">
</Component>
<Component class="opensesim.gui.orderbook.OrderBookPanel" name="askbook">
</Component>
</SubComponents>
</Form>

View File

@ -30,8 +30,9 @@ import java.awt.Frame;
import opensesim.world.AssetPair;
import opensesim.world.Exchange;
import opensesim.world.GodWorld;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener;
import opensesim.world.Order;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
/**
*
@ -52,7 +53,11 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
void init(){
this.setTitle(asset_pair.getSymbol()+" on "+ex.getSymbol());
this.orderBookPanel1.init(godworld, ex, asset_pair);
this.bidbook.type=Order.Type.BUYLIMIT;
this.bidbook.init(godworld, ex, asset_pair);
this.askbook.type=Order.Type.SELLLIMIT;
this.askbook.init(godworld, ex, asset_pair);
}
AssetPair asset_pair;
@ -83,7 +88,8 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
orderBookPanel1 = new opensesim.gui.orderbook.OrderBookPanel();
bidbook = new opensesim.gui.orderbook.OrderBookPanel();
askbook = new opensesim.gui.orderbook.OrderBookPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
@ -91,16 +97,20 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(bidbook, javax.swing.GroupLayout.PREFERRED_SIZE, 293, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addComponent(askbook, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(bidbook, javax.swing.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
.addComponent(askbook, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
@ -150,7 +160,8 @@ public class OrderBookDialog extends javax.swing.JDialog implements EventListene
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private opensesim.gui.orderbook.OrderBookPanel orderBookPanel1;
private opensesim.gui.orderbook.OrderBookPanel askbook;
private opensesim.gui.orderbook.OrderBookPanel bidbook;
// End of variables declaration//GEN-END:variables
@Override

View File

@ -28,6 +28,7 @@ package opensesim.gui.orderbook;
import opensesim.gui.Globals;
import opensesim.gui.util.NummericCellRenderer;
import java.util.Collection;
import java.util.Iterator;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.SwingUtilities;
@ -40,10 +41,11 @@ import opensesim.world.GodWorld;
import opensesim.world.Order;
import opensesim.world.TradingAPI;
import opensesim.world.scheduler.Event;
import opensesim.world.scheduler.EventListener;
import opensesim.util.scheduler.Event;
import opensesim.util.scheduler.EventListener;
/**
* Displays an orderbook
*
* @author 7u83 <7u83@mail.ru>
*/
@ -57,8 +59,6 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
@Override
public long receive(Event task) {
System.out.printf("There is an o event \n");
synchronized (this) {
if (oupdate) {
new_oupdate = true;
@ -109,6 +109,7 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
}
public void init(GodWorld godworld, Exchange ex, AssetPair pair) {
api = ex.getAPI(pair);
api.addOrderBookListener(this);
@ -116,7 +117,7 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
trader_column = list.getColumnModel().getColumn(0);
list.getColumnModel().getColumn(1).setCellRenderer(new NummericCellRenderer(api.getAssetPair().getCurrency().getDecimals()));
list.getColumnModel().getColumn(2).setCellRenderer(new NummericCellRenderer(api.getAssetPair().getAsset().getDecimals()));
this.setGodMode(true);
this.oupdater();
}
@ -144,17 +145,45 @@ public class OrderBookPanel extends javax.swing.JPanel implements EventListener
long ouctr = 0;
Order.Type type;
void oupdater() {
Collection<Order> ob = api.getOrderBook(type);
model.setRowCount(ob.size());
private void drawBookSimple(Collection<Order> orderbook) {
model.setRowCount(orderbook.size());
int row = 0;
for (Order ob1 : ob) {
for (Order order : orderbook) {
// model.setValueAt(ob1.getAccount().getOwner().getName(), row, 0);
model.setValueAt(ob1.getLimit(), row, 1);
model.setValueAt(ob1.getVolume(), row, 2);
model.setValueAt(order.getID(), row, 0);
model.setValueAt(order.getLimit(), row, 1);
model.setValueAt(order.getVolume(), row, 2);
row++;
}
}
private void drawBookCmplex(Collection<Order> orderbook){
model.setRowCount(orderbook.size());
int row = 0;
double volume = 0.0;
double limit = 0.0;
Iterator<Order> it;
for (Order order : orderbook) {
// model.setValueAt(ob1.getAccount().getOwner().getName(), row, 0);
model.setValueAt(order.getLimit(), row, 1);
model.setValueAt(order.getVolume(), row, 2);
row++;
}
}
void oupdater() {
// get order book from API
Collection<Order> orderbook = api.getOrderBook(type);
this.drawBookSimple(orderbook);
synchronized (this) {
oupdate = new_oupdate;

View File

@ -1,43 +0,0 @@
/*
* Copyright (c) 2018, 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 opensesim.gui.util;
import javax.swing.JComboBox;
/**
*
* @author 7u83 <7u83@mail.ru>
*/
public class Misc {
public class AssetTypeComboBox extends JComboBox
{
AssetTypeComboBox(){
super();
}
}
}