1 22 23 package org.gjt.sp.jedit.gui; 24 25 import javax.swing.*; 27 import javax.swing.border.*; 28 import java.awt.*; 29 31 class ErrorListCellRenderer extends JComponent implements ListCellRenderer 32 { 33 ErrorListCellRenderer() 35 { 36 plainFont = new JLabel().getFont(); 38 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 } 46 public Component getListCellRendererComponent(JList list, Object 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 } 56 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 } 74 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 } 89 private String path; 91 private String [] messages; 92 private Font plainFont; 93 private Font boldFont; 94 private FontMetrics plainFM; 95 private FontMetrics boldFM; 96 } 98 | Popular Tags |