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.

CompilerMessagesPanel.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.tools.ajbrowser;
  14. import java.awt.BorderLayout;
  15. import java.awt.event.*;
  16. import javax.swing.*;
  17. import org.aspectj.ajde.*;
  18. import org.aspectj.ajde.ui.swing.*;
  19. import org.aspectj.bridge.*;
  20. import org.aspectj.bridge.IMessage.Kind;
  21. /**
  22. * Used to display a list of compiler messages that can be clicked in order
  23. * to seek to their corresponding sourceline.
  24. *
  25. * @author Mik Kersten
  26. */
  27. public class CompilerMessagesPanel extends JPanel implements TaskListManager {
  28. private static final long serialVersionUID = -2251912345065588977L;
  29. private JScrollPane jScrollPane1 = new JScrollPane();
  30. //private JScrollPane jScrollPane2 = new JScrollPane();
  31. private JList list = new JList();
  32. private DefaultListModel listModel = new DefaultListModel();
  33. private BorderLayout borderLayout1 = new BorderLayout();
  34. private boolean hasWarning = false;
  35. public CompilerMessagesPanel() {
  36. try {
  37. jbInit();
  38. }
  39. catch(Exception e) {
  40. e.printStackTrace();
  41. }
  42. list.setModel(listModel);
  43. MouseListener mouseListener = new MouseAdapter() {
  44. public void mouseClicked(MouseEvent e) {
  45. if (e.getClickCount() >= 1) {
  46. int index = list.locationToIndex(e.getPoint());
  47. if (listModel.getSize() >= index && index != -1) {
  48. IMessage message = (IMessage)listModel.getElementAt(index);
  49. Ajde.getDefault().getEditorAdapter().showSourceLine(message.getSourceLocation(), true);
  50. }
  51. }
  52. }
  53. };
  54. list.addMouseListener(mouseListener);
  55. list.setCellRenderer(new CompilerMessagesCellRenderer());
  56. }
  57. public void addSourcelineTask(IMessage message) {
  58. listModel.addElement(message);
  59. checkIfWarning(message.getKind());
  60. }
  61. public void addSourcelineTask(String message, ISourceLocation sourceLocation, IMessage.Kind kind) {
  62. listModel.addElement(new Message(message, kind, null, sourceLocation));
  63. checkIfWarning(kind);
  64. }
  65. public void addProjectTask(String message, IMessage.Kind kind) {
  66. listModel.addElement(new Message(message, kind, null, null));
  67. checkIfWarning(kind);
  68. }
  69. private void checkIfWarning(Kind kind) {
  70. if (kind.equals(IMessage.WARNING)) hasWarning = true;
  71. }
  72. public void clearTasks() {
  73. listModel.clear();
  74. hasWarning = false;
  75. }
  76. private void jbInit() throws Exception {
  77. this.setLayout(borderLayout1);
  78. this.add(jScrollPane1, BorderLayout.CENTER);
  79. jScrollPane1.getViewport().add(list, null);
  80. }
  81. public boolean hasWarning() {
  82. return hasWarning;
  83. }
  84. }