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 Currencies with a
009     * {@link CatalogTableModel}.
010     *
011     * <p>Essentially this is a {@link DefaultCatalogItemTED} that renders its value column using the Currency to
012     * format the values.</p>
013     *
014     * @author Steffen Zschaler
015     * @version 2.0 23/08/1999
016     * @since v2.0
017     */
018    public class DefaultCurrencyItemTED extends DefaultCatalogItemTED {
019    
020        /**
021         * The Currency used for formatting.
022         *
023         * @serial
024         */
025        private Currency m_cCurrency;
026    
027        /**
028         * The cell renderer that renders the value column.
029         */
030        private transient TableCellRenderer m_tcrValueRenderer;
031    
032        /**
033         * Internal helper function that gets (and if necessary creates) the cell renderer for the value column.
034         *
035         * @override Never
036         */
037        protected TableCellRenderer getValueRenderer() {
038            if (m_tcrValueRenderer == null) {
039                m_tcrValueRenderer = new CurrencyRenderer(m_cCurrency);
040            }
041    
042            return m_tcrValueRenderer;
043        }
044    
045        /**
046         * Create a new DefaultCurrencyItemTED.
047         *
048         * @param c the Currency used for formatting. Must be the same as the Currency modelled by the associated
049         * {@link CatalogTableModel}.
050         */
051        public DefaultCurrencyItemTED(Currency c) {
052            super();
053    
054            m_cCurrency = c;
055        }
056    
057        /**
058         * @return <code>String.class</code> for the first, <code>{@link NumberValue}.class</code> for the second
059         * column.
060         * @override Sometimes
061         */
062        public Class getColumnClass(int nIdx) {
063            Class[] acClasses = {
064                    String.class, NumberValue.class};
065            return acClasses[nIdx];
066        }
067    
068        /**
069         * @return <code>null</code> for the first, {@link #getValueRenderer} for the second column.
070         * @override Sometimes
071         */
072        public TableCellRenderer getCellRenderer(int nIdx) {
073            if (nIdx == 1) {
074                return getValueRenderer();
075            } else {
076                return super.getCellRenderer(nIdx);
077            }
078        }
079    }