private void init() { setDefaultCloseOperation(DISPOSE_ON_CLOSE); setTitle("Strategy Information - " + strategy.getName()); this.addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { Dispatcher dispatcher = Dispatcher.getInstance(); dispatcher.removeListener(StrategyInformationDialog.this); } }); JPanel contentPanel = new JPanel(new BorderLayout()); getContentPane().add(contentPanel, BorderLayout.CENTER); JTabbedPane tabbedPane = new JTabbedPane(); contentPanel.add(tabbedPane, BorderLayout.CENTER); JPanel performancePanel = new JPanel(new SpringLayout()); tabbedPane.addTab("Performance", performancePanel); NumberFormat nf2 = NumberFormatterFactory.getNumberFormatter(2); PerformanceManager pm = strategy.getPerformanceManager(); add(performancePanel, "Position", strategy.getPositionManager().getCurrentPosition()); add(performancePanel, "Trades", pm.getTrades()); add(performancePanel, "% Profitable", nf2.format(pm.getPercentProfitableTrades())); add(performancePanel, "Average trade", nf2.format(pm.getAverageProfitPerTrade())); add(performancePanel, "Net Profit", nf2.format(pm.getNetProfit())); add(performancePanel, "Max Drawdown", nf2.format(pm.getMaxDrawdown())); add(performancePanel, "Profit Factor", nf2.format(pm.getProfitFactor())); add(performancePanel, "Kelly", nf2.format(pm.getKellyCriterion())); add(performancePanel, "PI", nf2.format(pm.getPerformanceIndex())); add(performancePanel, "CPI", nf2.format(pm.getCPI())); makeCompactGrid(performancePanel); JPanel securityPanel = new JPanel(new SpringLayout()); tabbedPane.addTab("Instrument", securityPanel); add(securityPanel, "Symbol", strategy.getContract().m_symbol); add(securityPanel, "Security Type", strategy.getContract().m_secType); add(securityPanel, "Exchange", strategy.getContract().m_exchange); add(securityPanel, "Multiplier", strategy.getContract().m_multiplier); add(securityPanel, "Commission", strategy.getPerformanceManager().getCommission().toString()); bidAskLabel = new JLabel(); securityPanel.add(new JLabel("Best bid-ask" + ":")); securityPanel.add(bidAskLabel); cumBidAskSizesLabel = new JLabel(); securityPanel.add(new JLabel("Book bid-ask size" + ":")); securityPanel.add(cumBidAskSizesLabel); makeCompactGrid(securityPanel); JPanel parametersPanel = new JPanel(new SpringLayout()); tabbedPane.addTab("Parameters", parametersPanel); StrategyParams params = strategy.getParams(); add(parametersPanel, "Schedule", strategy.getTradingSchedule().toString()); for (StrategyParam param : params.getAll()) { add(parametersPanel, param.getName(), param.getValue()); } makeCompactGrid(parametersPanel); IndicatorManager indicatorManager = strategy.getIndicatorManager(); if (indicatorManager != null) { JPanel indicatorsPanel = new JPanel(new SpringLayout()); tabbedPane.addTab("Indicators", indicatorsPanel); for (Indicator indicator : strategy.getIndicatorManager().getIndicators()) { add(indicatorsPanel, indicator.getKey(), indicator.getValue()); } makeCompactGrid(indicatorsPanel); } getContentPane().setPreferredSize(new Dimension(450, 400)); }
@Override public int loop() { for (Strategy currentStrategy : strategies) { if (currentStrategy.isValid()) { painter.setTotalMoneyMade(moneyHandler.getTotalMoneyMade()); currentStrategy.execute(); } } return Random.nextInt(300, 600); }
public void modelChanged(Event event, Object value) { switch (event) { case StrategyUpdate: MarketDepth marketDepth = strategy.getMarketBook().getMarketDepth(); cumBidAskSizesLabel.setText(marketDepth.getSizes()); bidAskLabel.setText(marketDepth.getTop()); break; } }
/** * Returns a JPanel that represents the mancala board using strategy pattern to insert style. * * @param strat concrete strategy * @return JPanel containing both users' pits as controllers */ public JPanel boardContextDoWork(Strategy strat) { this.s = strat; Color boardColor = s.getBoardColor(); Color fontColor = s.getFontColor(); Font font = s.getFont(); JPanel panCenter = new JPanel(); JPanel panLeft = new JPanel(); JPanel panRight = new JPanel(); panCenter.setLayout(new GridLayout(2, 6, 10, 10)); // B6 to B1 Controllers for (int i = 12; i > 6; i--) { final Pits temp = new Pits(i); final int pit = i; final JLabel tempLabel = new JLabel(temp); tempLabel.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (Model.player == 1) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Player A's turn!"); } else if (model.data[pit] == 0) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Pit is Empty try another one."); } else { if (temp.pitShape.contains(e.getPoint())) { model.move(pit); // mutator undoBtn.setText("Undo : " + model.getUndoCounter()); model.display(); } } } }); JPanel tempPanel = new JPanel(new BorderLayout()); JTextPane textPane = new JTextPane(); textPane.setEditable(false); textPane.setBackground(boardColor); textPane.setForeground(fontColor); textPane.setFont(font); textPane.setText("B" + (i - 6)); StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); tempPanel.add(textPane, BorderLayout.NORTH); tempPanel.add(tempLabel, BorderLayout.SOUTH); panCenter.add(tempPanel, BorderLayout.SOUTH); tempPanel.setBackground(boardColor); } // A1 to A6 Controllers for (int i = 0; i < 6; i++) { final Pits newPits = new Pits(i); JLabel label = new JLabel(newPits); final int pit = i; label.addMouseListener( new MouseAdapter() { public void mousePressed(MouseEvent e) { if (Model.player == 2) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Player B's turn!"); } else if (model.data[pit] == 0) { JFrame frame = new JFrame(); JOptionPane.showMessageDialog(frame, "Pit is Empty try another one."); } else { if (newPits.pitShape.contains(e.getPoint())) { model.move(pit); // mutator undoBtn.setText("Undo : " + model.getUndoCounter()); model.display(); } } } }); JPanel tempPanel = new JPanel(new BorderLayout()); tempPanel.add(label, BorderLayout.NORTH); JTextPane textPane = new JTextPane(); textPane.setBackground(boardColor); textPane.setForeground(fontColor); textPane.setFont(font); textPane.setEditable(false); textPane.setText("A" + (i + 1)); StyledDocument doc = textPane.getStyledDocument(); SimpleAttributeSet center = new SimpleAttributeSet(); StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER); doc.setParagraphAttributes(0, doc.getLength(), center, false); tempPanel.add(textPane, BorderLayout.SOUTH); tempPanel.setBackground(boardColor); panCenter.add(tempPanel, BorderLayout.SOUTH); } // left text pane JTextPane paneLeft = new JTextPane(); paneLeft.setBackground(boardColor); paneLeft.setForeground(fontColor); paneLeft.setFont(font); paneLeft.setEditable(false); paneLeft.setText("M\nA\nN\nC\nA\nL\nA\n \nB"); // right text pane JTextPane paneRight = new JTextPane(); paneRight.setBackground(boardColor); paneRight.setForeground(fontColor); paneRight.setFont(font); paneRight.setEditable(false); paneRight.setText("M\nA\nN\nC\nA\nL\nA\n \nA"); // Add text panes to left and right panels panLeft.setLayout(new BorderLayout()); panRight.setLayout(new BorderLayout()); panLeft.add(paneLeft, BorderLayout.WEST); panRight.add(paneRight, BorderLayout.EAST); panLeft.add(new JLabel(new Pits(13)), BorderLayout.EAST); panRight.add(new JLabel(new Pits(6)), BorderLayout.WEST); // add the 2 mancala panels and pit panel to larger displayPanel JPanel displayPanel = new JPanel(); displayPanel.add(panLeft, BorderLayout.WEST); displayPanel.add(panCenter, BorderLayout.CENTER); displayPanel.add(panRight, BorderLayout.EAST); // set color panCenter.setBackground(boardColor); panLeft.setBackground(boardColor); panRight.setBackground(boardColor); displayPanel.setBackground(boardColor); // return display panel which contains the containers and elements created return displayPanel; }