1 33 34 package com.nqadmin.swingSet.formatting; 35 36 import javax.swing.text.NumberFormatter ; 37 import java.text.NumberFormat ; 38 import java.util.Locale ; 39 40 import java.io.Serializable ; 41 import java.text.ParseException ; 42 43 47 public class SSCurrencyFormatterFactory extends javax.swing.text.DefaultFormatterFactory implements Serializable { 48 49 53 54 public SSCurrencyFormatterFactory() { 55 this.setDefaultFormatter(new NumberFormatter (NumberFormat.getCurrencyInstance())); 56 this.setNullFormatter(null); 57 this.setEditFormatter(new NumberFormatter (NumberFormat.getInstance(Locale.US))); 58 this.setDisplayFormatter(new NumberFormatter (NumberFormat.getCurrencyInstance())); 59 } 60 61 public SSCurrencyFormatterFactory(int precision, int decimals) { 62 NumberFormat nfd = NumberFormat.getCurrencyInstance(Locale.US); 63 nfd.setMaximumFractionDigits(decimals); 64 nfd.setMinimumFractionDigits(decimals); 65 66 nfd.setMaximumIntegerDigits(precision); 67 nfd.setMinimumIntegerDigits(1); 68 69 this.setDefaultFormatter(new NumberFormatter (NumberFormat.getCurrencyInstance())); 70 this.setNullFormatter(null); 71 this.setEditFormatter(new NumberFormatter (NumberFormat.getInstance(Locale.US))); 72 this.setDisplayFormatter(new NumberFormatter (nfd)); 73 } 74 75 public SSCurrencyFormatterFactory(int precision, int decimals, Locale editor_locale, Locale display_locale) { 76 77 NumberFormat nfe = NumberFormat.getCurrencyInstance(editor_locale); 78 nfe.setMaximumFractionDigits(decimals); 79 nfe.setMinimumFractionDigits(decimals); 80 nfe.setMaximumIntegerDigits(precision); 81 nfe.setMinimumIntegerDigits(1); 82 this.setEditFormatter(new NumberFormatter (nfe)); 83 84 NumberFormat nfd = NumberFormat.getCurrencyInstance(display_locale); 85 nfd.setMaximumFractionDigits(decimals); 86 nfd.setMinimumFractionDigits(decimals); 87 nfd.setMaximumIntegerDigits(precision); 88 nfd.setMinimumIntegerDigits(1); 89 this.setDisplayFormatter(new NumberFormatter (nfd)); 90 91 this.setDefaultFormatter(new NumberFormatter (NumberFormat.getCurrencyInstance())); 92 this.setNullFormatter(null); 93 94 } 95 96 } 97 98 116 | Popular Tags |