KickJava   Java API By Example, From Geeks To Geeks.

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


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
23 package org.aspectj.debugger.gui;
24
25 import org.aspectj.debugger.base.*;
26
27 import com.sun.jdi.*;
28 import java.awt.event.ActionEvent JavaDoc;
29 import java.awt.event.ActionListener JavaDoc;
30 import javax.swing.JMenuItem JavaDoc;
31
32 public class AJValueNodeMenu extends AJTreeNodeMenu {
33
34     private AJValueNode valueNode;
35     private JMenuItem JavaDoc menuItemChange = new JMenuItem JavaDoc("Change value");
36     private JMenuItem JavaDoc menuItemWatch = new JMenuItem JavaDoc("Set watchpoint");
37     private JMenuItem JavaDoc menuItemHex = new JMenuItem JavaDoc();
38
39     public AJValueNodeMenu() {
40         this(null);
41     }
42
43     public AJValueNodeMenu(AJValueNode valueNode) {
44         super();
45         setValueNode(valueNode);
46         add(menuItemWatch());
47         add(menuItemChange());
48         if (valueNode instanceof HexableAJValueNode) add(menuItemHex());
49     }
50
51
52     public void setValueNode(AJValueNode valueNode) {
53         this.valueNode = valueNode;
54         if (valueNode == null) {
55             menuItemWatch.setEnabled(false);
56             menuItemChange.setEnabled(false);
57         } else if (!valueNode.canSetWatchPoint()) {
58             menuItemWatch.setEnabled(false);
59             menuItemChange.setEnabled(true);
60         } else {
61             boolean canSetWatchPoint = true;
62             try {
63                 VirtualMachine vm = ComponentRepository.vm();
64                 canSetWatchPoint = vm.canWatchFieldAccess() &&
65                                    vm.canWatchFieldModification();
66             } catch (NoVMException e) {}
67             menuItemWatch.setEnabled(canSetWatchPoint);
68             menuItemChange.setEnabled(true);
69         }
70     }
71
72     private JMenuItem JavaDoc menuItemChange() {
73         menuItemChange.addActionListener( new ActionListener JavaDoc() {
74             public void actionPerformed(ActionEvent JavaDoc e) {
75                 setValue();
76             }});
77         return menuItemChange;
78     }
79
80     private JMenuItem JavaDoc menuItemWatch() {
81         menuItemWatch.addActionListener( new ActionListener JavaDoc() {
82             public void actionPerformed(ActionEvent JavaDoc e) {
83                 setWatchPoint();
84             }});
85         return menuItemWatch;
86     }
87
88     private JMenuItem JavaDoc menuItemHex() {
89         menuItemHex.setText("To " + (((HexableAJValueNode) valueNode).isHex()
90                                       ? "decimal" : "hex"));
91         menuItemHex.addActionListener( new ActionListener JavaDoc() {
92             public void actionPerformed(ActionEvent JavaDoc e) {
93                 toHex();
94             }});
95         return menuItemHex;
96     }
97
98     private void setWatchPoint() {
99         if (valueNode == null) return;
100         if (!valueNode.canSetWatchPoint()) return;
101         valueNode.setWatchPoint();
102     }
103
104     private void setValue() {
105         if (valueNode == null) return;
106         valueNode.setValue();
107     }
108
109     private void toHex() {
110         if (valueNode == null) return;
111         if (!(valueNode instanceof HexableAJValueNode)) return;
112         ((HexableAJValueNode) valueNode).toggle();
113     }
114 }
Popular Tags