private void updateUserInfo() { cashRemainjTextField.setText( (new DecimalFormat("###,###")).format(currentUser.getCash() * 1000) + " VND"); PortfolioTableModel portfolioTableModel = (PortfolioTableModel) portfolioJTable.getModel(); portfolioTableModel.setData(currentUser.getCurPortfolioList()); portfolioJTable.updateUI(); }
private void updateComparisonTable() { // create table layout double size[][] = new double[2][]; size[0] = new double[decEvaCrisJList.getModel().getSize() + 1]; for (int i = 0; i < size[0].length; ++i) { size[0][i] = TableLayout.PREFERRED; } size[1] = new double[decAlgsJList.getModel().getSize() + 1]; for (int i = 0; i < size[1].length; ++i) { size[1][i] = TableLayout.PREFERRED; } tableJPanel.removeAll(); tableJPanel.setLayout(new TableLayout(size)); // add components for (int i = 1; i < size[0].length; ++i) { JLabel jLabel = new JLabel(decEvaCrisJList.getModel().getElementAt(i - 1).toString()); jLabel.setVerticalAlignment(javax.swing.SwingConstants.CENTER); jLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER); jLabel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); tableJPanel.add(jLabel, i + ", 0"); } HashMap<AbstractDecisionAlgorithm, User> decAlg_ResultMap = new HashMap<AbstractDecisionAlgorithm, User>(); DefaultListModel algListModel = (DefaultListModel) decAlgsJList.getModel(); DefaultListModel criteriaListModel = (DefaultListModel) decEvaCrisJList.getModel(); // System.out.println(asset.getAssetID()); // System.out.println(toDate); // System.out.println(fromDate); TreeMap<AssetEntity, ArrayList<PriceEntity>> map = new TreeMap<AssetEntity, ArrayList<PriceEntity>>(); DefaultListModel defaultListModel = (DefaultListModel) this.assetJList.getModel(); for (int i = 0; i < defaultListModel.size(); ++i) { AssetEntity assetEntity = (AssetEntity) defaultListModel.get(i); ArrayList<PriceEntity> prices = (new PriceManager()) .getPriceInInterval( assetEntity.getAssetID(), new java.sql.Date(fromDate.getTime()), new java.sql.Date(toDate.getTime())); map.put(assetEntity, prices); } for (int algIndex = 0; algIndex < size[1].length - 1; ++algIndex) { // set price list for algorithm AbstractDecisionAlgorithm alg = (AbstractDecisionAlgorithm) algListModel.getElementAt(algIndex); alg.setPriceList(map); User user = new User(alg.toString(), currentUser.getCash(), currentUser.getCurPortfolioList()); // for (PortfolioEntry portfolioEntry : currentUser.getCurPortfolioList()) { // user.addPortfolio(portfolioEntry); // } decAlg_ResultMap.put(alg, user); for (int criteriaIndex = 0; criteriaIndex < size[0].length - 1; ++criteriaIndex) { DecisionCriteria curCriteria = (DecisionCriteria) criteriaListModel.getElementAt(criteriaIndex); curCriteria.setParametersValue(user, alg.runAlgorithm().getOrderList()); CriteriaOutputJPanel criteriaOutputJPanel = new CriteriaOutputJPanel(curCriteria.evaluate()); criteriaOutputJPanel.setBorder( javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); tableJPanel.add(criteriaOutputJPanel, (criteriaIndex + 1) + ", " + (algIndex + 1)); } } for (int i = 1; i < size[1].length; ++i) { AbstractDecisionAlgorithm decAlg = (AbstractDecisionAlgorithm) decAlgsJList.getModel().getElementAt(i - 1); // TODO type of order list is ArrayList<OrderEntity> or ArrayList<Order> ( Order.java in // virtualTrading) // i try ArrayList<Order> but it does not work // if it is ArrayList<Order> then replace // decAlg_ResultMap.get(decAlg).getCurOrderEntityList() // --> decAlg_ResultMap.get(decAlg).getCurOrderList() RowHeaderJPanel rowHeaderJPanel = new RowHeaderJPanel( decAlg, decAlg_ResultMap.get(decAlg).getCurOrderList(), decAlg_ResultMap.get(decAlg).getCurPortfolioList()); rowHeaderJPanel.setBorder( javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0))); tableJPanel.add(rowHeaderJPanel, "0, " + i); } tableJPanel.updateUI(); }