1 22 23 package org.aspectj.debugger.gui; 24 25 import com.sun.jdi.*; 26 import com.sun.jdi.event.*; 27 import com.sun.jdi.request.*; 28 import org.aspectj.debugger.base.*; 29 import org.aspectj.debugger.request.*; 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.util.*; 33 import java.util.List ; 34 import javax.swing.*; 35 import javax.swing.event.*; 36 import javax.swing.tree.*; 37 import javax.swing.plaf.*; 38 import javax.swing.plaf.basic.*; 39 40 public class VariablesTreePane 41 extends AJPanel 42 implements StopListener 43 { 44 45 private VariablesTree tree = null; 46 47 public VariablesTreePane(Frame frame, GUIDebugger guid) { 48 super(guid); 49 debugger().addStopListener(this); 50 setLayout(new BorderLayout()); 51 add(new JScrollPane(tree = new VariablesTree(frame)), 52 BorderLayout.CENTER); 53 54 } 55 56 57 public void accessWatchpointEvent(AccessWatchpointEvent e) { 58 updateLocals(); 59 } 60 public void breakpointEvent(BreakpointEvent e) { 61 updateLocals(); 62 } 63 public void exceptionEvent(ExceptionEvent e) { 64 updateLocals(); 65 } 66 public void modificationWatchpointEvent(ModificationWatchpointEvent e) { 67 updateLocals(); 68 } 69 public void stepEvent(StepEvent e) { 70 updateLocals(); 71 } 72 73 private DefaultMutableTreeNode getRoot() { 74 return (DefaultMutableTreeNode) tree.getModel().getRoot(); 75 } 76 77 private void newRoot() { 78 model().setRoot(new VariablesRootTreeNode()); 79 } 80 81 private DefaultTreeModel model() { 82 return (DefaultTreeModel) tree.getModel(); 83 } 84 85 private void updateLocals() { 86 newRoot(); 87 List locals = debugger().locals(); 88 Iterator iter; 89 iter = locals.iterator(); 90 while (iter.hasNext()) { 91 try { 92 add(AJValueNodeFactory.make((LocalVariable) iter.next(), 93 debugger.getDefaultFrame())); 94 } catch (Exception e) { AJUtil.ex(e); 95 } 96 } 97 try { 98 ObjectReference oref = debugger().getDefaultThisObject(); 99 ReferenceType refType = debugger().getDefaultFrame().location().declaringType(); 100 List fields = refType.fields(); 101 iter = fields.iterator(); 102 while (iter.hasNext()) { 103 Field field = (Field) iter.next(); 104 if (shouldAddField(field)) { 105 if (oref != null) { 106 add(AJValueNodeFactory.make(oref, field)); 107 } else if (field.isStatic()) { 108 add(AJValueNodeFactory.make(refType, field)); 109 } 110 } 111 } 112 } catch (Exception e) { AJUtil.ex(e); 113 } 114 tree.expandRow(0); 115 } 116 117 private boolean shouldAddField(Field field) { 118 return field != null && (field.name().indexOf("$ajc") == -1); 119 } 120 121 private void add(MutableTreeNode node) { 122 boolean expand = getRoot().getChildCount() == 0; 123 getRoot().add(node); 124 } 127 128 public static String d() { return "Variables Tree Pane"; } 129 public String toString() { return d(); } 130 } 131 132 class VariablesTree extends AJTree { 133 private Frame frame = null; 134 public VariablesTree(Frame frame) { 135 super(new VariablesTreeModel()); 136 this.frame = frame; 137 setCellRenderer(new VariablesTreeCellRenderer()); 138 addTreeWillExpandListener(new NoCollapsingRootExpansionListener(this)); 139 } 140 public void clear() { 141 setModel(new VariablesTreeModel()); 142 } 143 } 144 145 class VariablesTreeCellRenderer extends AJTreeCellRenderer { 146 } 147 148 class VariablesTreeModel extends DefaultTreeModel { 149 public VariablesTreeModel() { 150 super(new VariablesRootTreeNode()); 151 } 152 } 153 154 class VariablesRootTreeNode extends AJRootNode { 155 public VariablesRootTreeNode() { 156 super(Titles.VARIABLES, AJIcons.VARIABLES_ICON); 157 } 158 } 159 160 161 162 class VariablesTreeNode extends AJTreeNode { 163 public VariablesTreeNode(Object o) { 164 super(AJIcons.BAD_ICON); 165 } 166 } 167 | Popular Tags |