Exchange list and exchange creation works

This commit is contained in:
7u83 2018-12-02 21:38:17 +01:00
parent 7a707cd10c
commit 6a964bcb5e
7 changed files with 83 additions and 44 deletions

View File

@ -110,6 +110,7 @@ public class Globals {
public static final String STRATEGIES = "strategies"; public static final String STRATEGIES = "strategies";
public static final String TRADERS = "traders"; public static final String TRADERS = "traders";
public static final String ASSETS = "assets"; public static final String ASSETS = "assets";
public static final String EXCHANGES = "exchanges";
} }
@ -345,6 +346,13 @@ public class Globals {
prefs.put(PrefKeys.ASSETS, assets.toString()); prefs.put(PrefKeys.ASSETS, assets.toString());
} }
static public final JSONObject getExchanges(){
String json = prefs.get(PrefKeys.EXCHANGES, "{}");
return new JSONObject(json);
}
static public final void putExchanges(JSONObject e){
prefs.put(PrefKeys.EXCHANGES, e.toString());
}
static public final JSONArray getTraders() { static public final JSONArray getTraders() {

View File

@ -30,8 +30,11 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.swing.JDialog; import javax.swing.JDialog;
import javax.swing.JFrame; import javax.swing.JFrame;
import opensesim.gui.Globals;
import opensesim.gui.util.EscDialog; import opensesim.gui.util.EscDialog;
import opensesim.gui.util.Json;
import opensesim.util.SeSimException; import opensesim.util.SeSimException;
import org.json.JSONObject;
/** /**
* *
@ -47,11 +50,17 @@ public class ExchangeEditorDialog extends EscDialog {
initComponents(); initComponents();
} }
public static void runDialog(Dialog parent) { public static void runDialog(Dialog parent, JSONObject e) {
ExchangeEditorDialog dialog = new ExchangeEditorDialog(parent, true); ExchangeEditorDialog dialog = new ExchangeEditorDialog(parent, true);
dialog.setLocationRelativeTo(parent); dialog.setLocationRelativeTo(parent);
dialog.setVisible(true); dialog.setVisible(true);
JSONObject r = Json.get(dialog.exchangeEditorPanel1);
JSONObject ex = Globals.getExchanges();
ex.put(r.getString("symbol"), r);
Globals.putExchanges(ex);
/*
try { try {
dialog.exchangeEditorPanel1.saveData(); dialog.exchangeEditorPanel1.saveData();
} catch (SeSimException ex) { } catch (SeSimException ex) {
@ -60,7 +69,8 @@ public class ExchangeEditorDialog extends EscDialog {
javax.swing.JOptionPane.ERROR_MESSAGE); javax.swing.JOptionPane.ERROR_MESSAGE);
} }
dialog.dispose(); dialog.dispose();
*/
} }
/** /**

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo"> <Form version="1.4" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues> <AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
@ -24,9 +24,10 @@
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="nameField" pref="214" max="32767" attributes="0"/> <Component id="symField" pref="202" max="32767" attributes="0"/>
<Component id="symField" max="32767" attributes="0"/> <Component id="nameField" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
@ -56,7 +57,9 @@
</Component> </Component>
<Component class="opensesim.gui.util.JTextFieldLimit" name="symField"> <Component class="opensesim.gui.util.JTextFieldLimit" name="symField">
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodePost" type="java.lang.String" value="symField.setLimit(10);&#xa;"/> <AuxValue name="JavaCodeGenerator_CreateCodePost" type="java.lang.String" value="symField.setLimit(10);"/>
<AuxValue name="JavaCodeGenerator_DeclarationPre" type="java.lang.String" value="@Export(&quot;symbol&quot;)&#xa;@Import(&quot;name&quot;)"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues> </AuxValues>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel2"> <Component class="javax.swing.JLabel" name="jLabel2">
@ -65,6 +68,10 @@
</Properties> </Properties>
</Component> </Component>
<Component class="javax.swing.JTextField" name="nameField"> <Component class="javax.swing.JTextField" name="nameField">
<AuxValues>
<AuxValue name="JavaCodeGenerator_DeclarationPre" type="java.lang.String" value="@Import(&quot;name&quot;)&#xa;@Export(&quot;name&quot;)"/>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="1"/>
</AuxValues>
</Component> </Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -28,6 +28,8 @@ package opensesim.gui.exchangeeditor;
import opensesim.Exchange; import opensesim.Exchange;
import opensesim.World; import opensesim.World;
import opensesim.gui.Globals; import opensesim.gui.Globals;
import opensesim.gui.util.Json.Export;
import opensesim.gui.util.Json.Import;
import opensesim.util.SeSimException; import opensesim.util.SeSimException;
/** /**
@ -80,8 +82,9 @@ public class ExchangeEditorPanel extends javax.swing.JPanel {
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(nameField, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE) .addComponent(symField, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
.addComponent(symField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addComponent(nameField))
.addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -102,7 +105,11 @@ public class ExchangeEditorPanel extends javax.swing.JPanel {
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel2;
private javax.swing.JTextField nameField; @Import("name")
private opensesim.gui.util.JTextFieldLimit symField; @Export("name")
public javax.swing.JTextField nameField;
@Export("symbol")
@Import("name")
public opensesim.gui.util.JTextFieldLimit symField;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@ -3,6 +3,7 @@
<Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> <Form version="1.3" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JDialogFormInfo">
<Properties> <Properties>
<Property name="defaultCloseOperation" type="int" value="2"/> <Property name="defaultCloseOperation" type="int" value="2"/>
<Property name="title" type="java.lang.String" value="Exchanges"/>
</Properties> </Properties>
<SyntheticProperties> <SyntheticProperties>
<SyntheticProperty name="formSizePolicy" type="int" value="1"/> <SyntheticProperty name="formSizePolicy" type="int" value="1"/>
@ -23,16 +24,16 @@
<Layout> <Layout>
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Component id="exchangeListPanel" max="32767" attributes="0"/>
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/> <Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/> <Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Component id="exchangeListPanel1" pref="388" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@ -40,22 +41,20 @@
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="exchangeListPanel1" pref="199" max="32767" attributes="0"/> <Component id="exchangeListPanel" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="jButton2" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
</Layout> </Layout>
<SubComponents> <SubComponents>
<Component class="opensesim.gui.exchangeeditor.ExchangeListPanel" name="exchangeListPanel1">
</Component>
<Component class="javax.swing.JButton" name="jButton1"> <Component class="javax.swing.JButton" name="jButton1">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="Done"/> <Property name="text" type="java.lang.String" value="Done"/>
@ -69,5 +68,7 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="opensesim.gui.exchangeeditor.ExchangeListPanel" name="exchangeListPanel">
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@ -27,15 +27,13 @@ package opensesim.gui.exchangeeditor;
import java.awt.Dialog; import java.awt.Dialog;
import java.awt.Window; import java.awt.Window;
import javax.swing.JFrame;
import opensesim.gui.util.EscDialog; import opensesim.gui.util.EscDialog;
import opensesim.util.SeSimException;
/** /**
* *
* @author 7u83 <7u83@mail.ru> * @author 7u83 <7u83@mail.ru>
*/ */
public class ExchangeListDialog extends EscDialog { public class ExchangeListDialog extends EscDialog {
/** /**
* Creates new form ExchangeListDialog * Creates new form ExchangeListDialog
@ -45,21 +43,22 @@ public class ExchangeListDialog extends EscDialog {
initComponents(); initComponents();
} }
public static void runDialog(Window parent) { public static void runDialog(Window parent) {
ExchangeListDialog dialog = new ExchangeListDialog(parent, true); ExchangeListDialog dialog = new ExchangeListDialog(parent, true);
dialog.setLocationRelativeTo(parent); dialog.setLocationRelativeTo(parent);
dialog.setVisible(true); dialog.setVisible(true);
/* try { /* try {
dialog.exchangeListPanel1. dialog.exchangeListPanel1.
} catch (SeSimException ex) { } catch (SeSimException ex) {
javax.swing.JOptionPane.showMessageDialog(parent, ex.getMessage(), javax.swing.JOptionPane.showMessageDialog(parent, ex.getMessage(),
"Error Hello", "Error Hello",
javax.swing.JOptionPane.ERROR_MESSAGE); javax.swing.JOptionPane.ERROR_MESSAGE);
} }
*/ dialog.dispose(); */ dialog.dispose();
} }
/** /**
* This method is called from within the constructor to initialize the form. * 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 * WARNING: Do NOT modify this code. The content of this method is always
@ -69,11 +68,12 @@ public class ExchangeListDialog extends EscDialog {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() { private void initComponents() {
exchangeListPanel1 = new opensesim.gui.exchangeeditor.ExchangeListPanel();
jButton1 = new javax.swing.JButton(); jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton();
exchangeListPanel = new opensesim.gui.exchangeeditor.ExchangeListPanel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Exchanges");
jButton1.setText("Done"); jButton1.setText("Done");
@ -88,27 +88,27 @@ public class ExchangeListDialog extends EscDialog {
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(exchangeListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE) .addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2) .addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)) .addComponent(jButton1)))
.addComponent(exchangeListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addContainerGap() .addContainerGap()
.addComponent(exchangeListPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE) .addComponent(exchangeListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1) .addComponent(jButton1)
.addComponent(jButton2)) .addComponent(jButton2))
.addContainerGap()) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
); );
pack(); pack();
@ -116,7 +116,8 @@ public class ExchangeListDialog extends EscDialog {
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Dialog d = this; Dialog d = this;
ExchangeEditorDialog.runDialog(d); ExchangeEditorDialog.runDialog(d,null);
this.exchangeListPanel.reload();
}//GEN-LAST:event_jButton2ActionPerformed }//GEN-LAST:event_jButton2ActionPerformed
/** /**
@ -147,7 +148,7 @@ public class ExchangeListDialog extends EscDialog {
//</editor-fold> //</editor-fold>
/* Create and display the dialog */ /* Create and display the dialog */
/* java.awt.EventQueue.invokeLater(new Runnable() { /* java.awt.EventQueue.invokeLater(new Runnable() {
public void run() { public void run() {
ExchangeListDialog dialog = new ExchangeListDialog(new javax.swing.JFrame(), true); ExchangeListDialog dialog = new ExchangeListDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() { dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@ -162,7 +163,7 @@ public class ExchangeListDialog extends EscDialog {
} }
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private opensesim.gui.exchangeeditor.ExchangeListPanel exchangeListPanel1; private opensesim.gui.exchangeeditor.ExchangeListPanel exchangeListPanel;
private javax.swing.JButton jButton1; private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2; private javax.swing.JButton jButton2;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables

View File

@ -30,6 +30,7 @@ import javax.swing.table.TableModel;
import opensesim.World; import opensesim.World;
import opensesim.gui.Globals; import opensesim.gui.Globals;
import opensesim.Exchange; import opensesim.Exchange;
import org.json.JSONObject;
/** /**
* *
@ -37,34 +38,38 @@ import opensesim.Exchange;
*/ */
public class ExchangeListPanel extends javax.swing.JPanel { public class ExchangeListPanel extends javax.swing.JPanel {
World world;
/** /**
* Creates new form ExchangeList * Creates new form ExchangeList
*/ */
public ExchangeListPanel() { public ExchangeListPanel() {
world = Globals.world;
initComponents(); initComponents();
if (Globals.prefs==null)
return;
reload(); reload();
} }
final void reload() { final void reload() {
DefaultTableModel m = (DefaultTableModel) exchangeTable.getModel(); DefaultTableModel m = (DefaultTableModel) exchangeTable.getModel();
if (world == null) { JSONObject jex = Globals.getExchanges();
return;
}
m.setRowCount(0); m.setRowCount(0);
for (Exchange e : world.getExchangeCollection()) { for (String esym : jex.keySet()) {
JSONObject e = jex.getJSONObject(esym);
m.addRow(new Object[]{ m.addRow(new Object[]{
e.getString("symbol"),
e.getSymbol(), e.getString("name")
e.getName()
}); });
} }
} }
private TableModel getModel() { private TableModel getModel() {