PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/org/gjt/sp/jedit/gui/ErrorListCellRenderer.java

#
Java | 97 lines | 56 code | 10 blank | 31 comment | 2 complexity | c5f0989e665e1ddfa15b243c9c7caab2 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package org.gjt.sp.jedit.gui;
  23. //{{{ Imports
  24. import javax.swing.*;
  25. import javax.swing.border.*;
  26. import java.awt.*;
  27. //}}}
  28. class ErrorListCellRenderer extends JComponent implements ListCellRenderer
  29. {
  30. //{{{ ErrorListCellRenderer constructor
  31. ErrorListCellRenderer()
  32. {
  33. // fucking GTK look and feel!
  34. plainFont = new JLabel().getFont();
  35. //UIManager.getFont("Label.font");
  36. boldFont = new Font(plainFont.getName(),Font.BOLD,plainFont.getSize());
  37. plainFM = getFontMetrics(plainFont);
  38. boldFM = getFontMetrics(boldFont);
  39. setBorder(new EmptyBorder(2,2,2,2));
  40. } //}}}
  41. //{{{ getListCellRendererComponent() method
  42. public Component getListCellRendererComponent(JList list, Object value,
  43. int index, boolean isSelected, boolean cellHasFocus)
  44. {
  45. ErrorListDialog.ErrorEntry entry = (ErrorListDialog.ErrorEntry)value;
  46. this.path = entry.path + ":";
  47. this.messages = entry.messages;
  48. return this;
  49. } //}}}
  50. //{{{ getPreferredSize() method
  51. public Dimension getPreferredSize()
  52. {
  53. int width = boldFM.stringWidth(path);
  54. int height = boldFM.getHeight();
  55. for(int i = 0; i < messages.length; i++)
  56. {
  57. width = Math.max(plainFM.stringWidth(messages[i]),width);
  58. height += plainFM.getHeight();
  59. }
  60. Insets insets = getBorder().getBorderInsets(this);
  61. width += insets.left + insets.right;
  62. height += insets.top + insets.bottom;
  63. return new Dimension(width,height);
  64. } //}}}
  65. //{{{ paintComponent() method
  66. public void paintComponent(Graphics g)
  67. {
  68. Insets insets = getBorder().getBorderInsets(this);
  69. g.setFont(boldFont);
  70. g.drawString(path,insets.left,insets.top + boldFM.getAscent());
  71. int y = insets.top + boldFM.getHeight() + 2;
  72. g.setFont(plainFont);
  73. for(int i = 0; i < messages.length; i++)
  74. {
  75. g.drawString(messages[i],insets.left,y + plainFM.getAscent());
  76. y += plainFM.getHeight();
  77. }
  78. } //}}}
  79. //{{{ Instance variables
  80. private String path;
  81. private String[] messages;
  82. private Font plainFont;
  83. private Font boldFont;
  84. private FontMetrics plainFM;
  85. private FontMetrics boldFM;
  86. //}}}
  87. }