Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
157 kaklik 1
/*
2
    AVRcamVIEW: A PC application to test out the functionallity of the
3
     AVRcam real-time image processing engine.
4
    Copyright (C) 2004    Brent A. Taylor
5
 
6
    This program is free software; you can redistribute it and/or
7
    modify it under the terms of the GNU General Public
8
    License as published by the Free Software Foundation; either
9
    version 2 of the License, or (at your option) any later version.
10
 
11
    This program is distributed in the hope that it will be useful,
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
    General Public License for more details.
15
 
16
    You should have received a copy of the GNU General Public
17
    License along with this program; if not, write to the Free Software
18
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
20
   For more information on the AVRcamVIEW, please contact:
21
 
22
   taylorba@comcast.net
23
 
24
   or go to www.jrobot.net for more details regarding the system.
25
*/
26
 
27
package avr.swing.table;
28
 
29
import java.util.*;
30
import java.util.logging.*;
31
import javax.swing.table.*;
32
 
33
public class LogTableModel extends AbstractTableModel {
34
 
35
   public static final String[] COLUMN_NAMES = {
36
      "Time Stamp",
37
      "Level",
38
      "Message"
39
   };
40
 
41
   private List allRecords;
42
   private List filteredRecords;
43
 
44
   private Level level;
45
   private boolean selectedLabel;
46
 
47
   public LogTableModel(Level filterLevel) {
48
      this(filterLevel, false);
49
   }
50
 
51
   public LogTableModel(Level filterLevel, boolean selectedLabel) {
52
      super();
53
      allRecords = new ArrayList(10);
54
      filteredRecords = new ArrayList(10);
55
      this.level = filterLevel;
56
   }
57
 
58
   public void setFilter(Level level) {
59
      this.level = level;
60
      filteredRecords = new ArrayList(allRecords.size());
61
      Iterator i = allRecords.iterator();
62
      LogRecord record = null;
63
      while(i.hasNext()) {
64
         record = (LogRecord)i.next();
65
         if(selectedLabel) {
66
            if(level.intValue() == record.getLevel().intValue()) {
67
               filteredRecords.add(record);
68
            }
69
         } else {
70
            if(level.intValue() <= record.getLevel().intValue()) {
71
               filteredRecords.add(record);
72
            }
73
         }
74
      }
75
      fireTableDataChanged();
76
   }
77
 
78
   public void setOnlyShowSelectedLevel(boolean selectedLabel) {
79
      this.selectedLabel = selectedLabel;
80
      setFilter(level);
81
   }
82
 
83
   public void addRecord(LogRecord record) {
84
      allRecords.add(record);
85
      if(selectedLabel) {
86
         if(level.intValue() == record.getLevel().intValue()) {
87
            filteredRecords.add(record);
88
         }
89
      } else {
90
         if(level.intValue() <= record.getLevel().intValue()) {
91
            filteredRecords.add(record);
92
         }
93
      }
94
      this.fireTableRowsInserted(filteredRecords.size() - 1, filteredRecords.size() - 1);
95
   }
96
 
97
   public void clear() {
98
      allRecords.clear();
99
      filteredRecords.clear();
100
      fireTableDataChanged();
101
   }
102
 
103
   public int getRowCount() {
104
      return filteredRecords.size();
105
   }
106
 
107
   public int getColumnCount() {
108
      return COLUMN_NAMES.length;
109
   }
110
 
111
   public String getColumnName(int col) {
112
      return COLUMN_NAMES[col];
113
   }
114
 
115
   public Class getColumnClass(int col) {
116
      return String.class;
117
   }
118
 
119
   public Object getValueAt(int rowIndex, int columnIndex) {
120
      return filteredRecords.get(rowIndex);
121
   }
122
 
123
   public LogRecord getRecord(int row) {
124
      return (LogRecord)allRecords.get(row);
125
   }
126
 
127
   public int getRecordCount() {
128
      return allRecords.size();
129
   }
130
 
131
}