You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CompilerMessagesCellRenderer.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v 2.0
  7. * which accompanies this distribution and is available at
  8. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * Helen Hawkins Converted to new interface (bug 148190)
  13. * ******************************************************************/
  14. package org.aspectj.ajde.ui.swing;
  15. import java.awt.Component;
  16. import javax.swing.JLabel;
  17. import javax.swing.JList;
  18. import javax.swing.ListCellRenderer;
  19. import org.aspectj.ajde.Ajde;
  20. import org.aspectj.bridge.IMessage;
  21. import org.aspectj.util.LangUtil;
  22. /**
  23. * @author Mik Kersten
  24. */
  25. public class CompilerMessagesCellRenderer extends JLabel implements ListCellRenderer {
  26. private static final long serialVersionUID = -4406791252357837712L;
  27. public Component getListCellRendererComponent(
  28. JList list,
  29. Object value,
  30. int index,
  31. boolean isSelected,
  32. boolean cellHasFocus) {
  33. String label = "<no message>";
  34. String detail = null;
  35. IMessage.Kind kind = IMessage.ERROR;
  36. if (value instanceof IMessage) {
  37. IMessage cm = (IMessage) value;
  38. label = cm.getMessage();
  39. if (LangUtil.isEmpty(label)) {
  40. label = cm.getMessage();
  41. }
  42. kind = cm.getKind();
  43. Throwable thrown = cm.getThrown();
  44. if (null != thrown) {
  45. detail = LangUtil.renderException(thrown);
  46. }
  47. } else if (null != value) {
  48. label = value.toString();
  49. }
  50. setText(label);
  51. if (kind.equals(IMessage.WARNING)) {
  52. setIcon(Ajde.getDefault().getIconRegistry().getWarningIcon());
  53. } else if (IMessage.ERROR.isSameOrLessThan(kind)) {
  54. setIcon(Ajde.getDefault().getIconRegistry().getErrorIcon());
  55. } else {
  56. setIcon(Ajde.getDefault().getIconRegistry().getInfoIcon());
  57. }
  58. if (isSelected) {
  59. setBackground(list.getSelectionBackground());
  60. setForeground(list.getSelectionForeground());
  61. } else {
  62. setBackground(list.getBackground());
  63. setForeground(list.getForeground());
  64. }
  65. setEnabled(list.isEnabled());
  66. setFont(list.getFont());
  67. setOpaque(true);
  68. if (null != detail) {
  69. setToolTipText(detail);
  70. }
  71. return this;
  72. }
  73. }