From e4f85ba418db4bdd6b0068c0be7914dcfcde4854 Mon Sep 17 00:00:00 2001 From: 7u83 <7u83@mail.ru> Date: Mon, 30 Jan 2017 16:52:55 +0100 Subject: [PATCH] Trader List Editor --- src/main/java/gui/EditAutoTraderList.form | 1 + src/main/java/gui/EditAutoTraderList.java | 86 ++++++++++++++----- .../java/gui/EditAutoTraderListDialog.form | 11 ++- .../java/gui/EditAutoTraderListDialog.java | 33 ++++--- src/main/java/gui/NewMDIApplication.form | 4 +- src/main/java/gui/NewMDIApplication.java | 26 +++--- src/main/java/gui/TraderListPanel.form | 1 + src/main/java/gui/TraderListPanel.java | 1 + 8 files changed, 110 insertions(+), 53 deletions(-) diff --git a/src/main/java/gui/EditAutoTraderList.form b/src/main/java/gui/EditAutoTraderList.form index cfef8bd..eabbd55 100644 --- a/src/main/java/gui/EditAutoTraderList.form +++ b/src/main/java/gui/EditAutoTraderList.form @@ -43,6 +43,7 @@ + diff --git a/src/main/java/gui/EditAutoTraderList.java b/src/main/java/gui/EditAutoTraderList.java index 68292c6..d8268dd 100644 --- a/src/main/java/gui/EditAutoTraderList.java +++ b/src/main/java/gui/EditAutoTraderList.java @@ -33,6 +33,7 @@ import java.util.logging.Logger; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; import javax.swing.table.AbstractTableModel; +import javax.swing.table.DefaultTableCellRenderer; import javax.swing.table.DefaultTableModel; import javax.swing.table.JTableHeader; import org.json.JSONArray; @@ -45,18 +46,20 @@ import sesim.AutoTraderConfig; */ public class EditAutoTraderList extends javax.swing.JPanel { + private String getColumnHeader(int i) { + JTableHeader th = list.getTableHeader(); + return (String) th.getColumnModel().getColumn(i).getHeaderValue(); + + } + void save() { DefaultTableModel model = (DefaultTableModel) list.getModel(); JTableHeader th = list.getTableHeader(); - + /* for (int i = 0; i < model.getColumnCount(); i++) { String hw = (String) th.getColumnModel().getColumn(i).getHeaderValue(); - System.out.printf("%s\t", hw); } - - System.out.println(); - - // JSONObject ja = new JSONObject(); + */ JSONArray ja = new JSONArray(); for (int i = 0; i < model.getRowCount(); i++) { @@ -66,7 +69,7 @@ public class EditAutoTraderList extends javax.swing.JPanel { if (cw != null) { jo.put((String) th.getColumnModel().getColumn(x).getHeaderValue(), cw.toString()); - } + } //ja.put(Integer.toString(i),jo); } @@ -74,8 +77,47 @@ public class EditAutoTraderList extends javax.swing.JPanel { } Globals.prefs.put("Traders", ja.toString()); - - // System.out.printf("Arlist: %s\n", ja.toString()); + + // System.out.printf("Arlist: %s\n", ja.toString()); + } + + final void load() { + String traders_json = Globals.prefs.get("Traders", "[]"); + JSONArray traders = new JSONArray(traders_json); + + int size = traders.toList().size(); + System.out.printf("Size = %d\n", size); + + for (int row = 0; row < size; row++) { + JSONObject rowobj = traders.getJSONObject(row); + for (int col = 0; col < list.getColumnCount(); col++) { + String h = this.getColumnHeader(col); + System.out.printf("Doing stuff for %s\n", h); + String val = rowobj.getString(h); + System.out.printf("Want to set (%d,%d): %s\n", row, col, val); + + //list.getModel().setValueAt(val, row, col); + Class cl = list.getModel().getColumnClass(col); + System.out.printf("The Class is: %s\n", cl.getName()); + Object cv = new Object(); + if (cl == Double.class) { + cv = rowobj.getDouble(h); + } + if (cl == String.class) { + cv = rowobj.getString(h); + } + if (cl == Integer.class) { + cv = rowobj.getInt(h); + } + if (cl == Boolean.class) { + cv = rowobj.getBoolean(h); + } + list.getModel().setValueAt(cv, row, col); + + } + + } + } /** @@ -84,15 +126,17 @@ public class EditAutoTraderList extends javax.swing.JPanel { public EditAutoTraderList() { initComponents(); + this.load(); + JComboBox comboBox = new JComboBox(); - - ArrayList > trconfigs=null; + + ArrayList> trconfigs = null; trconfigs = Globals.tloader.getTraders(); - - for (int i=0; i - + @@ -40,7 +40,7 @@ - + @@ -56,14 +56,17 @@ + + + - + - + diff --git a/src/main/java/gui/EditAutoTraderListDialog.java b/src/main/java/gui/EditAutoTraderListDialog.java index 17c08a9..dc87f64 100644 --- a/src/main/java/gui/EditAutoTraderListDialog.java +++ b/src/main/java/gui/EditAutoTraderListDialog.java @@ -38,6 +38,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { super(parent, modal); initComponents(); this.setTitle("Edit Auto Traders"); + this.setLocationRelativeTo(this.getParent()); //this.setLocationRelativeTo(MainWin.instance); } @@ -52,19 +53,24 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { editAutoTraderList1 = new gui.EditAutoTraderList(); jButton1 = new javax.swing.JButton(); - jButton2 = new javax.swing.JButton(); + jOkButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jButton1.setMnemonic('c'); jButton1.setText("Cancel"); jButton1.setToolTipText(""); - - jButton2.setMnemonic('o'); - jButton2.setText("Ok"); - jButton2.addActionListener(new java.awt.event.ActionListener() { + jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton2ActionPerformed(evt); + jButton1ActionPerformed(evt); + } + }); + + jOkButton.setMnemonic('o'); + jOkButton.setText("Ok"); + jOkButton.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + jOkButtonActionPerformed(evt); } }); @@ -74,7 +80,7 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(jButton2) + .addComponent(jOkButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addContainerGap()) @@ -87,17 +93,22 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) - .addComponent(jButton2)) + .addComponent(jOkButton)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents - private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed + private void jOkButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOkButtonActionPerformed // TODO add your handling code here: this.editAutoTraderList1.save(); - }//GEN-LAST:event_jButton2ActionPerformed + this.dispose(); + }//GEN-LAST:event_jOkButtonActionPerformed + + private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + this.dispose(); + }//GEN-LAST:event_jButton1ActionPerformed /** * @param args the command line arguments @@ -144,6 +155,6 @@ public class EditAutoTraderListDialog extends javax.swing.JDialog { // Variables declaration - do not modify//GEN-BEGIN:variables private gui.EditAutoTraderList editAutoTraderList1; private javax.swing.JButton jButton1; - private javax.swing.JButton jButton2; + private javax.swing.JButton jOkButton; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/gui/NewMDIApplication.form b/src/main/java/gui/NewMDIApplication.form index 3432782..db0f1a9 100644 --- a/src/main/java/gui/NewMDIApplication.form +++ b/src/main/java/gui/NewMDIApplication.form @@ -227,7 +227,7 @@ - + @@ -239,7 +239,7 @@ - + diff --git a/src/main/java/gui/NewMDIApplication.java b/src/main/java/gui/NewMDIApplication.java index 9a3c585..19ac4fd 100644 --- a/src/main/java/gui/NewMDIApplication.java +++ b/src/main/java/gui/NewMDIApplication.java @@ -87,7 +87,7 @@ public class NewMDIApplication extends javax.swing.JFrame { jScrollPane2 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jToolBar1 = new javax.swing.JToolBar(); - jButton1 = new javax.swing.JButton(); + jRunButton = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); orderBookPanel1 = new gui.OrderBookPanel(); jScrollPane1 = new javax.swing.JScrollPane(); @@ -126,18 +126,18 @@ public class NewMDIApplication extends javax.swing.JFrame { jToolBar1.setFloatable(false); jToolBar1.setRollover(true); - jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/run.gif"))); // NOI18N - jButton1.setText("Run sim!"); - jButton1.setToolTipText("Run the simmulation"); - jButton1.setFocusable(false); - jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jButton1.addActionListener(new java.awt.event.ActionListener() { + jRunButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/run.gif"))); // NOI18N + jRunButton.setText("Run sim!"); + jRunButton.setToolTipText("Run the simmulation"); + jRunButton.setFocusable(false); + jRunButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + jRunButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + jRunButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { - jButton1ActionPerformed(evt); + jRunButtonActionPerformed(evt); } }); - jToolBar1.add(jButton1); + jToolBar1.add(jRunButton); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pause.gif"))); // NOI18N jButton2.setText("Pause"); @@ -318,10 +318,10 @@ public class NewMDIApplication extends javax.swing.JFrame { }//GEN-LAST:event_aboutMenuItemActionPerformed - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed + private void jRunButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRunButtonActionPerformed this.startTraders(); Globals.se.timer.start(); - }//GEN-LAST:event_jButton1ActionPerformed + }//GEN-LAST:event_jRunButtonActionPerformed private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed Globals.LOGGER.info("Edit prefs..."); @@ -429,12 +429,12 @@ public class NewMDIApplication extends javax.swing.JFrame { private javax.swing.JMenuItem exitMenuItem; private javax.swing.JMenu fileMenu; private javax.swing.JMenu helpMenu; - private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JMenu jMenu1; private javax.swing.JMenuItem jMenuItem1; private javax.swing.JMenuItem jMenuItem2; private javax.swing.JMenuItem jMenuItem3; + private javax.swing.JButton jRunButton; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; diff --git a/src/main/java/gui/TraderListPanel.form b/src/main/java/gui/TraderListPanel.form index 4b5398c..752ad3c 100644 --- a/src/main/java/gui/TraderListPanel.form +++ b/src/main/java/gui/TraderListPanel.form @@ -35,6 +35,7 @@ +
diff --git a/src/main/java/gui/TraderListPanel.java b/src/main/java/gui/TraderListPanel.java index 5718f9a..86dc8ab 100644 --- a/src/main/java/gui/TraderListPanel.java +++ b/src/main/java/gui/TraderListPanel.java @@ -222,6 +222,7 @@ public class TraderListPanel extends javax.swing.JPanel traderListScroller = new javax.swing.JScrollPane(); traderList = new javax.swing.JTable(); + traderList.setAutoCreateRowSorter(true); traderList.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {null, null, null, null},