Commit 1f44e903 authored by Christophe Demarey's avatar Christophe Demarey

Update GUI to add peso conversion.

parent 418c7a22
......@@ -33,6 +33,7 @@ import java.awt.event.KeyListener;
import java.text.NumberFormat;
import java.util.Locale;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
......@@ -50,7 +51,7 @@ import org.ow2.frascati.explorer.gui.AbstractSelectionPanel;
@SuppressWarnings("serial")
public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
private NumberFormat nf; // used to format double display
private JLabel jLabelDollar;
private JComboBox jComboBoxCurrency;
private JLabel jLabelEuro;
private JFormattedTextField jTextFieldDollar;
private JFormattedTextField jTextFieldEuro;
......@@ -67,7 +68,7 @@ public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
nf.setMaximumFractionDigits(4);
jLabelEuro = new JLabel();
jLabelDollar = new JLabel();
jComboBoxCurrency = new JComboBox( new String[] { "Dollar", "Colombian Peso" } );
euroFormat = NumberFormat.getCurrencyInstance(Locale.FRANCE);
dollarFormat = NumberFormat.getCurrencyInstance(Locale.US);
jTextFieldEuro = new JFormattedTextField(euroFormat);
......@@ -75,8 +76,7 @@ public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
jLabelEuro.setText("Euro");
jLabelEuro.setName("jLabelEuro");
jLabelDollar.setText("Dollar");
jLabelDollar.setName("jLabelDollar");
jComboBoxCurrency.setName("jComboBoxCurrency");
jTextFieldEuro.setName("jTextFieldEuro");
jTextFieldDollar.setName("jTextFieldDollar");
......@@ -84,36 +84,31 @@ public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
GroupLayout mainPanelLayout = new GroupLayout(this);
this.setLayout(mainPanelLayout);
mainPanelLayout.setHorizontalGroup(
mainPanelLayout.createParallelGroup(GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.add(mainPanelLayout.createParallelGroup(GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(mainPanelLayout.createParallelGroup(GroupLayout.CENTER)
.add(jLabelEuro)
.add(jTextFieldEuro, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE))
.add(18, 18, 18)
.add(mainPanelLayout.createParallelGroup(GroupLayout.CENTER)
.add(jLabelDollar)
.add(jTextFieldDollar, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE))))
.addContainerGap(607, Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(20, 20, 20)
.add(mainPanelLayout.createParallelGroup(GroupLayout.TRAILING)
.add(mainPanelLayout.createSequentialGroup()
.add(jLabelDollar)
.addPreferredGap(LayoutStyle.RELATED)
.add(jTextFieldDollar, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.add(mainPanelLayout.createSequentialGroup()
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.addContainerGap()
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
.add(jLabelEuro)
.addPreferredGap(LayoutStyle.RELATED)
.add(jTextFieldEuro, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(LayoutStyle.RELATED)
.addContainerGap(545, Short.MAX_VALUE))
);
.add(jTextFieldEuro, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE))
.add(23, 23, 23)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
.add(jTextFieldDollar, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
.add(jComboBoxCurrency, 0, 140, Short.MAX_VALUE))
.addContainerGap(520, Short.MAX_VALUE))
);
mainPanelLayout.setVerticalGroup(
mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(mainPanelLayout.createSequentialGroup()
.add(21, 21, 21)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER)
.add(jComboBoxCurrency, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabelEuro))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(mainPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextFieldDollar, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jTextFieldEuro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.addContainerGap(556, Short.MAX_VALUE))
);
// actions
jTextFieldEuro.addKeyListener( new KeyListener() {
......@@ -127,8 +122,13 @@ public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
if (text.length() > 0) {
Double value = parseDouble(text);
if (value != null) {
Double result;
jTextFieldEuro.setValue(value);
Double result = selected.euroToDollar(value);
if (jComboBoxCurrency.getSelectedIndex() == 0)
result = selected.euroToDollar(value);
else
result = selected.euroToPeso(value);
jTextFieldDollar.setValue(result);
}
}
......@@ -145,9 +145,14 @@ public class ConverterPanel extends AbstractSelectionPanel<CurrencyConverter> {
if ( e.getKeyCode() == KeyEvent.VK_ENTER ) {
String text = jTextFieldDollar.getText();
if (text.length() > 0) {
Double result;
Double value = parseDouble(text);
jTextFieldDollar.setValue(value);
Double result = selected.dollarToEuro(value);
if (jComboBoxCurrency.getSelectedIndex() == 0)
result = selected.dollarToEuro(value);
else
result = selected.pesoToEuro(value);
jTextFieldEuro.setValue(result);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment