1 17 package org.columba.core.gui.scripting; 18 19 import java.util.ArrayList ; 20 import java.util.List ; 21 import java.util.Observable ; 22 import java.util.Observer ; 23 24 import javax.swing.SwingUtilities ; 25 import javax.swing.table.AbstractTableModel ; 26 27 import org.columba.core.scripting.ScriptLogger; 28 29 32 public class ScriptLogTableModel 33 extends AbstractTableModel 34 implements Observer 35 { 36 37 private static final String 38 RES_MESSAGE_COLUMN = "Message"; 39 40 private String [] columns = new String [] 41 { 42 RES_MESSAGE_COLUMN 43 }; 44 45 public static final int 46 MESSAGE_COLUMN = 0; 47 48 private List <ScriptLogger.LogEntry> logList; 49 50 public ScriptLogTableModel() 51 { 52 logList = new ArrayList <ScriptLogger.LogEntry>(); 53 logList.addAll(ScriptLogger.getInstance().dumpCurrentLog()); 54 ScriptLogger.getInstance().addObserver(this); 55 } 56 57 public void clearLog() 58 { 59 logList.clear(); 60 ScriptLogger.getInstance().clear(); 61 fireTableChangedEv(); 62 } 63 64 public int getColumnCount() 65 { 66 return columns.length; 67 } 68 69 public int getRowCount() 70 { 71 return logList.size(); 72 } 73 74 public String getColumnName(int col) 75 { 76 return columns[col]; 77 } 78 79 public Class getColumnClass(int columnIndex) 80 { 81 if (columnIndex == 0) return ScriptLogger.LogEntry.class; 82 else return super.getColumnClass(columnIndex); 83 } 84 85 public Object getValueAt(int row, int col) 86 { 87 switch (col) 88 { 89 case MESSAGE_COLUMN: 90 return logList.get(row); 91 default: 92 return ""; 93 } 94 95 } 96 97 private void fireTableChangedEv() 98 { 99 SwingUtilities.invokeLater(new Runnable () 100 { 101 public void run() 102 { 103 fireTableDataChanged(); 104 } 105 }); 106 } 107 108 public void update(Observable o, Object arg) 109 { 110 fireTableChangedEv(); 111 } 112 113 public void dispose() 114 { 115 ScriptLogger.getInstance().deleteObserver(this); 116 } 117 118 } 119 | Popular Tags |