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