001: /*
002: * Created on 16/03/2005 Swing Components - visit http://sf.net/projects/gfd
003: * Copyright (C) 2004 Igor Regis da Silva Simões This program is free software;
004: * you can redistribute it and/or modify it under the terms of the GNU General
005: * Public License as published by the Free Software Foundation; either version 2
006: * of the License, or (at your option) any later version. This program is
007: * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
008: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
009: * PARTICULAR PURPOSE. See the GNU General Public License for more details. You
010: * should have received a copy of the GNU General Public License along with this
011: * program; if not, write to the Free Software Foundation, Inc., 59 Temple Place -
012: * Suite 330, Boston, MA 02111-1307, USA.
013: */
014: package br.com.gfp.windows.componentes;
015:
016: import java.awt.Component;
017: import java.util.HashMap;
018:
019: import javax.swing.JList;
020:
021: import br.com.gfpshare.beans.DBComboBoxRenderer;
022: import br.com.gfpshare.db.formatter.GeneralFormatter;
023:
024: /**
025: * @author Igor Regis da Silva Simoes - f4353008
026: * @since 16/03/2005 19:01:40
027: */
028: public class GFPComboBoxRenderer extends DBComboBoxRenderer {
029: /**
030: *
031: */
032: public static final int TIPO_DE_CONTA = GFPTableCellRenderer.TIPO_CONTA;
033:
034: /**
035: *
036: */
037: private static GeneralFormatter formatter = new GeneralFormatter();
038:
039: /**
040: *
041: */
042: private HashMap<String, Object> cache = new HashMap<String, Object>();
043:
044: /**
045: *
046: */
047: private HashMap<Integer, String> tiposDeDados = new HashMap<Integer, String>();
048:
049: /**
050: * Cria uma nova instância de DBComboBoxRenderer
051: *
052: * @param format
053: * @param toolTip
054: */
055: public GFPComboBoxRenderer(int format, int toolTip) {
056: super (format, toolTip);
057:
058: tiposDeDados.put(GFPTableCellRenderer.BANCO, "Bank");
059: tiposDeDados.put(GFPTableCellRenderer.BEM, "Assets");
060: tiposDeDados.put(GFPTableCellRenderer.ENTIDADE, "Contact");
061: tiposDeDados
062: .put(GFPTableCellRenderer.LANCAMENTO, "Transaction");
063: tiposDeDados.put(GFPTableCellRenderer.TIPO_LANCAMENTO,
064: "TransactionType");
065: tiposDeDados.put(GFPTableCellRenderer.NUMERO_CONTA_CORRENTE,
066: "NumeroContaCorrente");
067: tiposDeDados.put(GFPTableCellRenderer.NUMERO_AGENCIA,
068: "NumeroAgencia");
069: tiposDeDados
070: .put(GFPTableCellRenderer.APLICACAO, "AccoutSaving");
071: tiposDeDados.put(GFPTableCellRenderer.CONTA_CORRENTE,
072: "CheckingAccount");
073: tiposDeDados.put(GFPTableCellRenderer.TIPO_DE_RENDIMENTO,
074: "IncomeType");
075: tiposDeDados.put(GFPTableCellRenderer.TIPO_REPETICAO,
076: "RepetitioType");
077: tiposDeDados
078: .put(GFPTableCellRenderer.TIPO_CONTA, "AccountType");
079: }
080:
081: /**
082: * @see javax.swing.plaf.basic.BasicComboBoxRenderer#getListCellRendererComponent(javax.swing.JList,
083: * java.lang.Object, int, boolean, boolean)
084: */
085: @Override
086: public Component getListCellRendererComponent(JList list,
087: Object value, int index, boolean isSelected,
088: boolean cellHasFocus) {
089: super .getListCellRendererComponent(list, value, index,
090: isSelected, cellHasFocus);
091:
092: Object valor = null;
093:
094: // Se não for null e não estiver no Cache... ( o cache é usado para
095: // evitar consultas redundantes ao banco de dados)
096: if (value != null
097: && (!(value instanceof String))
098: && (valor = cache.get(value.toString() + getFormat())) == null) {
099: if (tiposDeDados.get(new Integer(getFormat())) != null) {
100: valor = formatter.format(value,
101: GeneralFormatter.FORMATO_CURTO, tiposDeDados
102: .get(new Integer(getFormat()))
103: .toString());
104: cache.put(value.toString() + getFormat(), valor);
105: }
106: }
107:
108: if (valor != null)
109: setText(valor.toString());
110:
111: return this;
112: }
113: }
|