Trader List Editor
This commit is contained in:
parent
78faaa59a2
commit
e4f85ba418
@ -43,6 +43,7 @@
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="list">
|
||||
<Properties>
|
||||
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
||||
<Table columnCount="6" rowCount="2">
|
||||
<Column editable="true" title="Name" type="java.lang.String">
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
@ -75,7 +78,46 @@ 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 <Class <AutoTraderConfig>> trconfigs=null;
|
||||
ArrayList<Class<AutoTraderConfig>> trconfigs = null;
|
||||
trconfigs = Globals.tloader.getTraders();
|
||||
|
||||
for (int i=0; i<trconfigs.size(); i++){
|
||||
for (int i = 0; i < trconfigs.size(); i++) {
|
||||
try {
|
||||
AutoTraderConfig ac = trconfigs.get(i).newInstance();
|
||||
System.out.printf("TrConfig: %s\n", ac.getName());
|
||||
|
||||
comboBox.addItem(ac.getName());
|
||||
} catch (InstantiationException ex) {
|
||||
Logger.getLogger(EditAutoTraderList.class.getName()).log(Level.SEVERE, null, ex);
|
||||
@ -101,19 +145,14 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// comboBox.addItem("AAA");
|
||||
// comboBox.addItem("BBB");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
DefaultTableModel model = (DefaultTableModel) list.getModel();
|
||||
list.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(comboBox));
|
||||
model.setRowCount(3);
|
||||
|
||||
// list.getColumnModel().getColumn(2).setCellRenderer(new javax.swing.table.DefaultTableCellRenderer());
|
||||
// model.setRowCount(3);
|
||||
|
||||
list.setRowHeight(30);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,6 +167,7 @@ public class EditAutoTraderList extends javax.swing.JPanel {
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
list = new javax.swing.JTable();
|
||||
|
||||
list.setAutoCreateRowSorter(true);
|
||||
list.setModel(new javax.swing.table.DefaultTableModel(
|
||||
new Object [][] {
|
||||
{"Alice", new Integer(1), "", new Double(10000.0), new Double(100.0), new Boolean(true)},
|
||||
|
@ -25,7 +25,7 @@
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="1" attributes="0">
|
||||
<EmptySpace max="32767" attributes="0"/>
|
||||
<Component id="jButton2" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="jOkButton" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
@ -40,7 +40,7 @@
|
||||
<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="jOkButton" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
@ -56,14 +56,17 @@
|
||||
<Property name="text" type="java.lang.String" value="Cancel"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||
</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">
|
||||
<Component class="javax.swing.JButton" name="jOkButton">
|
||||
<Properties>
|
||||
<Property name="mnemonic" type="int" value="111"/>
|
||||
<Property name="text" type="java.lang.String" value="Ok"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<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="jOkButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
|
@ -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();
|
||||
}// </editor-fold>//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
|
||||
}
|
||||
|
@ -227,7 +227,7 @@
|
||||
|
||||
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignBoxLayout"/>
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JButton" name="jButton1">
|
||||
<Component class="javax.swing.JButton" name="jRunButton">
|
||||
<Properties>
|
||||
<Property name="icon" type="javax.swing.Icon" editor="org.netbeans.modules.form.editors2.IconEditor">
|
||||
<Image iconType="3" name="/icons/run.gif"/>
|
||||
@ -239,7 +239,7 @@
|
||||
<Property name="verticalTextPosition" type="int" value="3"/>
|
||||
</Properties>
|
||||
<Events>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jButton1ActionPerformed"/>
|
||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jRunButtonActionPerformed"/>
|
||||
</Events>
|
||||
</Component>
|
||||
<Component class="javax.swing.JButton" name="jButton2">
|
||||
|
@ -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;
|
||||
|
@ -35,6 +35,7 @@
|
||||
<SubComponents>
|
||||
<Component class="javax.swing.JTable" name="traderList">
|
||||
<Properties>
|
||||
<Property name="autoCreateRowSorter" type="boolean" value="true"/>
|
||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
||||
<Table columnCount="4" rowCount="4">
|
||||
<Column editable="true" title="Title 1" type="java.lang.Object"/>
|
||||
|
@ -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},
|
||||
|
Loading…
Reference in New Issue
Block a user