001: /*
002: * Created on 10/07/2004
003: *
004: * Swing Components - visit http://sf.net/projects/gfd
005: *
006: * Copyright (C) 2004 Igor Regis da Silva Simões
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or (at your option) any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package br.com.gfp.data;
024:
025: import java.text.ParseException;
026:
027: import javax.swing.text.MaskFormatter;
028:
029: import br.com.gfp.dao.GFPController;
030: import br.com.gfp.internationalization.TelaContaCorrenteMessages;
031: import br.com.gfp.util.SimpleLog;
032: import br.com.gfpshare.db.formatter.Formatter;
033:
034: /**
035: * Classe que formata um Numero de Account Corrente
036: * @author Igor Regis da Silva Simoes
037: */
038: public class NumeroContaCorrenteFormatter implements Formatter {
039:
040: private MaskFormatter formato;
041:
042: /** Cria uma nova instância de NumeroContaCorrenteFormatter */
043: public NumeroContaCorrenteFormatter() {
044: try {
045: formato = new MaskFormatter(TelaContaCorrenteMessages
046: .getMessages().getString("mascaraContaCorrente"));
047: formato.setValidCharacters(TelaContaCorrenteMessages
048: .getMessages().getString(
049: "caracteresValidosContaCorrente"));
050: formato.setPlaceholderCharacter('0');
051: formato.setValueContainsLiteralCharacters(false);
052: } catch (ParseException e) {
053: ((SimpleLog) GFPController.getGFPController().getContexto()
054: .get(GFPController.LOG))
055: .log("Erro ao criar objeto de formatação de numero de conta corrente");
056: ((SimpleLog) GFPController.getGFPController().getContexto()
057: .get(GFPController.LOG)).log(e
058: .getLocalizedMessage());
059: ((SimpleLog) GFPController.getGFPController().getContexto()
060: .get(GFPController.LOG)).log(e);
061: }
062: }
063:
064: /**
065: * @see br.com.gfpshare.db.formatter.Formatter#parse(java.lang.String, java.lang.String)
066: */
067: public Object parse(String dado, String dataType) {
068: try {
069: return formato.stringToValue(dado.toString());
070: } catch (ParseException e) {
071: ((SimpleLog) GFPController.getGFPController().getContexto()
072: .get(GFPController.LOG))
073: .log("Erro ao formatar numero de conta corrente: "
074: + dado);
075: ((SimpleLog) GFPController.getGFPController().getContexto()
076: .get(GFPController.LOG)).log(e
077: .getLocalizedMessage());
078: ((SimpleLog) GFPController.getGFPController().getContexto()
079: .get(GFPController.LOG)).log(e);
080: }
081: return null;
082: }
083:
084: /**
085: * @see br.com.gfpshare.db.formatter.Formatter#format(java.lang.Object, int, java.lang.String)
086: */
087: public String format(Object objeto, int tipo, String dataType) {
088: try {
089: return formato.valueToString(objeto);
090: } catch (ParseException e) {
091: ((SimpleLog) GFPController.getGFPController().getContexto()
092: .get(GFPController.LOG))
093: .log("Erro ao formatar numero de conta corrente: "
094: + objeto);
095: ((SimpleLog) GFPController.getGFPController().getContexto()
096: .get(GFPController.LOG)).log(e
097: .getLocalizedMessage());
098: ((SimpleLog) GFPController.getGFPController().getContexto()
099: .get(GFPController.LOG)).log(e);
100: }
101: return null;
102: }
103: }
|