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             * ID for serialization.
022             */
023            private static final long serialVersionUID = 5154459383072256109L;
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 DefaultCurrencyItemTED.
052         *
053         * @param c the Currency used for formatting. Must be the same as the Currency modelled by the associated
054         * {@link CatalogTableModel}.
055         */
056        public DefaultCurrencyItemTED(Currency c) {
057            super();
058    
059            m_cCurrency = c;
060        }
061    
062        /**
063         * @return <code>String.class</code> for the first, <code>{@link NumberValue}.class</code> for the second
064         * column.
065         * @override Sometimes
066         */
067        public Class<?> getColumnClass(int nIdx) {
068            Class[] acClasses = {
069                    String.class, NumberValue.class};
070            return acClasses[nIdx];
071        }
072    
073        /**
074         * @return <code>null</code> for the first, {@link #getValueRenderer} for the second column.
075         * @override Sometimes
076         */
077        public TableCellRenderer getCellRenderer(int nIdx) {
078            if (nIdx == 1) {
079                return getValueRenderer();
080            } else {
081                return super.getCellRenderer(nIdx);
082            }
083        }
084    }