01: /*
02: * ErrorListCellRenderer.java - Used to list I/O and plugin load errors
03: * :tabSize=8:indentSize=8:noTabs=false:
04: * :folding=explicit:collapseFolds=1:
05: *
06: * Copyright (C) 2001 Slava Pestov
07: *
08: * This program is free software; you can redistribute it and/or
09: * 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:
32: class ErrorListCellRenderer extends JComponent implements
33: ListCellRenderer {
34: //{{{ ErrorListCellRenderer constructor
35: ErrorListCellRenderer() {
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
40: .getSize());
41: plainFM = getFontMetrics(plainFont);
42: boldFM = getFontMetrics(boldFont);
43:
44: setBorder(new EmptyBorder(2, 2, 2, 2));
45: } //}}}
46:
47: //{{{ getListCellRendererComponent() method
48: public Component getListCellRendererComponent(JList list,
49: Object value, int index, boolean isSelected,
50: boolean cellHasFocus) {
51: ErrorListDialog.ErrorEntry entry = (ErrorListDialog.ErrorEntry) value;
52: this .path = entry.path + ":";
53: this .messages = entry.messages;
54: return this ;
55: } //}}}
56:
57: //{{{ getPreferredSize() method
58: public Dimension getPreferredSize() {
59: int width = boldFM.stringWidth(path);
60: int height = boldFM.getHeight();
61: for (int i = 0; i < messages.length; i++) {
62: width = Math.max(plainFM.stringWidth(messages[i]), width);
63: height += plainFM.getHeight();
64: }
65:
66: Insets insets = getBorder().getBorderInsets(this );
67: width += insets.left + insets.right;
68: height += insets.top + insets.bottom;
69:
70: return new Dimension(width, height);
71: } //}}}
72:
73: //{{{ paintComponent() method
74: public void paintComponent(Graphics g) {
75: Insets insets = getBorder().getBorderInsets(this );
76: g.setFont(boldFont);
77: g
78: .drawString(path, insets.left, insets.top
79: + boldFM.getAscent());
80: int y = insets.top + boldFM.getHeight() + 2;
81: g.setFont(plainFont);
82: for (int i = 0; i < messages.length; i++) {
83: g.drawString(messages[i], insets.left, y
84: + plainFM.getAscent());
85: y += plainFM.getHeight();
86: }
87: } //}}}
88:
89: //{{{ Instance variables
90: private String path;
91: private String[] messages;
92: private Font plainFont;
93: private Font boldFont;
94: private FontMetrics plainFM;
95: private FontMetrics boldFM;
96: //}}}
97: }
|