1 4 package com.nightlabs.rcp.composite; 5 6 import java.text.ParseException ; 7 8 import org.eclipse.jface.dialogs.MessageDialog; 9 import org.eclipse.swt.SWT; 10 import org.eclipse.swt.events.ModifyEvent; 11 import org.eclipse.swt.events.ModifyListener; 12 import org.eclipse.swt.widgets.Composite; 13 import org.eclipse.swt.widgets.Label; 14 import org.eclipse.swt.widgets.Text; 15 16 import com.nightlabs.l10n.Currency; 17 import com.nightlabs.l10n.NumberFormatter; 18 19 22 public class CurrencyEditComposite extends TightWrapperComposite 23 { 24 private Currency currency; 25 private Text numberText; 26 private long value; 27 28 31 public CurrencyEditComposite(Composite parent, Currency _currency) 32 { 33 super(parent, SWT.NONE, true); 34 this.currency = _currency; 35 36 getGridLayout().numColumns = 2; 37 numberText = new Text(this, SWT.BORDER); 38 setValue(0); 39 new Label(this, SWT.NONE).setText(currency.getCurrencySymbol()); 40 41 numberText.addModifyListener(new ModifyListener(){ 42 45 public void modifyText(ModifyEvent e) 46 { 47 String s = numberText.getText(); 48 try { 49 value = NumberFormatter.parseCurrency(s, currency, false); 50 } catch (ParseException x) { 51 MessageDialog.openError(getShell(), "Invalid text!", "The text you entered is not a valid number: " + x.getLocalizedMessage()); 52 } 53 } 54 }); 55 } 56 57 public void setValue(long currencyValue) 58 { 59 this.value = currencyValue; 60 numberText.setText( 61 NumberFormatter.formatCurrency(currencyValue, currency, false)); 62 } 63 64 public long getValue() 65 { 66 return value; 67 } 68 69 72 public Currency getCurrency() 73 { 74 return currency; 75 } 76 } 77 | Popular Tags |