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