001 package market.swing;
002
003 import java.util.List;
004
005 import javax.swing.table.AbstractTableModel;
006
007 import market.Conversions;
008 import market.statistics.HistoryEntry;
009
010 /**
011 * TableModel for tables that display {@link HistoryEntry HistoryEntries}.
012 */
013 public class HistoryEntryModel extends AbstractTableModel {
014
015 public final static int PRICE_HISTORY = 0;
016 public final static int ORDER_HISTORY = 1;
017
018 private List data;
019 private int type;
020
021 /**
022 * @param data the history to be displayed
023 * @param type the kind of history:
024 * <ul><li>0: interpreted as {@link market.statistics.CISalesStats#priceHistory}</li>
025 * <li>1: interpreted as {@link market.statistics.CISalesStats#orderHistory}</li></ul>
026 */
027 public HistoryEntryModel(List data, int type) {
028 super();
029 this.data = data;
030 this.type = type;
031 }
032
033 /**
034 * @param i the affected column.
035 * @return columns' names.
036 */
037 public String getColumnName(int i) {
038 return new String[] {"Datum", type == 0 ? "Preis" : "Bestellt"}[i];
039 }
040
041 /**
042 * @return the number of the table's rows.
043 */
044 public int getRowCount() {
045 return data.size();
046 }
047
048 /**
049 * @return the number of the table's columns.
050 */
051 public int getColumnCount() {
052 return 2;
053 }
054
055 /**
056 * @param column the affected column.
057 * @return columns' classes. They indicate how column's values should be aligned.
058 */
059 public Class getColumnClass(int column) {
060 return String.class;
061 }
062
063 /**
064 * @param row the affected row.
065 * @param column the affected column.
066 * @return the table cell's value.
067 */
068 public Object getValueAt(int row, int column) {
069 HistoryEntry oRecord = (HistoryEntry)data.get(row);
070 switch (column) {
071 case 0:
072 return oRecord.getDate();
073 case 1:
074 return type == 0 ? Conversions.doubleToCurrency(oRecord.getValue()) :
075 Integer.toString(oRecord.getValue());
076 default:
077 return "";
078 }
079 }
080 }