Java tutorial
package com.view; import Autocomplete.CSVReader; import Autocomplete.Java2sAutoComboBox; import UserObjects.Broker; import UserObjects.Order; import UserObjects.SingleOrder; import UserObjects.Trader; import com.controller.CMAIN; import com.controller.CPMEndOfDay; import com.controller.CPMOrderMANIAC; import com.controller.ControllerPMCreatedOrders; import java.awt.Component; import java.util.ArrayList; import java.util.List; import javax.swing.DefaultCellEditor; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.RowFilter; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import javax.swing.table.TableModel; import javax.swing.table.TableRowSorter; import static javax.swing.JOptionPane.showMessageDialog; import javax.swing.Timer; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.util.Arrays; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import static javax.swing.JOptionPane.showMessageDialog; import org.json.JSONException; import javax.swing.table.DefaultTableCellRenderer; /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * * @author csavas */ public class PortfolioManagerWindow extends javax.swing.JFrame { /** * Creates new form MainJFrame */ public PortfolioManagerWindow() { super(); //The following line is for the exit confirmation addWindowListener(new AreYouSure()); initComponents(); //START TIMER TO UPDATE ORDERS Timer timer = new Timer(5000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ArrayList<SingleOrder> ordersDone = new ArrayList<>(); try { ordersDone = (ArrayList) CPMOrderMANIAC.updateOrders(); CPMEndOfDay.getEODData(); } catch (ExecutionException | InterruptedException | IOException | JSONException ex) { Logger.getLogger(PortfolioManagerWindow.class.getName()).log(Level.SEVERE, null, ex); } ArrayList<SingleOrder> ordersPending = new ArrayList<>(); ArrayList<SingleOrder> ordersExecuted = new ArrayList<>(); if (null != ordersDone) { for (int i = 0; i < ordersDone.size(); i++) { String currStatus = ordersDone.get(i).getStatus(); if (currStatus.equals("Pending")) { ordersPending.add(ordersDone.get(i)); } if (currStatus.equals("Executed")) { ordersExecuted.add(ordersDone.get(i)); } } CPMOrderMANIAC.setPendings(ordersPending); CPMOrderMANIAC.setExecuted(ordersExecuted); PMOrderHistoryTable.setModel(CPMOrderMANIAC.getOHTableModel()); PMPendingOrdersTable.setModel(CPMOrderMANIAC.getPRTableModel()); //System.out.println("ABOUT TO SET MODEL OF EOD TABLE"); PMEODBoughtTable.setModel(CPMEndOfDay.getBuyTableModel()); PMEODSoldTable.setModel(CPMEndOfDay.getSellTableModel()); } else { System.out.println("ERROR UPDATING ORDERS"); } } }); timer.start(); try { Thread.sleep(1000); } catch (InterruptedException e) { } timer.restart(); } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; logOutButton = new javax.swing.JButton(); PMPlatformTabbedPane = new javax.swing.JTabbedPane(); PendingOrders = new javax.swing.JPanel(); PendingOrderRequests = new javax.swing.JScrollPane(); PMPendingOrdersTable = new javax.swing.JTable(); PMPendingOrderFilter = new javax.swing.JButton(); FilterOptionsPMPending = new javax.swing.JComboBox<>(); FilterTextPMPending = new javax.swing.JTextField(); ClearFilterPMPendingOrder = new javax.swing.JButton(); PMEOD = new javax.swing.JPanel(); jLabel2 = new javax.swing.JLabel(); PMEODBoughtScrollPane = new javax.swing.JScrollPane(); PMEODBoughtTable = new javax.swing.JTable(); PMEODSoldScrollPane = new javax.swing.JScrollPane(); PMEODSoldTable = new javax.swing.JTable(); jLabel3 = new javax.swing.JLabel(); FilterTextPMEOD = new javax.swing.JTextField(); FilterOptionsPMEOD = new javax.swing.JComboBox<>(); PMEODFilter = new javax.swing.JButton(); ClearFilterPMEOD = new javax.swing.JButton(); CreateOrder = new javax.swing.JPanel(); PMSelectTraderOptions = new javax.swing.JComboBox<>(); jLabel5 = new javax.swing.JLabel(); PMSendOrderScrollPane = new javax.swing.JScrollPane(); PMSendOrderTable = new javax.swing.JTable(); PMSendOrder = new javax.swing.JButton(); PMAddOrderRow = new javax.swing.JButton(); PMOrderHistory = new javax.swing.JPanel(); PMOrderHistoryScrollPane = new javax.swing.JScrollPane(); PMOrderHistoryTable = new javax.swing.JTable(); FilterTextPMOrderHistory = new javax.swing.JTextField(); FilterOptionsPMOrderHistory = new javax.swing.JComboBox<>(); PMOrderHistoryFilter = new javax.swing.JButton(); ClearFilterPMOrderHistory = new javax.swing.JButton(); ChangePassword = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("MoneyTree Trading Platform: Portfolio Manager"); setMinimumSize(new java.awt.Dimension(1024, 768)); getContentPane().setLayout(new java.awt.GridBagLayout()); logOutButton.setText("Logout"); logOutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logOutButtonActionPerformed(evt); } }); getContentPane().add(logOutButton, new java.awt.GridBagConstraints()); PMPlatformTabbedPane.setMinimumSize(new java.awt.Dimension(150, 65)); PMPendingOrdersTable.setBackground(new java.awt.Color(102, 102, 102)); PMPendingOrdersTable .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); String[] CurrencyValues = { "USD", "GBP" }; PMPendingOrdersTable.setForeground(new java.awt.Color(255, 255, 255)); PMPendingOrdersTable.setModel(com.controller.CPMOrderMANIAC.getPRTableModel()); PMPendingOrdersTable.setGridColor(new java.awt.Color(255, 255, 255)); PMPendingOrdersTable.getTableHeader().setReorderingAllowed(false); PendingOrderRequests.setViewportView(PMPendingOrdersTable); PMPendingOrderFilter.setText("Filter"); PMPendingOrderFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMPendingOrderFilterActionPerformed(evt); } }); FilterOptionsPMPending.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Order ID", "Portfolio ID", "Symbol", "Quantity", "Action", "Stop Price", "Limit Price", "Account Type", "Order Type", "Assigned To" })); FilterTextPMPending.setText("Filter Text"); ClearFilterPMPendingOrder.setText("Clear Filter"); ClearFilterPMPendingOrder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMPendingOrderActionPerformed(evt); } }); javax.swing.GroupLayout PendingOrdersLayout = new javax.swing.GroupLayout(PendingOrders); PendingOrders.setLayout(PendingOrdersLayout); PendingOrdersLayout.setHorizontalGroup( PendingOrdersLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PendingOrdersLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(PendingOrderRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) .addGroup(PendingOrdersLayout.createSequentialGroup().addContainerGap() .addComponent(FilterTextPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(FilterOptionsPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMPendingOrderFilter).addGap(18, 18, 18) .addComponent(ClearFilterPMPendingOrder) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PendingOrdersLayout.setVerticalGroup(PendingOrdersLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PendingOrdersLayout.createSequentialGroup().addContainerGap() .addComponent(PendingOrderRequests, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(PendingOrdersLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(FilterTextPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterOptionsPMPending, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PMPendingOrderFilter).addComponent(ClearFilterPMPendingOrder)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Pending Order Requests", PendingOrders); jLabel2.setText("Bought"); PMEODBoughtTable.setModel(CPMEndOfDay.getBuyTableModel()); PMEODBoughtScrollPane.setViewportView(PMEODBoughtTable); PMEODSoldTable.setModel(CPMEndOfDay.getSellTableModel()); PMEODSoldScrollPane.setViewportView(PMEODSoldTable); jLabel3.setText("Sold"); FilterTextPMEOD.setText("Filter By"); FilterOptionsPMEOD.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Portfolio ID", "Symbol", "Quantity", "Price" })); PMEODFilter.setText("Filter"); PMEODFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMEODFilterActionPerformed(evt); } }); ClearFilterPMEOD.setText("Clear Filter"); ClearFilterPMEOD.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMEODActionPerformed(evt); } }); javax.swing.GroupLayout PMEODLayout = new javax.swing.GroupLayout(PMEOD); PMEOD.setLayout(PMEODLayout); PMEODLayout.setHorizontalGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup() .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(PMEODLayout.createSequentialGroup().addGap(124, 124, 124) .addComponent(FilterTextPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 350, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(FilterOptionsPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMEODFilter)) .addGroup(PMEODLayout.createSequentialGroup().addGroup(PMEODLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addGap(234, 234, 234) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(PMEODBoughtScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18))) .addGroup(PMEODLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMEODSoldScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, PMEODLayout.createSequentialGroup().addComponent(jLabel3) .addGap(132, 132, 132))))) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(ClearFilterPMEOD).addGap(55, 55, 55))); PMEODLayout.setVerticalGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addContainerGap() .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel3).addComponent(jLabel2)) .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMEODLayout.createSequentialGroup().addGap(15, 15, 15).addComponent( PMEODSoldScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGroup(PMEODLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(PMEODBoughtScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))) .addGap(21, 21, 21) .addGroup(PMEODLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(PMEODFilter) .addComponent(FilterOptionsPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterTextPMEOD, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(ClearFilterPMEOD)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("EOD", PMEOD); PMSelectTraderOptions.setModel(new javax.swing.DefaultComboBoxModel<>(TraderNames)); PMSelectTraderOptions.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMSelectTraderOptionsActionPerformed(evt); } }); jLabel5.setText("Select Trader to Assign To:"); PMSendOrderTable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { { null, null, null, null, null, null, null, null, null } }, new String[] { "Portfolio ID", "Stock Exchange", "Symbol", "Quantity", "Action", "Order Type", "Stop Price", "Limit Price", "Account Type" }) { Class[] types = new Class[] { java.lang.Long.class, java.lang.String.class, java.lang.String.class, java.lang.Integer.class, java.lang.String.class, java.lang.String.class, java.lang.Double.class, java.lang.Double.class, java.lang.String.class }; public Class getColumnClass(int columnIndex) { return types[columnIndex]; } }); TableColumn col2 = PMSendOrderTable.getColumnModel().getColumn(1); col2.setCellEditor(new myComboBoxEditor(StockExchange)); col2.setCellRenderer(new MyComboBoxRenderer(StockExchange)); TableColumn col1 = PMSendOrderTable.getColumnModel().getColumn(4); col1.setCellEditor(new myComboBoxEditor(ActionItems)); col1.setCellRenderer(new MyComboBoxRenderer(ActionItems)); TableColumn col5 = PMSendOrderTable.getColumnModel().getColumn(5); col5.setCellEditor(new myComboBoxEditor(OrderType)); col5.setCellRenderer(new MyComboBoxRenderer(OrderType)); TableColumn col3 = PMSendOrderTable.getColumnModel().getColumn(8); col3.setCellEditor(new myComboBoxEditor(AccountType)); col3.setCellRenderer(new MyComboBoxRenderer(AccountType)); /////////////////////////////////////GG TableColumn col4 = PMSendOrderTable.getColumnModel().getColumn(2); CSVReader csv = new CSVReader(); ArrayList<String> symbolList = csv.loadSymbol(); Java2sAutoComboBox comboBox = new Java2sAutoComboBox(symbolList); comboBox.setDataList(symbolList); comboBox.setMaximumRowCount(5); col4.setCellEditor(new DefaultCellEditor(comboBox)); //Set up tool tips for the sport cells. DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for combo box"); col4.setCellRenderer(renderer); /////////////////////////////////////gg PMSendOrderScrollPane.setViewportView(PMSendOrderTable); PMSendOrder.setText("Send Order"); PMSendOrder.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMSendOrderActionPerformed(evt); } }); PMAddOrderRow.setText("Add Row"); PMAddOrderRow.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMAddOrderRowActionPerformed(evt); } }); javax.swing.GroupLayout CreateOrderLayout = new javax.swing.GroupLayout(CreateOrder); CreateOrder.setLayout(CreateOrderLayout); CreateOrderLayout.setHorizontalGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMSendOrderScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(CreateOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout .createSequentialGroup().addComponent(jLabel5).addGap(18, 18, 18) .addComponent(PMSelectTraderOptions, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(213, 213, 213).addComponent(PMSendOrder).addContainerGap()) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, CreateOrderLayout.createSequentialGroup().addComponent(PMAddOrderRow) .addGap(109, 109, 109))))); CreateOrderLayout.setVerticalGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CreateOrderLayout.createSequentialGroup().addGap(5, 5, 5).addGroup(CreateOrderLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(CreateOrderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5).addComponent(PMSelectTraderOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(PMSendOrder)).addGap(28, 28, 28) .addComponent(PMSendOrderScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMAddOrderRow) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Create Order", CreateOrder); PMOrderHistoryTable.setBackground(new java.awt.Color(102, 102, 102)); PMOrderHistoryTable .setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED)); PMOrderHistoryTable.setForeground(new java.awt.Color(255, 255, 255)); PMOrderHistoryTable.setModel(com.controller.CPMOrderMANIAC.getOHTableModel()); PMOrderHistoryTable.setGridColor(new java.awt.Color(255, 255, 255)); PMOrderHistoryTable.getTableHeader().setReorderingAllowed(false); PMOrderHistoryScrollPane.setViewportView(PMOrderHistoryTable); FilterTextPMOrderHistory.setText("Filter By"); FilterOptionsPMOrderHistory.setModel(new javax.swing.DefaultComboBoxModel<>( new String[] { "Order ID", "Portfolio ID", "Symbol", "Quantity", "Action", "Stop Price", "Limit Price", "Account Type", "Order Type", "Assigned To" })); PMOrderHistoryFilter.setText("Filter"); PMOrderHistoryFilter.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { PMOrderHistoryFilterActionPerformed(evt); } }); ClearFilterPMOrderHistory.setText("Clear Filter"); ClearFilterPMOrderHistory.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ClearFilterPMOrderHistoryActionPerformed(evt); } }); javax.swing.GroupLayout PMOrderHistoryLayout = new javax.swing.GroupLayout(PMOrderHistory); PMOrderHistory.setLayout(PMOrderHistoryLayout); PMOrderHistoryLayout .setHorizontalGroup( PMOrderHistoryLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMOrderHistoryLayout.createSequentialGroup().addContainerGap() .addGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(PMOrderHistoryScrollPane) .addGroup(PMOrderHistoryLayout.createSequentialGroup() .addComponent(FilterTextPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(FilterOptionsPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(18, 18, 18).addComponent(PMOrderHistoryFilter) .addGap(18, 18, 18).addComponent(ClearFilterPMOrderHistory) .addGap(0, 0, Short.MAX_VALUE))) .addContainerGap())); PMOrderHistoryLayout.setVerticalGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(PMOrderHistoryLayout.createSequentialGroup() .addComponent(PMOrderHistoryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 187, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(PMOrderHistoryLayout .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(FilterTextPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(FilterOptionsPMOrderHistory, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(PMOrderHistoryFilter).addComponent(ClearFilterPMOrderHistory)) .addGap(0, 0, Short.MAX_VALUE))); PMPlatformTabbedPane.addTab("Executed Order History", PMOrderHistory); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.gridwidth = 2; gridBagConstraints.ipady = 127; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(6, 0, 0, 85); getContentPane().add(PMPlatformTabbedPane, gridBagConstraints); ChangePassword.setText("Change Password"); ChangePassword.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { ChangePasswordActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.gridheight = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; gridBagConstraints.insets = new java.awt.Insets(11, 610, 0, 85); getContentPane().add(ChangePassword, gridBagConstraints); pack(); }// </editor-fold>//GEN-END:initComponents private void PMSendOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMSendOrderActionPerformed DefaultTableModel dtm = (DefaultTableModel) PMSendOrderTable.getModel(); int nRow = dtm.getRowCount(); long currUID = 0; int nCol = dtm.getColumnCount(); Object[][] tableData = new Object[nRow][nCol]; List<SingleOrder> parsedOrders = new ArrayList(); String selectedTrader = String.valueOf(PMSelectTraderOptions.getSelectedItem()); for (int t = 0; t < traderListForBox.size(); t++) { if (traderListForBox.get(t).getUsername().equals(selectedTrader)) { currUID = traderListForBox.get(t).getU_id(); System.out.println("OUR TRADER WE ASSIGN TO IS: " + selectedTrader + " HIS ID IS: " + currUID); } } boolean thereAreOrders = false; boolean ignoreRowFlag = false; for (int i = 0; i < nRow; i++) { for (int j = 0; j < nCol; j++) { tableData[i][j] = dtm.getValueAt(i, j); } System.out.println("Retrieved all table data"); boolean trigg = true; for (int k = 0; k < nCol; k++) { if (tableData[i][k] != null) { ignoreRowFlag = false; } else { ignoreRowFlag = true; System.out.println("IGNORING EMPTY ROW"); } } //double check symbol is not null if (ignoreRowFlag == false) { if (tableData[i][2] == null) { trigg = false; } else if (tableData[i][2].toString().trim().equals("")) { showMessageDialog(null, "Please enter non-empty Symbol."); trigg = false; } else if (!(tableData[i][2].toString().trim() .equals(tableData[i][2].toString().trim().toUpperCase()))) { showMessageDialog(null, "Please enter the Symbol in all capital letters."); trigg = false; } if (tableData[i][0] != null && tableData[i][1] != null && tableData[i][2] != null && tableData[i][3] != null && tableData[i][4] != null && tableData[i][5] != null) { if (tableData[i][0] != null) { long portIDC = (long) tableData[i][0]; if (portIDC < 0) { showMessageDialog(null, "You have entered a negative portfolio ID value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][3] != null) { int quantityC = (int) tableData[i][3]; if (quantityC < 0) { showMessageDialog(null, "You have entered a negative quantity value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][5] != null) { String orderType = (String) tableData[i][5]; switch (orderType) { case "Market": if ((tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] == null && tableData[i][7] != null)) { showMessageDialog(null, "A market order should have neither a stop price nor a limit price."); trigg = false; } break; case "Limit": if ((tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] == null && tableData[i][7] == null)) { showMessageDialog(null, "A limit order should have a limit price and no stop price."); trigg = false; } break; case "Stop": if ((tableData[i][6] == null && tableData[i][7] != null) || (tableData[i][6] != null && tableData[i][7] != null) || (tableData[i][6] == null && tableData[i][7] == null)) { showMessageDialog(null, "A stop order should have a stop price and no limit price."); trigg = false; } break; case "Stop Limit": if ((tableData[i][6] == null && tableData[i][7] == null) || (tableData[i][6] != null && tableData[i][7] == null) || (tableData[i][6] == null && tableData[i][7] != null)) { showMessageDialog(null, "A Stop Limit order should have both a stop price and a limit price."); trigg = false; } break; default: showMessageDialog(null, "Something messed up in cases for order type."); } } if (tableData[i][6] != null) { double stopC = (double) tableData[i][6]; if (stopC < 0) { showMessageDialog(null, "You have entered a negative stop price value. Please fix this value before submitting the order."); trigg = false; } } if (tableData[i][7] != null) { double limitC = (double) tableData[i][7]; if (limitC < 0) { showMessageDialog(null, "You have entered a negative limit price value. Please fix this value before submitting the order."); trigg = false; } } if (trigg == true) { thereAreOrders = true; SingleOrder o = new SingleOrder(tableData[i]); parsedOrders.add(o); } } else { String a, b, c, d, e, f; if (tableData[i][0] == null) { a = "Portfolio ID"; } else { a = ""; } if (tableData[i][1] == null) { b = "Stock Exchange"; } else { b = ""; } if (tableData[i][2] == null || tableData[i][2].toString().trim().equals("")) { c = "Symbol"; } else { c = ""; } if (tableData[i][3] == null) { d = "Quantity"; } else { d = ""; } if (tableData[i][4] == null) { e = "Action"; } else { e = ""; } if (tableData[i][5] == null) { f = "Order Type"; } else { f = ""; } showMessageDialog(null, "You need to fill in the necessary fields before sending the order:\n" + a + "\n" + b + "\n" + c + "\n" + d + "\n" + e + "\n" + f); } } } if (thereAreOrders) { showMessageDialog(null, "You have successfully sent your trades."); dtm.setRowCount(0); dtm.addRow(new Object[] { null, null, null, null, null, null, null, null, null }); Order toSend = new Order(selectedTrader, parsedOrders); toSend.setAssignedTo(currUID); Long currID = CMAIN.reportUser().getU_id(); String currUname = CMAIN.reportUser().getUsername(); toSend.setPmId(currID); toSend.setPmUsername(currUname); ControllerPMCreatedOrders.handleOrder(toSend); } }//GEN-LAST:event_PMSendOrderActionPerformed private void ChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ChangePasswordActionPerformed new ChangePassword().setVisible(true); }//GEN-LAST:event_ChangePasswordActionPerformed private void PMSelectTraderOptionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMSelectTraderOptionsActionPerformed // TODO add your handling code here: }//GEN-LAST:event_PMSelectTraderOptionsActionPerformed private void PMPendingOrderFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMPendingOrderFilterActionPerformed final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMPendingOrdersTable.getModel()); PMPendingOrdersTable.setRowSorter(sorter); String text = FilterTextPMPending.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter(text)); } }//GEN-LAST:event_PMPendingOrderFilterActionPerformed //Code for giving a pop up box for exit confirmation private class AreYouSure extends WindowAdapter { public void windowClosing(WindowEvent e) { int option = JOptionPane.showOptionDialog(PortfolioManagerWindow.this, "Are you sure you want to quit?", "Exit Dialog", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE, null, null, null); if (option == JOptionPane.YES_OPTION) { dispose(); } else { setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); } } } private void PMEODFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMEODFilterActionPerformed final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMEODBoughtTable.getModel()); PMEODBoughtTable.setRowSorter(sorter); final TableRowSorter<TableModel> sorter2 = new TableRowSorter<TableModel>(PMEODSoldTable.getModel()); PMEODSoldTable.setRowSorter(sorter2); String text = FilterTextPMEOD.getText(); if (text.length() == 0) { sorter.setRowFilter(null); sorter2.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter(text)); sorter2.setRowFilter(RowFilter.regexFilter(text)); } }//GEN-LAST:event_PMEODFilterActionPerformed private void PMOrderHistoryFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMOrderHistoryFilterActionPerformed final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMOrderHistoryTable.getModel()); PMOrderHistoryTable.setRowSorter(sorter); String text = FilterTextPMOrderHistory.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { sorter.setRowFilter(RowFilter.regexFilter(text)); } }//GEN-LAST:event_PMOrderHistoryFilterActionPerformed private void PMAddOrderRowActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PMAddOrderRowActionPerformed DefaultTableModel m = (DefaultTableModel) PMSendOrderTable.getModel(); m.addRow(new Object[] { null, null, null, null, null, null, null, null, null }); }//GEN-LAST:event_PMAddOrderRowActionPerformed private void logOutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logOutButtonActionPerformed UserLogin u = new UserLogin(); //u.setSize(300,300); u.setVisible(true); CMAIN.handleLogout(); this.dispose(); }//GEN-LAST:event_logOutButtonActionPerformed private void ClearFilterPMPendingOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMPendingOrderActionPerformed FilterTextPMPending.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMPendingOrdersTable.getModel()); PMPendingOrdersTable.setRowSorter(sorter); sorter.setRowFilter(null); }//GEN-LAST:event_ClearFilterPMPendingOrderActionPerformed private void ClearFilterPMOrderHistoryActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMOrderHistoryActionPerformed FilterTextPMOrderHistory.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMOrderHistoryTable.getModel()); PMOrderHistoryTable.setRowSorter(sorter); sorter.setRowFilter(null); // TODO add your handling code here: }//GEN-LAST:event_ClearFilterPMOrderHistoryActionPerformed private void ClearFilterPMEODActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearFilterPMEODActionPerformed // TODO add your handling code here: FilterTextPMEOD.setText(""); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(PMEODBoughtTable.getModel()); PMEODBoughtTable.setRowSorter(sorter); final TableRowSorter<TableModel> sorter2 = new TableRowSorter<TableModel>(PMEODSoldTable.getModel()); PMEODSoldTable.setRowSorter(sorter2); sorter.setRowFilter(null); sorter2.setRowFilter(null); }//GEN-LAST:event_ClearFilterPMEODActionPerformed private class myComboBoxEditor extends DefaultCellEditor { myComboBoxEditor(String[] items) { super(new JComboBox(items)); } } private class MyComboBoxRenderer extends JComboBox implements TableCellRenderer { public MyComboBoxRenderer(String[] items) { super(items); } @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { if (isSelected) { setForeground(table.getSelectionForeground()); super.setBackground(table.getSelectionBackground()); } else { setForeground(table.getForeground()); setBackground(table.getBackground()); } setSelectedItem(value); return this; } } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.hifi.HiFiLookAndFeel"); /*for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } }*/ } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(PortfolioManagerWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(PortfolioManagerWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(PortfolioManagerWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(PortfolioManagerWindow.class.getName()) .log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> //</editor-fold> //</editor-fold> //</editor-fold> /* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new PortfolioManagerWindow().setVisible(true); } }); } // public void addAuto(ArrayList<String> t) { // t.add("Automatic"); // } public String[] tlist() { ArrayList<String> NameList = new ArrayList<>(); ArrayList<Long> IDList = new ArrayList<>(); NameList.add("Automatic"); List<Trader> listOfTraders = ControllerPMCreatedOrders.getTraderList(); for (int i = 0; i < listOfTraders.size(); i++) { traderListForBox.add(listOfTraders.get(i)); NameList.add(listOfTraders.get(i).getUsername()); IDList.add(listOfTraders.get(i).getU_id()); } String[] t = new String[NameList.size()]; t = NameList.toArray(t); return t; } //Trader Names and Currency Strings String[] TraderNames = tlist(); String[] ActionItems = { "Buy", "Sell" }; String[] StockExchange = { "NYSE", "LSE" }; String[] AccountType = { "Margin", "Cash" }; String[] OrderType = { "Market", "Stop", "Limit", "Stop Limit" }; /* public void readNasdaq() throws IOException { try { FileReader input; input = new FileReader("...\\JAVA\\Resources\\nasdaqlisted.txt"); BufferedReader bufRead = new BufferedReader(input); String myLine = null; while ((myLine = bufRead.readLine()) != null){ String[] array1 = myLine.split("|"); // check to make sure you have valid data String[] array2 = array1[1].split(" "); for (int i = 0; i < array2.length; i++) function(array1[0], array2[i]); } } catch(IOException e) { System.out.println("File to read NASDAQ data not found"); } } */ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton ChangePassword; private javax.swing.JButton ClearFilterPMEOD; private javax.swing.JButton ClearFilterPMOrderHistory; private javax.swing.JButton ClearFilterPMPendingOrder; private javax.swing.JPanel CreateOrder; private javax.swing.JComboBox<String> FilterOptionsPMEOD; private javax.swing.JComboBox<String> FilterOptionsPMOrderHistory; private javax.swing.JComboBox<String> FilterOptionsPMPending; private javax.swing.JTextField FilterTextPMEOD; private javax.swing.JTextField FilterTextPMOrderHistory; private javax.swing.JTextField FilterTextPMPending; private javax.swing.JButton PMAddOrderRow; private javax.swing.JPanel PMEOD; private javax.swing.JScrollPane PMEODBoughtScrollPane; private javax.swing.JTable PMEODBoughtTable; private javax.swing.JButton PMEODFilter; private javax.swing.JScrollPane PMEODSoldScrollPane; private javax.swing.JTable PMEODSoldTable; private javax.swing.JPanel PMOrderHistory; private javax.swing.JButton PMOrderHistoryFilter; private javax.swing.JScrollPane PMOrderHistoryScrollPane; private javax.swing.JTable PMOrderHistoryTable; private javax.swing.JButton PMPendingOrderFilter; private javax.swing.JTable PMPendingOrdersTable; private javax.swing.JTabbedPane PMPlatformTabbedPane; private javax.swing.JComboBox<String> PMSelectTraderOptions; private javax.swing.JButton PMSendOrder; private javax.swing.JScrollPane PMSendOrderScrollPane; private javax.swing.JTable PMSendOrderTable; private javax.swing.JScrollPane PendingOrderRequests; private javax.swing.JPanel PendingOrders; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel5; private javax.swing.JButton logOutButton; // End of variables declaration//GEN-END:variables static public ArrayList<Trader> traderListForBox = new ArrayList<>(); }