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