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