001: /*
002: * Created on 01/05/2004
003: *
004: * ============================================================================
005: * GNU Lesser General Public License
006: * ============================================================================
007: *
008: * Swing Components - visit http://sf.net/projects/gfd
009: *
010: * Copyright (C) 2004 Igor Regis da Silva Simões
011: *
012: * This library is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU Lesser General Public
014: * License as published by the Free Software Foundation; either
015: * version 2.1 of the License, or (at your option) any later version.
016: *
017: * This library is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
020: * Lesser General Public License for more details.
021: *
022: * You should have received a copy of the GNU Lesser General Public
023: * License along with this library; if not, write to the Free Software
024: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
025: */
026:
027: package br.com.igor.beans;
028:
029: import java.awt.Color;
030: import java.awt.Component;
031:
032: import javax.swing.JList;
033: import javax.swing.plaf.basic.BasicComboBoxRenderer;
034:
035: import br.com.igor.db.PersistentObject;
036:
037: /**
038: * Este componente renderiza itens de uma DBComboBox em vários formatos, dependendo do parametro passado em seu contrutor
039: * @author Igor Regis da Silva Simões
040: */
041: public class DBComboBoxRenderer extends BasicComboBoxRenderer {
042: private int format = PersistentObject.CURTO;
043:
044: private int toolTip = PersistentObject.MEDIO;
045:
046: /**
047: * Cria uma nova instância de DBComboBoxRenderer
048: */
049: public DBComboBoxRenderer() {
050: //Não fazemos nada
051: }
052:
053: /**
054: * Cria uma nova instância de DBComboBoxRenderer
055: * @param format
056: */
057: public DBComboBoxRenderer(int format) {
058: this .format = format;
059: }
060:
061: /**
062: * Cria uma nova instância de DBComboBoxRenderer
063: * @param format
064: * @param toolTip
065: */
066: public DBComboBoxRenderer(int format, int toolTip) {
067: this .format = format;
068: this .toolTip = toolTip;
069: }
070:
071: /**
072: * @see javax.swing.plaf.basic.BasicComboBoxRenderer#getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, boolean, boolean)
073: */
074: @Override
075: public Component getListCellRendererComponent(JList list,
076: Object value, int index, boolean isSelected,
077: boolean cellHasFocus) {
078: super .getListCellRendererComponent(list, value, index,
079: isSelected, cellHasFocus);
080:
081: if (value instanceof PersistentObject) {
082: setText(((PersistentObject) value).getAsString(format));
083: setToolTipText(((PersistentObject) value)
084: .getAsString(toolTip));
085: } else
086: setToolTipText("");
087:
088: if (value != null
089: && value.toString().trim().equals("< INSERT NEW >")) {
090: setText(PaginadorDeTabelaMessages.getMessages().getString(
091: "INSERT_NEW"));
092: setForeground(Color.RED);
093: setToolTipText(PaginadorDeTabelaMessages.getMessages()
094: .getString("INSERT_NEW_TOOLTIP"));
095: } else
096: setForeground(Color.BLACK);
097:
098: return this ;
099: }
100:
101: /**
102: * Formato em que será apresentado a informação
103: * @return
104: */
105: public int getFormat() {
106: return format;
107: }
108:
109: /**
110: * Formato em que será apresentado a informação
111: * @param format
112: */
113: public void setFormat(int format) {
114: this.format = format;
115: }
116: }
|