private void registerListeners() { FocusListener focusListener = new FocusAdapter() { @Override public void focusLost(final FocusEvent evt) { updateTotalField(); } }; feePanel.addFocusListener(focusListener); feePanel.addActionListener(this); gainsPanel.addActionListener(this); quantityField.addFocusListener(focusListener); priceField.addFocusListener(focusListener); datePanel.getDateField().addKeyListener(keyListener); feePanel.addKeyListener(keyListener); memoField.addKeyListener(keyListener); priceField.addKeyListener(keyListener); quantityField.addKeyListener(keyListener); securityCombo.addKeyListener(keyListener); reconciledButton.addKeyListener(keyListener); }
@Override public void modifyTransaction(final Transaction tran) { if (!(tran instanceof InvestmentTransaction)) { throw new IllegalArgumentException("bad tranType"); } clearForm(); datePanel.setDate(tran.getDate()); List<TransactionEntry> entries = tran.getTransactionEntries(); feePanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentFeeEntries()); gainsPanel.setTransactionEntries(((InvestmentTransaction) tran).getInvestmentGainLossEntries()); for (TransactionEntry e : entries) { if (e instanceof TransactionEntrySellX) { AbstractInvestmentTransactionEntry entry = (AbstractInvestmentTransactionEntry) e; memoField.setText(e.getMemo()); priceField.setDecimal(entry.getPrice()); quantityField.setDecimal(entry.getQuantity()); securityCombo.setSelectedNode(entry.getSecurityNode()); accountExchangePanel.setSelectedAccount(entry.getDebitAccount()); accountExchangePanel.setExchangedAmount(entry.getDebitAmount().abs()); } } updateTotalField(); modTrans = tran; reconciledButton.setSelected(tran.getReconciled(getAccount()) == ReconciledState.RECONCILED); }
@Override public void clearForm() { super.clearForm(); accountExchangePanel.setSelectedAccount(getAccount()); feePanel.clearForm(); gainsPanel.clearForm(); updateTotalField(); }
void updateTotalField() { BigDecimal fee = feePanel.getDecimal(); BigDecimal quantity = quantityField.getDecimal(); BigDecimal price = priceField.getDecimal(); BigDecimal value = quantity.multiply(price); value = value.subtract(fee); totalField.setDecimal(value); }
@Override public Transaction buildTransaction() { BigDecimal exchangeRate = accountExchangePanel.getExchangeRate(); Collection<TransactionEntry> fees = feePanel.getTransactions(); Collection<TransactionEntry> gains = gainsPanel.getTransactions(); return TransactionFactory.generateSellXTransaction( accountExchangePanel.getSelectedAccount(), getAccount(), securityCombo.getSelectedNode(), priceField.getDecimal(), quantityField.getDecimal(), exchangeRate, datePanel.getDate(), memoField.getText(), reconciledButton.isSelected(), fees, gains); }