/* * Copyright (c) 2017, 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 gui; import java.awt.Dialog; import java.io.File; import java.util.ArrayList; import java.util.logging.Handler; import java.util.logging.LogRecord; import java.util.logging.Logger; import java.util.prefs.Preferences; import javax.swing.JFileChooser; import javax.swing.UIManager; import sesim.AutoTrader; import sesim.AutoTraderConfig; import sesim.Exchange; import traders.RandomTraderConfig; /** * * @author 7u83 <7u83@mail.ru> */ public class NewMDIApplication extends javax.swing.JFrame { /** * Creates new form NewMDIApplication */ public NewMDIApplication() { initComponents(); this.setLocationRelativeTo(this); this.setTitle("SeSim - Stock Exchange Simmulator"); } public void startTraders() { AutoTraderConfig cfg1 = new RandomTraderConfig(); AutoTrader rt1 = cfg1.createTrader(Globals.se, null, 100000, 100000); Globals.se.traders.add(rt1); rt1.setName("Alice"); rt1.start(); AutoTraderConfig cfg2 = new RandomTraderConfig(); for (int i = 0; i < 700; i++) { AutoTrader randt = cfg2.createTrader(Globals.se, null, 100, 100); Globals.se.traders.add(randt); randt.setName("Bob"); randt.start(); } } /** * 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 * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { jScrollPane2 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); jToolBar1 = new javax.swing.JToolBar(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); orderBookPanel1 = new gui.OrderBookPanel(); jScrollPane1 = new javax.swing.JScrollPane(); chart1 = new chart.Chart(); menuBar = new javax.swing.JMenuBar(); fileMenu = new javax.swing.JMenu(); openMenuItem = new javax.swing.JMenuItem(); saveMenuItem = new javax.swing.JMenuItem(); saveAsMenuItem = new javax.swing.JMenuItem(); exitMenuItem = new javax.swing.JMenuItem(); jMenuItem1 = new javax.swing.JMenuItem(); editMenu = new javax.swing.JMenu(); cutMenuItem = new javax.swing.JMenuItem(); copyMenuItem = new javax.swing.JMenuItem(); jSeparator1 = new javax.swing.JPopupMenu.Separator(); pasteMenuItem = new javax.swing.JMenuItem(); deleteMenuItem = new javax.swing.JMenuItem(); jSeparator2 = new javax.swing.JPopupMenu.Separator(); editPreferences = new javax.swing.JMenuItem(); jMenu1 = new javax.swing.JMenu(); jMenuItem2 = new javax.swing.JMenuItem(); jMenuItem3 = new javax.swing.JMenuItem(); helpMenu = new javax.swing.JMenu(); contentMenuItem = new javax.swing.JMenuItem(); aboutMenuItem = new javax.swing.JMenuItem(); jTextArea1.setColumns(20); jTextArea1.setRows(5); jTextArea1.setText("Hakke"); jScrollPane2.setViewportView(jTextArea1); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setMinimumSize(new java.awt.Dimension(640, 480)); setPreferredSize(new java.awt.Dimension(800, 561)); 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() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jToolBar1.add(jButton1); jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icons/pause.gif"))); // NOI18N jButton2.setText("Pause"); jButton2.setFocusable(false); jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jToolBar1.add(jButton2); javax.swing.GroupLayout chart1Layout = new javax.swing.GroupLayout(chart1); chart1.setLayout(chart1Layout); chart1Layout.setHorizontalGroup( chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); chart1Layout.setVerticalGroup( chart1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); jScrollPane1.setViewportView(chart1); fileMenu.setMnemonic('f'); fileMenu.setText("File"); openMenuItem.setMnemonic('o'); openMenuItem.setText("Open"); fileMenu.add(openMenuItem); saveMenuItem.setMnemonic('s'); saveMenuItem.setText("Save"); fileMenu.add(saveMenuItem); saveAsMenuItem.setMnemonic('a'); saveAsMenuItem.setText("Save As ..."); saveAsMenuItem.setDisplayedMnemonicIndex(5); fileMenu.add(saveAsMenuItem); exitMenuItem.setMnemonic('x'); exitMenuItem.setText("Exit"); exitMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { exitMenuItemActionPerformed(evt); } }); fileMenu.add(exitMenuItem); jMenuItem1.setText("Run"); jMenuItem1.setHideActionText(true); jMenuItem1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem1ActionPerformed(evt); } }); fileMenu.add(jMenuItem1); menuBar.add(fileMenu); editMenu.setMnemonic('e'); editMenu.setText("Edit"); cutMenuItem.setMnemonic('t'); cutMenuItem.setText("Cut"); editMenu.add(cutMenuItem); copyMenuItem.setMnemonic('y'); copyMenuItem.setText("Copy"); editMenu.add(copyMenuItem); editMenu.add(jSeparator1); pasteMenuItem.setMnemonic('s'); pasteMenuItem.setText("Strategies ..."); pasteMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { pasteMenuItemActionPerformed(evt); } }); editMenu.add(pasteMenuItem); deleteMenuItem.setMnemonic('d'); deleteMenuItem.setText("Traders ..."); deleteMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { deleteMenuItemActionPerformed(evt); } }); editMenu.add(deleteMenuItem); editMenu.add(jSeparator2); editPreferences.setMnemonic('p'); editPreferences.setText("Preferences ..."); editPreferences.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { editPreferencesActionPerformed(evt); } }); editMenu.add(editPreferences); menuBar.add(editMenu); jMenu1.setText("View"); jMenuItem2.setText("Traders"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem2ActionPerformed(evt); } }); jMenu1.add(jMenuItem2); jMenuItem3.setText("LogWindow"); jMenuItem3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jMenuItem3ActionPerformed(evt); } }); jMenu1.add(jMenuItem3); menuBar.add(jMenu1); helpMenu.setMnemonic('h'); helpMenu.setText("Help"); contentMenuItem.setMnemonic('c'); contentMenuItem.setText("Contents"); helpMenu.add(contentMenuItem); aboutMenuItem.setMnemonic('a'); aboutMenuItem.setText("About"); aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { aboutMenuItemActionPerformed(evt); } }); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); setJMenuBar(menuBar); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 797, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(orderBookPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane1) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(orderBookPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE) .addComponent(jScrollPane1)) .addContainerGap()) ); pack(); }// //GEN-END:initComponents private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed System.exit(0); }//GEN-LAST:event_exitMenuItemActionPerformed private void aboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_aboutMenuItemActionPerformed Dialog d = new gui.AboutDialog(this, rootPaneCheckingEnabled); d.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_aboutMenuItemActionPerformed private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed this.startTraders(); Globals.se.timer.start(); }//GEN-LAST:event_jButton1ActionPerformed private void editPreferencesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editPreferencesActionPerformed Globals.LOGGER.info("Edit prefs..."); Dialog d = new gui.EditPreferencesDialog(this, rootPaneCheckingEnabled); d.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_editPreferencesActionPerformed private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jMenuItem1ActionPerformed private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed TraderListDialog d = new TraderListDialog(this, false); d.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_jMenuItem2ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed Globals.se.timer.pause(); }//GEN-LAST:event_jButton2ActionPerformed private void deleteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteMenuItemActionPerformed EditAutoTraderListDialog ed = new EditAutoTraderListDialog(this, true); ed.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_deleteMenuItemActionPerformed private void pasteMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pasteMenuItemActionPerformed EditStrategies s = new EditStrategies(this, true); s.setVisible(rootPaneCheckingEnabled); }//GEN-LAST:event_pasteMenuItemActionPerformed private final LoggerDialog log_d = new LoggerDialog(this,false); private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed log_d.setVisible(!log_d.isShowing()); }//GEN-LAST:event_jMenuItem3ActionPerformed /** * @param args the command line arguments * @throws java.lang.IllegalAccessException * @throws java.lang.InstantiationException */ public static void main(String args[]) throws IllegalAccessException, InstantiationException { Globals.se = new Exchange(); class Tube { } Class c = sesim.Exchange.class; Globals.prefs = Preferences.userNodeForPackage(c); Globals.setLookAndFeel(Globals.prefs.get("laf", "Nimbus")); /* try { // Set cross-platform Java L&F (also called "Metal") UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel"); } catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) { } */ ArrayList> traders; traders = null; sesim.AutoTraderLoader tl = new sesim.AutoTraderLoader(); try { traders = tl.getTraders(); } catch (Exception e) { System.out.print("Execption\n"); } for (Class at_class : traders) { AutoTraderConfig cfg = at_class.newInstance(); System.out.printf("Have a Trader with name: %s\n", cfg.getName()); } //System.exit(0); /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { // Globals.prefs = Preferences.userNodeForPackage(this) new NewMDIApplication().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JMenuItem aboutMenuItem; private chart.Chart chart1; private javax.swing.JMenuItem contentMenuItem; private javax.swing.JMenuItem copyMenuItem; private javax.swing.JMenuItem cutMenuItem; private javax.swing.JMenuItem deleteMenuItem; private javax.swing.JMenu editMenu; private javax.swing.JMenuItem editPreferences; 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.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JPopupMenu.Separator jSeparator1; private javax.swing.JPopupMenu.Separator jSeparator2; private javax.swing.JTextArea jTextArea1; private javax.swing.JToolBar jToolBar1; private javax.swing.JMenuBar menuBar; private javax.swing.JMenuItem openMenuItem; private gui.OrderBookPanel orderBookPanel1; private javax.swing.JMenuItem pasteMenuItem; private javax.swing.JMenuItem saveAsMenuItem; private javax.swing.JMenuItem saveMenuItem; // End of variables declaration//GEN-END:variables }