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 Agencia
036: * @author Igor Regis da Silva Simoes
037: */
038: public class NumeroAgenciaFormatter implements Formatter {
039:
040: private MaskFormatter formato;
041:
042: /** Cria uma nova instância de NumeroAgenciaFormatter */
043: public NumeroAgenciaFormatter() {
044: try {
045: formato = new MaskFormatter(TelaContaCorrenteMessages
046: .getMessages().getString("mascaraAgencia"));
047: formato.setValidCharacters(TelaContaCorrenteMessages
048: .getMessages()
049: .getString("caracteresValidosAgencia"));
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 Agencia");
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 agencia: " + dado);
074: ((SimpleLog) GFPController.getGFPController().getContexto()
075: .get(GFPController.LOG)).log(e
076: .getLocalizedMessage());
077: ((SimpleLog) GFPController.getGFPController().getContexto()
078: .get(GFPController.LOG)).log(e);
079: }
080: return null;
081: }
082:
083: /**
084: * @see br.com.gfpshare.db.formatter.Formatter#format(java.lang.Object, int, java.lang.String)
085: */
086: public String format(Object objeto, int tipo, String dataType) {
087: try {
088: return formato.valueToString(objeto);
089: } catch (ParseException e) {
090: ((SimpleLog) GFPController.getGFPController().getContexto()
091: .get(GFPController.LOG))
092: .log("Erro ao formatar numero de agencia: "
093: + objeto);
094: ((SimpleLog) GFPController.getGFPController().getContexto()
095: .get(GFPController.LOG)).log(e
096: .getLocalizedMessage());
097: ((SimpleLog) GFPController.getGFPController().getContexto()
098: .get(GFPController.LOG)).log(e);
099: }
100: return null;
101: }
102: }
|