📄 newbuytransactionjdialog.java
字号:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
if(isValidInput() == false) {
return;
}
commitEdit();
this.transaction = generateTransaction();
this.setVisible(false);
this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void commitEdit() {
try {
jFormattedTextField1.commitEdit();
jFormattedTextField2.commitEdit();
jFormattedTextField3.commitEdit();
jFormattedTextField4.commitEdit();
jFormattedTextField5.commitEdit();
jFormattedTextField6.commitEdit();
} catch (ParseException ex) {
log.error("", ex);
}
}
private void update() {
// Commit the value first before updating. This is to prevent
// double rounding issue. We force the current value to
// follow the formatter text field's.
commitEdit();
if(shouldAutoCalculateBrokerFee())
{
final BrokingFirm brokingFirm = MainFrame.getJStockOptions().getSelectedBrokingFirm();
SwingUtilities.invokeLater(new Runnable() { public void run() {
final String name = jTextField1.getText();
final int unit = (Integer)jSpinner1.getValue();
final double price = (Double)jFormattedTextField1.getValue();
final DateField dateField = (DateField)jPanel3;
final Date date = (Date)dateField.getValue();
// Stock and date information is not important at this moment.
Contract.ContractBuilder builder = new Contract.ContractBuilder(Utils.getEmptyStock(Code.newInstance(name), Symbol.newInstance(name)), new SimpleDate(date));
Contract contract = builder.type(Contract.Type.Buy).quantity(unit).price(price).build();
final double brokerFee = brokingFirm.brokerCalculate(contract);
final double clearingFee = brokingFirm.clearingFeeCalculate(contract);
final double stampDuty = brokingFirm.stampDutyCalculate(contract);
jFormattedTextField3.setValue(brokerFee);
jFormattedTextField4.setValue(clearingFee);
jFormattedTextField5.setValue(stampDuty);
jFormattedTextField2.setValue(price * (double)unit);
jFormattedTextField6.setValue(price * (double)unit + brokerFee + clearingFee + stampDuty);
}});
}
else {
SwingUtilities.invokeLater(new Runnable() { public void run() {
final int unit = (Integer)jSpinner1.getValue();
final double price = (Double)jFormattedTextField1.getValue();
final double brokerFee = (Double)jFormattedTextField3.getValue();
final double clearingFee = (Double)jFormattedTextField4.getValue();
final double stampDuty = (Double)jFormattedTextField5.getValue();
jFormattedTextField2.setValue(price * (double)unit);
jFormattedTextField6.setValue(price * (double)unit + brokerFee + clearingFee + stampDuty);
}});
}
}
private void jSpinner1StateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jSpinner1StateChanged
// TODO add your handling code here:
update();
}//GEN-LAST:event_jSpinner1StateChanged
private void jFormattedTextField1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField1FocusLost
// TODO add your handling code here:
update();
}//GEN-LAST:event_jFormattedTextField1FocusLost
private void jFormattedTextField3FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField3FocusLost
// TODO add your handling code here:
update();
}//GEN-LAST:event_jFormattedTextField3FocusLost
private void jFormattedTextField4FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField4FocusLost
// TODO add your handling code here:
update();
}//GEN-LAST:event_jFormattedTextField4FocusLost
private void jFormattedTextField5FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jFormattedTextField5FocusLost
// TODO add your handling code here:
update();
}//GEN-LAST:event_jFormattedTextField5FocusLost
private JFormattedTextField getCurrencyJFormattedTextField() {
NumberFormat format= NumberFormat.getNumberInstance();
NumberFormatter formatter= new NumberFormatter(format);
formatter.setMinimum(0.0);
formatter.setValueClass(Double.class);
JFormattedTextField field= new JFormattedTextField(formatter);
return field;
}
public void setPrice(double price) {
this.jFormattedTextField1.setValue(price);
update();
}
public void setJComboBoxEnabled(boolean enable) {
this.jComboBox1.setEnabled(enable);
}
public void setStockSymbol(Symbol symbol) {
this.jTextField1.setText(symbol.toString());
}
public void setStockSelectionEnabled(boolean flag) {
jComboBox1.setEnabled(flag);
}
public void setStockCodeAndSymbolDatabase(StockCodeAndSymbolDatabase stockCodeAndSymbolDatabase) {
((AutoCompleteJComboBox)jComboBox1).setStockCodeAndSymbolDatabase(stockCodeAndSymbolDatabase);
}
public void initjComboBox1EditorComponentKeyListerner() {
KeyListener[] listeners = this.jComboBox1.getEditor().getEditorComponent().getKeyListeners();
for(KeyListener listener : listeners) {
if(listener == jComboBox1EditorComponentKeyAdapter) {
return;
}
}
// Bug in Java 6. Most probably this listener had been removed during look n feel updating, reassign!
this.jComboBox1.getEditor().getEditorComponent().addKeyListener(jComboBox1EditorComponentKeyAdapter);
log.info("Reassign key adapter to combo box");
}
public Transaction getTransaction() {
return this.transaction;
}
private KeyAdapter getjComboBox1EditorComponentKeyAdapter() {
return new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
if(KeyEvent.VK_ENTER == e.getKeyCode()) {
String stock = NewBuyTransactionJDialog.this.jComboBox1.getEditor().getItem().toString();
if(stock.length() > 0) {
MainFrame m = (MainFrame)NewBuyTransactionJDialog.this.getParent();
if(m == null) return;
final StockCodeAndSymbolDatabase stockCodeAndSymbolDatabase = m.getStockCodeAndSymbolDatabase();
Code code = stockCodeAndSymbolDatabase.searchStockCode(stock);
Symbol symbol = null;
if(code != null) {
symbol = stockCodeAndSymbolDatabase.codeToSymbol(code);
}
else {
symbol = stockCodeAndSymbolDatabase.searchStockSymbol(stock);
if(symbol != null) {
code = stockCodeAndSymbolDatabase.symbolToCode(symbol);
}
}
NewBuyTransactionJDialog.this.jTextField1.setText(symbol.toString());
} /* if(stock.length() > 0) */
} /* if(KeyEvent.VK_ENTER == e.getKeyCode()) */
} /* public void keyReleased(KeyEvent e) */
};
}
private static final Log log = LogFactory.getLog(NewBuyTransactionJDialog.class);
private final KeyListener jComboBox1EditorComponentKeyAdapter = getjComboBox1EditorComponentKeyAdapter();
private Transaction transaction = null;
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JFormattedTextField jFormattedTextField1;
private javax.swing.JFormattedTextField jFormattedTextField2;
private javax.swing.JFormattedTextField jFormattedTextField3;
private javax.swing.JFormattedTextField jFormattedTextField4;
private javax.swing.JFormattedTextField jFormattedTextField5;
private javax.swing.JFormattedTextField jFormattedTextField6;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JSpinner jSpinner1;
private javax.swing.JTextField jTextField1;
// End of variables declaration//GEN-END:variables
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -