/*
 * Copyright © 2000-2005 Canoo Engineering AG, Switzerland.
 */
package format;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.text.NumberFormat;
import java.util.Locale;


public class SwingDollarInCurrencyDataTypeSnippet  {
	  public void start() {
            NumberFormat paymentFormat = NumberFormat.getCurrencyInstance();
	        JFormattedTextField textField = new JFormattedTextField(paymentFormat);

            textField.setValue(new Double(50.00));
            JPanel content = new JPanel(new BorderLayout());
	        content.add(textField, BorderLayout.NORTH);
	        content.add(new JButton(new ShowValueAction(textField)), BorderLayout.SOUTH);
	        JTabbedPane tab = new JTabbedPane();
            tab.add(content);
            tab.add(new JLabel("Label"));
	        JFrame frame = new JFrame("SwingDollarInCurrencyDataTypeSnippet");
	        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        frame.getContentPane().add(tab);
            frame.setSize(200,200);
	        frame.setVisible(true);
	    }

	    private static class ShowValueAction extends AbstractAction {
	        private JFormattedTextField fTextField;

	        public ShowValueAction(JFormattedTextField textField) {
	            fTextField = textField;
	            putValue(Action.NAME, "Show Value");
               
	        }

            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                Object value = fTextField.getValue();
                System.out.println("value = " + value);
                System.out.println("value.getClass() = " + (value == null ? null : value.getClass().getName()));
                fTextField.setEditable(fTextField.isEditable());
                
            }
	    }
	    
	    
	    
    
    public static void main(String[] args) {
    	Locale l = new Locale("fr", "CA");
    	l.setDefault(l);
        new SwingDollarInCurrencyDataTypeSnippet().start();
    }
}