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.awt.*;
30
import java.text.*;
31
import java.util.*;
32
import java.util.logging.*;
33
import javax.swing.*;
34
import javax.swing.table.DefaultTableCellRenderer;
35
 
36
public class LogTableCellRenderer extends DefaultTableCellRenderer {
37
 
38
   private Color defaultBackground;
39
   private Color defaultForeground;
40
 
41
   private static final DateFormat DATE_FORMAT;
42
 
43
   static {
44
 
45
      DATE_FORMAT = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss.SSS");
46
 
47
   }
48
 
49
   public LogTableCellRenderer() {
50
      super();
51
      defaultBackground = getBackground();
52
      defaultForeground = getForeground();
53
   }
54
 
55
   public Component getTableCellRendererComponent(JTable table, Object value,
56
      boolean isSelected, boolean hasFocus, int row, int column) {
57
 
58
      String text = null;
59
 
60
      switch(column) {
61
         case 0:
62
            text = DATE_FORMAT.format(new Date(((LogRecord)value).getMillis()));
63
            break;
64
         case 1:
65
            text = ((LogRecord)value).getLevel().toString();
66
            break;
67
         case 2:
68
            LogRecord record = (LogRecord)value;
69
 
70
            if(record.getMessage() == null) {
71
               text =  "No Message...";
72
            } else {
73
               text = record.getMessage();
74
            }
75
 
76
            if(!(text.startsWith("Sending") || text.startsWith("Received"))) {
77
               StringBuffer buffer = new StringBuffer(text);
78
 
79
               buffer.append(" ");
80
               if(record.getSourceClassName() != null) {
81
                  buffer.append(record.getSourceClassName());
82
               }
83
 
84
               if(record.getSourceMethodName() != null) {
85
                  buffer.append(":");
86
                  buffer.append(record.getSourceMethodName());
87
               }
88
               buffer.append(" ");
89
 
90
               text = buffer.toString();
91
            }
92
 
93
            break;
94
      }
95
 
96
      super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
97
 
98
      if(!isSelected) {
99
         if(((LogRecord)value).getLevel().equals(Level.SEVERE)) {
100
            setBackground(Color.RED.darker());
101
            setForeground(Color.WHITE);
102
         } else if(((LogRecord)value).getLevel().equals(Level.WARNING)) {
103
            setBackground(Color.ORANGE);
104
            setForeground(Color.BLACK);
105
         } else if(((LogRecord)value).getLevel().equals(Level.INFO)) {
106
            setBackground(Color.YELLOW);
107
            setForeground(Color.BLACK);
108
         } else if(((LogRecord)value).getLevel().equals(Level.CONFIG)) {
109
            setBackground(Color.CYAN);
110
            setForeground(Color.BLACK);
111
         } else {
112
            setBackground(defaultBackground);
113
            setForeground(defaultForeground);
114
         }
115
      }
116
 
117
      if(column != 2) {
118
         setHorizontalAlignment(JLabel.CENTER);
119
      } else {
120
         setHorizontalAlignment(JLabel.LEFT);
121
      }
122
 
123
      return this;
124
 
125
   }
126
}