Exchange edit dialog/list

Creates new exchanges
This commit is contained in:
2018-12-09 01:53:47 +01:00
parent df2c535bd4
commit 70661d6711
18 changed files with 767 additions and 127 deletions

View File

@ -62,7 +62,7 @@ import opensesim.world.GodWorld;
public class SeSimApplication extends javax.swing.JFrame {
GodWorld worldadm;
GodWorld godworld;
/**
* Creates new form NewMDIApplication
@ -76,7 +76,7 @@ public class SeSimApplication extends javax.swing.JFrame {
JSONObject cfg;
cfg = new JSONObject(Globals.prefs.get("world","{}"));
worldadm = new GodWorld(cfg);
godworld = new GodWorld(cfg);
@ -926,7 +926,7 @@ public class SeSimApplication extends javax.swing.JFrame {
opensesim.gui.AssetEditor.AssetListDialog dialog;
dialog = new opensesim.gui.AssetEditor.AssetListDialog(worldadm,this,true);
dialog = new opensesim.gui.AssetEditor.AssetListDialog(godworld,this,true);
dialog.setLocationRelativeTo(this);
dialog.setVisible(rootPaneCheckingEnabled);
dialog.dispose();
@ -941,7 +941,8 @@ public class SeSimApplication extends javax.swing.JFrame {
private void exchangesMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exchangesMenuItemActionPerformed
ExchangeListDialog.runDialog(this);
//ExchangeListDialog.runDialog(this,this.godworld);
ExchangeListDialog.runDialog(this, godworld);
}//GEN-LAST:event_exchangesMenuItemActionPerformed
public static class Pojo {

View File

@ -62,6 +62,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="Cancel"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton2ActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Form>

View File

@ -26,9 +26,13 @@
package opensesim.gui.exchangeeditor;
import java.awt.Dialog;
import java.util.logging.Level;
import java.util.logging.Logger;
import opensesim.gui.Globals;
import opensesim.gui.util.EscDialog;
import opensesim.gui.util.Json;
import opensesim.util.SeSimException;
import opensesim.world.GodWorld;
import org.json.JSONObject;
/**
@ -37,6 +41,8 @@ import org.json.JSONObject;
*/
public class ExchangeEditorDialog extends EscDialog {
private GodWorld world;
/**
* Creates new form ExchangeEditorDialog
*/
@ -45,15 +51,16 @@ public class ExchangeEditorDialog extends EscDialog {
initComponents();
}
public static void runDialog(Dialog parent, JSONObject e) {
public static void runDialog(Dialog parent, GodWorld world, JSONObject e) {
ExchangeEditorDialog dialog = new ExchangeEditorDialog(parent, true);
dialog.world=world;
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
JSONObject r = Json.get(dialog.exchangeEditorPanel1);
JSONObject ex = Globals.getExchanges();
ex.put(r.getString("symbol"), r);
Globals.putExchanges(ex);
// JSONObject r = Json.get(dialog.exchangeEditorPanel1);
// JSONObject ex = Globals.getExchanges();
// ex.put(r.getString("symbol"), r);
// Globals.putExchanges(ex);
/*
try {
@ -91,6 +98,11 @@ public class ExchangeEditorDialog extends EscDialog {
});
jButton2.setText("Cancel");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
@ -119,9 +131,20 @@ public class ExchangeEditorDialog extends EscDialog {
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
setVisible(false);
try {
if (!this.exchangeEditorPanel1.save(world))
return;
} catch (SeSimException ex) {
return;
}
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jButton2ActionPerformed
/**
* @param args the command line arguments
*/

View File

@ -28,10 +28,12 @@ package opensesim.gui.exchangeeditor;
import opensesim.world.Exchange;
import opensesim.world.RealWorld;
import opensesim.gui.Globals;
import opensesim.gui.util.Json;
import opensesim.gui.util.Json.Export;
import opensesim.gui.util.Json.Import;
import opensesim.util.SeSimException;
import opensesim.world.GodWorld;
import org.json.JSONObject;
/**
*
@ -39,18 +41,19 @@ import opensesim.world.GodWorld;
*/
public class ExchangeEditorPanel extends javax.swing.JPanel {
GodWorld world=null;
/**
* Creates new form ExchangeEditorPanel
*/
public ExchangeEditorPanel() {
//world = Globals.world;
initComponents();
}
public void saveData() throws SeSimException{
Exchange ex = world.addExchange(symField.getText());
ex.setName(nameField.getText());
public boolean save(GodWorld world) throws SeSimException{
JSONObject cfg;
cfg = Json.get(this);
world.createExchange(cfg);
return true;
}
/**

View File

@ -23,33 +23,27 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="32767" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="exchangeListPanel" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
<Component id="exchangeListPanel" alignment="1" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="exchangeListPanel" min="-2" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="exchangeListPanel" pref="257" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" 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="jButton1" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -59,6 +53,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="Done"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="jButton2">
<Properties>
@ -69,6 +66,9 @@
</Events>
</Component>
<Component class="opensesim.gui.exchangeeditor.ExchangeListPanel" name="exchangeListPanel">
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new opensesim.gui.exchangeeditor.ExchangeListPanel(world)"/>
</AuxValues>
</Component>
</SubComponents>
</Form>

View File

@ -27,7 +27,11 @@ package opensesim.gui.exchangeeditor;
import java.awt.Dialog;
import java.awt.Window;
import opensesim.gui.Globals;
import opensesim.gui.util.EscDialog;
import opensesim.world.GodWorld;
import opensesim.world.World;
import org.json.JSONObject;
/**
*
@ -35,28 +39,30 @@ import opensesim.gui.util.EscDialog;
*/
public class ExchangeListDialog extends EscDialog {
GodWorld world = null;
/**
* Creates new form ExchangeListDialog
*/
public ExchangeListDialog(Window parent, boolean modal) {
super(parent, modal);
}
public ExchangeListDialog(Window parent, GodWorld world) {
this(parent, true);
this.world = world;
initComponents();
}
public static void runDialog(Window parent) {
public static void runDialog(Window parent, GodWorld world) {
ExchangeListDialog dialog = new ExchangeListDialog(parent, true);
ExchangeListDialog dialog = new ExchangeListDialog(parent, world);
dialog.setLocationRelativeTo(parent);
dialog.setVisible(true);
/* try {
dialog.exchangeListPanel1.
} catch (SeSimException ex) {
javax.swing.JOptionPane.showMessageDialog(parent, ex.getMessage(),
"Error Hello",
javax.swing.JOptionPane.ERROR_MESSAGE);
}
*/ dialog.dispose();
dialog.world = world;
dialog.dispose();
JSONObject o = world.getJson();
Globals.prefs.put("world", o.toString());
}
/**
@ -70,12 +76,17 @@ public class ExchangeListDialog extends EscDialog {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
exchangeListPanel = new opensesim.gui.exchangeeditor.ExchangeListPanel();
exchangeListPanel = new opensesim.gui.exchangeeditor.ExchangeListPanel(world);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Exchanges");
jButton1.setText("Done");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("New ...");
jButton2.addActionListener(new java.awt.event.ActionListener() {
@ -87,28 +98,24 @@ public class ExchangeListDialog extends EscDialog {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.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()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)))
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1)
.addContainerGap())
.addComponent(exchangeListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(exchangeListPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(exchangeListPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addComponent(jButton2)
.addComponent(jButton1))
.addContainerGap())
);
pack();
@ -116,10 +123,14 @@ public class ExchangeListDialog extends EscDialog {
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
Dialog d = this;
ExchangeEditorDialog.runDialog(d,null);
ExchangeEditorDialog.runDialog(d, world, null);
this.exchangeListPanel.reload();
}//GEN-LAST:event_jButton2ActionPerformed
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/

View File

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