001    package videoautomat;
002    
003    import util.swing.AbstractTableEntryDescriptor;
004    
005    /**
006     * This class implements a TableEntryDescriptor used to display rented {@link VideoCassette}s
007     *  
008     */
009    public class TEDVideoCassette extends AbstractTableEntryDescriptor {
010    
011            /**
012             * ID for Serialization.
013             */
014            private static final long serialVersionUID = 5824064237889692447L;
015    
016            /**
017             * @return the number of columns each record will consist of.
018             * 
019             * @see util.swing.TableEntryDescriptor#getColumnCount()
020             */
021            public int getColumnCount() {
022                    return 3;
023            }
024    
025            /**
026             * @return the text to be printed in the header of the given column.
027             * @param nIdx
028             *                  the index of the column for which to return the header. Indices run from 0 to
029             *                  {@link TEDVideoCassette#getColumnCount()}- 1.
030             * @see util.swing.TableEntryDescriptor#getColumnName(int)
031             */
032            public String getColumnName(int nIdx) {
033                    switch (nIdx) {
034                            case 0 :
035                                    return "Title";
036                            case 1 :
037                                    return "Days";
038                            case 2 :
039                                    return "Cost";
040                    }
041                    return null;
042            }
043    
044            /**
045             * @return the class of objects that make up the values of cells of the given column. This will be used to
046             *              determine the cell renderer and editor unless you specify otherwise through
047             *              util.swing.AbstractTableEntryDescriptor#getCellEditor(int) and
048             *              util.swing.AbstractTableEntryDescriptor#getCellRenderer(int).
049             * @param nIdx
050             *                  the index of the column for which to return the header. Indices run from 0 to
051             *                  {@link TEDVideoCassette#getColumnCount()}- 1.
052             * @see util.swing.TableEntryDescriptor#getColumnClass(int)
053             */
054            public Class<?> getColumnClass(int nIdx) {
055                    switch (nIdx) {
056                            case 0 :
057                                    return String.class;
058                            case 1 :
059                                    return Integer.class;
060                            case 2 :
061                                    return String.class;
062                    }
063                    return null;
064            }
065    
066            /**
067             * @return the value to be printed in the given column for the given record. The actual class must be a subclass of
068             *              what was returned by {@link TEDVideoCassette#getColumnClass(int)}or that class itself.
069             * @param nIdx
070             *                  the index of the column for which to return the header. Indices run from 0 to
071             *                  {@link TEDVideoCassette#getColumnCount()}- 1.
072             * @see util.swing.TableEntryDescriptor#getValueAt(java.lang.Object, int)
073             */
074            public Object getValueAt(Object oRecord, int nIdx) {
075                    VideoCassette vc = (VideoCassette) oRecord;
076                    switch (nIdx) {
077                            case 0 :
078                                    return vc.getName();
079                            case 1 :
080                                    return new Integer(vc.getDays());
081                            case 2 :
082                                    return VideoShop.getCurrency().toString(vc.getCost());
083                    }
084                    return null;
085            }
086    }