001 package data.swing; 002 003 import data.*; 004 005 import javax.swing.table.*; 006 007 /** 008 * A {@link util.swing.TableEntryDescriptor} that can be used to model MoneyBags with a 009 * {@link CountingStockTableModel}. 010 * 011 * <p>Essentially this is a {@link DefaultCountingStockItemTED} that renders its value column using a 012 * Currency to format the values.</p> 013 * 014 * @author Steffen Zschaler 015 * @version 2.0 23/08/1999 016 * @since v2.0 017 */ 018 public class DefaultMoneyBagItemTED extends DefaultCountingStockItemTED { 019 020 /** 021 * ID for serialization. 022 */ 023 private static final long serialVersionUID = 5111628598155861152L; 024 025 /** 026 * The Currency used for formatting. 027 * 028 * @serial 029 */ 030 private Currency m_cCurrency; 031 032 /** 033 * The cell renderer that renders the value column. 034 */ 035 private transient TableCellRenderer m_tcrValueRenderer; 036 037 /** 038 * Internal helper function that gets (and if necessary creates) the cell renderer for the value column. 039 * 040 * @override Never 041 */ 042 protected TableCellRenderer getValueRenderer() { 043 if (m_tcrValueRenderer == null) { 044 m_tcrValueRenderer = new CurrencyRenderer(m_cCurrency); 045 } 046 047 return m_tcrValueRenderer; 048 } 049 050 /** 051 * Create a new DefaultMoneyBagItemTED. 052 * 053 * @param c the Currency used for formatting. Must be the same as the Currency of the MoneyBag modelled by 054 * the associated {@link CountingStockTableModel}. 055 */ 056 public DefaultMoneyBagItemTED(Currency c) { 057 super(); 058 059 m_cCurrency = c; 060 } 061 062 /** 063 * @return <code>{@link NumberValue}.class</code> for the second column, otherwise the superclass' return 064 * values. 065 * @override Sometimes 066 */ 067 public Class<?> getColumnClass(int nIdx) { 068 if (nIdx == 1) { 069 return NumberValue.class; 070 } else { 071 return super.getColumnClass(nIdx); 072 } 073 } 074 075 /** 076 * @return <code>null</code> for the first, {@link #getValueRenderer} for the second column. 077 * @override Sometimes 078 */ 079 public TableCellRenderer getCellRenderer(int nIdx) { 080 if (nIdx == 1) { 081 return getValueRenderer(); 082 } else { 083 return super.getCellRenderer(nIdx); 084 } 085 } 086 }