KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > debugger > gui > ClassNodeMouseListener


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This file is part of the debugger and core tools for the AspectJ(tm)
4 * programming language; see http://aspectj.org
5 *
6 * The contents of this file are subject to the Mozilla Public License
7 * Version 1.1 (the "License"); you may not use this file except in
8 * compliance with the License. You may obtain a copy of the License at
9 * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is AspectJ.
17 *
18 * The Initial Developer of the Original Code is Xerox Corporation. Portions
19 * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20 * All Rights Reserved.
21 */

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 JavaDoc;
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 JavaDoc breakString = null;
52             List JavaDoc adviceStrings = null;
53             List JavaDoc advisedMethodStrings = null;
54             List JavaDoc classMethodStrings = null;
55             List JavaDoc classAdviceStrings = null;
56             String JavaDoc 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 JavaDoc 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.name();
92
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 JavaDoc stop = "stop in ";
106     private void show(int x, int y,
107                       final boolean isAdvice,
108                       final String JavaDoc breakString,
109                       final List JavaDoc adviceStrings,
110                       final List JavaDoc advisedMethodStrings,
111                       final List JavaDoc classMethodStrings,
112                       final List JavaDoc classAdviceStrings,
113                       final String JavaDoc name) {
114         JPopupMenu menu = new JPopupMenu();
115         if (breakString != null && !breakString.equals("")) {
116             final String JavaDoc adviceOrMethod = isAdvice ? "advice" : "method";
117             final String JavaDoc cmd = stop + breakString;
118             final String JavaDoc 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 JavaDoc title, final String JavaDoc command) {
135         List JavaDoc list = new Vector();
136         list.add(command);
137         add(menu, title, list, "");
138     }
139     private void add(JPopupMenu menu, final String JavaDoc title, final List JavaDoc strings) {
140         add(menu, title, strings, stop);
141     }
142     private void add(JPopupMenu menu, final String JavaDoc title,
143                      final List JavaDoc strings, final String JavaDoc 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 JavaDoc 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