1 package ist.coach.coachEmfClientComponents.gui; 2 3 import javax.swing.table.AbstractTableModel ; 4 import java.util.Vector ; 5 6 class AlarmTableModel extends AbstractTableModel { 7 8 final String [] columnNames = {" Time ", 9 " Event Type ", 10 " Source Type ", 11 " Source ", 12 " Alarm Id ", 13 " Details " 14 }; 15 16 Vector data; 17 protected static int NUM_COLUMNS = 6; 18 protected static int TIME_C = 0; 19 protected static int EVENT_C = 1; 20 protected static int SOURCE_T_C = 2; 21 protected static int SOURCE_C = 3; 22 protected static int ID_C = 4; 23 protected static int DETAILS_C = 5; 24 25 private int nextEmptyRow = 0; 26 private static int START_NUM_ROWS = 20; 27 int numRows = 0; 28 29 AlarmTableModel() { 30 31 data = new Vector (); 32 } 33 34 public int getColumnCount() { 35 return columnNames.length; 36 } 37 38 public int getRowCount() { 39 40 if (numRows < START_NUM_ROWS) 41 return START_NUM_ROWS; 42 else 43 return numRows; 44 } 45 46 public String getColumnName(int col) { 47 48 return columnNames[col]; 49 } 50 51 public Object getValueAt(int row, int col) { 52 53 try { 54 AlarmRecord alarmR = (AlarmRecord) data.elementAt(row); 55 56 switch(col) { 57 case 0: 58 return alarmR.timeR; 59 case 1: 60 return alarmR.eventType; 61 case 2: 62 return alarmR.sourceClass; 63 case 3: 64 return alarmR.source; 65 case 4: 66 return alarmR.notifId; 67 case 5: 68 return alarmR.details; 69 } 70 } 71 catch(Exception e) {} 72 73 return new String (); 74 75 } 76 77 83 public Class getColumnClass(int c) { 84 return getValueAt(0, c).getClass(); 85 } 86 87 91 public boolean isCellEditable(int row, int col) { 92 return false; 93 } 94 95 public void updateAlarmTable(String dateR, String eventType, 96 String source, String sourceClass, 97 String notifId, String details) { 98 99 AlarmRecord alarmR = new AlarmRecord(dateR, eventType, source, 100 sourceClass,notifId, details); 101 102 data.addElement(alarmR); 103 104 numRows++; 105 fireTableRowsInserted(nextEmptyRow, nextEmptyRow); 106 nextEmptyRow++; 107 } 108 109 public synchronized void clear() { 110 111 int oldNumRows = numRows; 112 113 numRows = START_NUM_ROWS; 114 data.removeAllElements(); 115 nextEmptyRow = 0; 116 117 if (oldNumRows > START_NUM_ROWS) 118 fireTableRowsDeleted(START_NUM_ROWS, oldNumRows - 1); 119 120 fireTableRowsUpdated(0, START_NUM_ROWS - 1); 121 } 122 123 public void printDebugData() { 124 int numRows = getRowCount(); 125 126 AlarmRecord record ; 127 for (int i=0; i < numRows; i++) { 128 System.err.println("------> AlarmRecord" + i + " <-----------"); 129 record = (AlarmRecord) data.get(i); 130 record.print(); 131 } 132 } 133 134 private class AlarmRecord { 135 136 String timeR = null; 137 String notifId = null; 138 String eventType = null; 139 String source = null; 140 String sourceClass = null; 141 String details = null; 142 143 AlarmRecord() {} 144 AlarmRecord(String timeR, String eventType, String source, 145 String sourceClass, String notifId, String details) { 146 147 148 this.timeR = timeR; 149 this.notifId = notifId; 150 this.eventType = eventType; 151 this.source = source; 152 this.sourceClass = sourceClass; 153 this.details = details; 154 } 155 156 void print() { 157 System.err.println("Time =" + timeR + 158 "\tEvent Type =" + eventType + 159 "\tSource = " + source + 160 "\tSourceClass = " + sourceClass + 161 "\tId = " + notifId + 162 "\tDetails = " + details); 163 } 164 165 } 166 } 167 168 | Popular Tags |