KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > ErrorListCellRenderer


1 /*
2  * ErrorListCellRenderer.java - Used to list I/O and plugin load errors
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2001 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.gui;
24
25 //{{{ Imports
26
import javax.swing.*;
27 import javax.swing.border.*;
28 import java.awt.*;
29 //}}}
30

31 class ErrorListCellRenderer extends JComponent implements ListCellRenderer
32 {
33     //{{{ ErrorListCellRenderer constructor
34
ErrorListCellRenderer()
35     {
36         // fucking GTK look and feel!
37
plainFont = new JLabel().getFont();
38         //UIManager.getFont("Label.font");
39
boldFont = new Font(plainFont.getName(),Font.BOLD,plainFont.getSize());
40         plainFM = getFontMetrics(plainFont);
41         boldFM = getFontMetrics(boldFont);
42
43         setBorder(new EmptyBorder(2,2,2,2));
44     } //}}}
45

46     //{{{ getListCellRendererComponent() method
47
public Component getListCellRendererComponent(JList list, Object JavaDoc value,
48         int index, boolean isSelected, boolean cellHasFocus)
49     {
50         ErrorListDialog.ErrorEntry entry = (ErrorListDialog.ErrorEntry)value;
51         this.path = entry.path + ":";
52         this.messages = entry.messages;
53         return this;
54     } //}}}
55

56     //{{{ getPreferredSize() method
57
public Dimension getPreferredSize()
58     {
59         int width = boldFM.stringWidth(path);
60         int height = boldFM.getHeight();
61         for(int i = 0; i < messages.length; i++)
62         {
63             width = Math.max(plainFM.stringWidth(messages[i]),width);
64             height += plainFM.getHeight();
65         }
66
67         Insets insets = getBorder().getBorderInsets(this);
68         width += insets.left + insets.right;
69         height += insets.top + insets.bottom;
70
71         return new Dimension(width,height);
72     } //}}}
73

74     //{{{ paintComponent() method
75
public void paintComponent(Graphics g)
76     {
77         Insets insets = getBorder().getBorderInsets(this);
78         g.setFont(boldFont);
79         g.drawString(path,insets.left,insets.top + boldFM.getAscent());
80         int y = insets.top + boldFM.getHeight() + 2;
81         g.setFont(plainFont);
82         for(int i = 0; i < messages.length; i++)
83         {
84             g.drawString(messages[i],insets.left,y + plainFM.getAscent());
85             y += plainFM.getHeight();
86         }
87     } //}}}
88

89     //{{{ Instance variables
90
private String JavaDoc path;
91     private String JavaDoc[] messages;
92     private Font plainFont;
93     private Font boldFont;
94     private FontMetrics plainFM;
95     private FontMetrics boldFM;
96     //}}}
97
}
98
Popular Tags