KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > core > gui > logdisplay > LogRecordListRenderer


1 //The contents of this file are subject to the Mozilla Public License Version 1.1
2
//(the "License"); you may not use this file except in compliance with the
3
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
4
//
5
//Software distributed under the License is distributed on an "AS IS" basis,
6
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
7
//for the specific language governing rights and
8
//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
package org.columba.core.gui.logdisplay;
17
18 import java.awt.Color JavaDoc;
19 import java.awt.Component JavaDoc;
20 import java.util.logging.Level JavaDoc;
21 import java.util.logging.LogRecord JavaDoc;
22
23 import javax.swing.JLabel JavaDoc;
24 import javax.swing.JList JavaDoc;
25 import javax.swing.ListCellRenderer JavaDoc;
26
27 /**
28  * A list cell renderer for the LogRecordList.
29  *
30  * @author redsolo
31  */

32 public class LogRecordListRenderer extends JLabel JavaDoc implements ListCellRenderer JavaDoc {
33
34     /**
35      * Creates the list cell renderer.
36      */

37     public LogRecordListRenderer() {
38         super();
39         setOpaque(true);
40     }
41
42     /** {@inheritDoc} */
43     public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
44
45         LogRecord JavaDoc record = (LogRecord JavaDoc) value;
46
47         if (record.getLevel() == Level.SEVERE) {
48             setForeground(Color.RED);
49         } else if (record.getLevel() == Level.WARNING) {
50             setForeground(Color.ORANGE);
51         } else {
52             setForeground(list.getForeground());
53         }
54
55         if (isSelected) {
56             setBackground(list.getSelectionBackground());
57         } else {
58             setBackground(list.getBackground());
59         }
60
61         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
62         /*
63          * buffer.append(getShortClassName(record.getSourceClassName()));
64          * buffer.append("."); buffer.append(record.getSourceMethodName());
65          * buffer.append(" - ");
66          */

67         buffer.append(record.getMessage());
68
69         setText(buffer.toString());
70
71         return this;
72     }
73
74     /*private String getShortClassName(String className) {
75         String name = "";
76
77         if (className != null) {
78             int lastPos = className.lastIndexOf('.');
79             if (lastPos != -1) {
80                 name = className.substring(lastPos + 1);
81             }
82         }
83
84         return name;
85     }*/

86
87     // The following methods override the defaults for performance reasons
88

89     /** {@inheritDoc} */
90     public void validate() {
91     }
92
93     /** {@inheritDoc} */
94     public void revalidate() {
95     }
96
97     /** {@inheritDoc} */
98     protected void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue) {
99     }
100
101     /** {@inheritDoc} */
102     public void firePropertyChange(String JavaDoc propertyName, boolean oldValue, boolean newValue) {
103     }
104
105 }
106
Popular Tags