KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > scripting > ScriptLogTableModel


1 /*
2  The contents of this file are subject to the Mozilla Public License Version 1.1
3  (the "License"); you may not use this file except in compliance with the License.
4  You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
6  Software distributed under the License is distributed on an "AS IS" basis,
7  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8  for the specific language governing rights and limitations under the License.
9
10  The Original Code is "The Columba Project"
11
12  The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
13  Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
14
15  All Rights Reserved.
16  */

17 package org.columba.core.gui.scripting;
18
19 import java.util.ArrayList JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.Observable JavaDoc;
22 import java.util.Observer JavaDoc;
23
24 import javax.swing.SwingUtilities JavaDoc;
25 import javax.swing.table.AbstractTableModel JavaDoc;
26
27 import org.columba.core.scripting.ScriptLogger;
28
29 /**
30     @author Celso Pinto (cpinto@yimports.com)
31  */

32 public class ScriptLogTableModel
33     extends AbstractTableModel JavaDoc
34     implements Observer JavaDoc
35 {
36
37     private static final String JavaDoc
38         RES_MESSAGE_COLUMN = "Message";
39
40     private String JavaDoc[] columns = new String JavaDoc[]
41         {
42             RES_MESSAGE_COLUMN
43         };
44
45     public static final int
46         MESSAGE_COLUMN = 0;
47
48     private List JavaDoc<ScriptLogger.LogEntry> logList;
49
50     public ScriptLogTableModel()
51     {
52         logList = new ArrayList JavaDoc<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 JavaDoc getColumnName(int col)
75     {
76         return columns[col];
77     }
78
79     public Class JavaDoc getColumnClass(int columnIndex)
80     {
81         if (columnIndex == 0) return ScriptLogger.LogEntry.class;
82         else return super.getColumnClass(columnIndex);
83     }
84
85     public Object JavaDoc 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 JavaDoc()
100         {
101             public void run()
102             {
103                 fireTableDataChanged();
104             }
105         });
106     }
107
108     public void update(Observable JavaDoc o, Object JavaDoc arg)
109     {
110         fireTableChangedEv();
111     }
112
113     public void dispose()
114     {
115         ScriptLogger.getInstance().deleteObserver(this);
116     }
117
118 }
119
Popular Tags