import javax.swing.table.AbstractTableModel; /** * A messy, non-reusable (outside of this application) TableModel used to render the tables. Due to 'performance reasons', * swing has a very roundabout way of populating tables. * * @author Cormac Redmond -- credmond85 /at/ gmail */ public class ClientUITimetableTableModel extends AbstractTableModel { private int rowCount; private boolean[] data; private boolean[][] data2d; private Object[] dataGeneric; private javax.swing.JComboBox drpRoomList; private String available; private String notAvailable; private String[] columnNames = {"Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sun",}; public ClientUITimetableTableModel(boolean[] data, int rowCount) { this.rowCount = rowCount; this.data = data; } public ClientUITimetableTableModel(boolean[][] data, int rowCount) { this.available = "-click-"; this.notAvailable = "BOOKED"; this.rowCount = rowCount; this.data2d = data; } public ClientUITimetableTableModel(boolean[][] data, int rowCount, String notAvailable, String available) { this.available = available; this.notAvailable = notAvailable; this.rowCount = rowCount; this.data2d = data; } public ClientUITimetableTableModel(Object[] data, int rowCount) { this.rowCount = rowCount; this.dataGeneric = data; columnNames[0] = "Room(s)"; } public ClientUITimetableTableModel(javax.swing.JComboBox drpRoomList, int rowCount) { this.rowCount = rowCount; this.drpRoomList = drpRoomList; columnNames[0] = "Room(s)"; } public int getColumnCount() { if (dataGeneric != null) return 1; else if (drpRoomList != null) return 1; else return columnNames.length; } public int getRowCount() { return rowCount; } public String getColumnName(int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { if (data != null) { if (data[col] == false) return "-click-"; else return "BOOKED"; } else if (data2d != null) { if (data2d[row][col] == false) return available; else return notAvailable; } else if (dataGeneric != null) { return dataGeneric[row].toString(); } else if (drpRoomList != null) { return drpRoomList.getItemAt(row + 2).toString(); } return null; } }