1 22 package org.aspectj.debugger.gui; 23 24 import org.aspectj.debugger.base.*; 25 import java.awt.event.*; 26 import java.util.*; 27 import java.util.List ; 28 import javax.swing.*; 29 import javax.swing.tree.*; 30 31 public class ClassNodeMouseListener extends MouseAdapter { 32 33 protected JTree tree; 34 protected GUIDebugger guiDebugger; 35 36 public ClassNodeMouseListener(GUIDebugger guiDebugger, JTree tree) { 37 this.guiDebugger = guiDebugger; 38 this.tree = tree; 39 } 40 41 public void mouseClicked(MouseEvent e) { 42 int x = e.getX(); 43 int y = e.getY(); 44 int selRow = tree.getRowForLocation(x, y); 45 TreePath path = tree.getPathForLocation(x, y); 46 if (path == null) return; 47 if (SwingUtilities.isRightMouseButton(e)) { 48 49 AJTreeNode treeNode = (AJTreeNode) path.getLastPathComponent(); 50 51 String breakString = null; 52 List adviceStrings = null; 53 List advisedMethodStrings = null; 54 List classMethodStrings = null; 55 List classAdviceStrings = null; 56 String name = null; 57 boolean isAdvice = true; 58 59 if (treeNode instanceof MethodNode) { 60 isAdvice = false; 61 } 62 63 if (treeNode instanceof Breakable) { 64 Breakable breakable = (Breakable) treeNode; 65 breakString = breakable.getBreakpoint(); 66 final String cmd = "stop in " + breakString; 67 JPopupMenu menu = new JPopupMenu(); 68 JMenuItem item = new JMenuItem(cmd); 69 item.addActionListener(new ActionListener() { 70 public void actionPerformed(ActionEvent _) { 71 ComponentRepository.getAJDebugger().execute(cmd); 72 } 73 }); 74 menu.add(item); 75 menu.show(tree, x, y); 76 } 77 78 if (treeNode instanceof Advisedable) { 79 Advisedable advisedable = (Advisedable) treeNode; 80 adviceStrings = advisedable.getAdviceStrings(); 81 } 82 83 if (treeNode instanceof Advisable) { 84 Advisable advisable = (Advisable) treeNode; 85 advisedMethodStrings = advisable.getAdvisedMethodStrings(); 86 } 87 88 if (treeNode instanceof ClassNode) { 89 ClassNode classNode = (ClassNode) treeNode; 90 classMethodStrings = classNode.getMethodStrings(); 91 name = classNode.fullName(); 93 } 94 if (treeNode instanceof AJCClassNode) { 95 AJCClassNode ajcClassNode = (AJCClassNode) treeNode; 96 classAdviceStrings = ajcClassNode.getAdviceStrings(); 97 } 98 99 show(x, y, isAdvice, breakString, adviceStrings, advisedMethodStrings, 100 classMethodStrings, classAdviceStrings, name); 101 } else if (SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) { 102 } 103 } 104 105 final static String stop = "stop in "; 106 private void show(int x, int y, 107 final boolean isAdvice, 108 final String breakString, 109 final List adviceStrings, 110 final List advisedMethodStrings, 111 final List classMethodStrings, 112 final List classAdviceStrings, 113 final String name) { 114 JPopupMenu menu = new JPopupMenu(); 115 if (breakString != null && !breakString.equals("")) { 116 final String adviceOrMethod = isAdvice ? "advice" : "method"; 117 final String cmd = stop + breakString; 118 final String title = cmd; 119 menu.add(new AbstractAction(title) { 120 public void actionPerformed(ActionEvent _) { 121 ComponentRepository.getAJDebugger().execute(cmd); 122 }}); 123 } 124 add(menu, "stop in all advice", adviceStrings); 125 add(menu, "stop in all advised methods", advisedMethodStrings); 126 add(menu, "stop in all declared methods", classMethodStrings); 127 add(menu, "stop in all declared advice", classAdviceStrings); 128 if (name != null && !name.equals("null")) { 129 add(menu, "run class " + name, "run " + name); 130 } 131 menu.show(tree, x, y); 132 } 133 134 private void add(JPopupMenu menu, final String title, final String command) { 135 List list = new Vector(); 136 list.add(command); 137 add(menu, title, list, ""); 138 } 139 private void add(JPopupMenu menu, final String title, final List strings) { 140 add(menu, title, strings, stop); 141 } 142 private void add(JPopupMenu menu, final String title, 143 final List strings, final String prefix) { 144 if (strings == null || strings.size() == 0) return; 145 menu.add(new AbstractAction(title) { 146 public void actionPerformed(ActionEvent _) { 147 for (int i = 0; i < strings.size(); i++) { 148 Object command = strings.get(i); 149 if (command != null && !(command+"").equals("null")) 150 guiDebugger.getDebugger().execute(prefix + command); 151 } 152 } 153 }); 154 } 155 156 protected JTree tree() { 157 return tree; 158 } 159 160 } 161 | Popular Tags |