001    package data.swing;
002    
003    import javax.swing.table.DefaultTableCellRenderer;
004    import javax.swing.JTable;
005    
006    import data.Currency;
007    
008    import data.NumberValue;
009    
010    /**
011     * A cell renderer that takes a {@link NumberValue} and renders it using the formatting capabilities of a
012     * {@link Currency}.
013     *
014     * @author Steffen Zschaler
015     * @version 2.0 23/08/1999
016     * @since v2.0
017     */
018    public class CurrencyRenderer extends DefaultTableCellRenderer {
019    
020        /**
021             * ID for serialization.
022             */
023            private static final long serialVersionUID = 7330291552008413274L;
024            
025            /**
026         * The Currency used to format the rendered values.
027         *
028         * @serial
029         */
030        protected Currency m_cCurrency;
031    
032        /**
033         * Create a new CurrencyRenderer.
034         *
035         * @param c the Currency to be used for formatting.
036         */
037        public CurrencyRenderer(Currency c) {
038            super();
039    
040            m_cCurrency = c;
041    
042            setHorizontalAlignment(RIGHT);
043        }
044    
045        /**
046         * @override Never
047         */
048        public java.awt.Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
049                boolean hasFocus, int row, int column) {
050            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
051            setText(m_cCurrency.toString((NumberValue)value));
052    
053            return this;
054        }
055    }