1 22 23 package org.aspectj.debugger.gui; 24 25 import org.aspectj.debugger.base.*; 26 27 import com.sun.jdi.*; 28 import com.sun.jdi.event.*; 29 import java.awt.*; 30 import java.awt.event.*; 31 import javax.swing.*; 32 import javax.swing.event.*; 33 import javax.swing.table.*; 34 import javax.swing.plaf.basic.*; 35 import java.util.*; 36 import java.util.List ; 37 38 public class StackTablePane 39 extends AJPanel 40 implements StopListener { 41 42 private JTable table = null; 43 private JScrollPane scrollPane = null; 44 45 public StackTablePane(GUIDebugger debugger) { 46 super(debugger); 47 debugger.getDebugger().addStopListener(this); 48 setLayout(new BorderLayout()); 49 ThreadReference threadRef = null; 50 try { 51 threadRef = guid().getDebugger().getDefaultThread(); 52 } catch (DebuggerException de) { 53 } 54 table = new StackTable(new StackTableModel(threadRef)); 55 table.setDefaultRenderer(Integer .class, new IntegerTableCellRenderer()); 56 scrollPane = new JScrollPane(table); 57 add(scrollPane, BorderLayout.CENTER); 58 } 59 60 protected JTable getTable() { 61 return table; 62 } 63 64 65 public void accessWatchpointEvent(AccessWatchpointEvent e) { 66 showForThread(e.thread()); 67 } 68 public void breakpointEvent(BreakpointEvent e) { 69 showForThread(e.thread()); 70 } 71 public void exceptionEvent(ExceptionEvent e) { 72 showForThread(e.thread()); 73 } 74 public void modificationWatchpointEvent(ModificationWatchpointEvent e) { 75 showForThread(e.thread()); 76 } 77 public void stepEvent(StepEvent e) { 78 showForThread(e.thread()); 79 } 80 81 public void showForThread(ThreadReference threadRef) { 82 table.setModel(new StackTableModel(threadRef)); 83 try { 84 table.setRowSelectionInterval(0, 0); 85 } catch (IllegalArgumentException iae) { 86 } catch (IndexOutOfBoundsException ioobe) { 87 } 88 } 89 90 public static String d() { return "Stack Table Pane"; } 91 public String toString() { return d(); } 92 } 93 94 class StackTable extends JTable { 95 public StackTable(TableModel model) { 96 super(model); 97 setUI(new StackTableUI()); 98 } 99 100 public void setModel(TableModel model) { 101 super.setModel(model); 102 TableColumn col = getColumnModel().getColumn(0); 103 int charWidth = 10; 104 col.setWidth(4 * charWidth); 105 col.setMinWidth(3 * charWidth); 106 col.setMaxWidth(5 * charWidth); 107 } 108 109 class StackTableUI extends BasicTableUI { 110 protected MouseInputListener createMouseInputListener() { 111 return new BasicTableUI.MouseInputHandler() { 112 public void mouseClicked(MouseEvent e) { 113 int row = StackTable.this.getSelectedRow(); 114 int col = StackTable.this.getSelectedColumn(); 115 int x = e.getX(); 116 int y = e.getY(); 117 AJStackFrameFormatter.MethodAndSource 118 ms = (AJStackFrameFormatter.MethodAndSource) 119 StackTable.this.getModel().getValueAt 120 (row, 1); 121 if (!ms.isValid()) { 122 return; 123 } 124 String s = ms.getFullPath(); 125 final int l = ms.lineNumber; 126 if (SwingUtilities.isRightMouseButton(e) || 127 SwingUtilities.isMiddleMouseButton(e)) { 128 JPopupMenu popup = new JPopupMenu(); 129 final String source = AJLineMapper.removeRoot(s); 130 JMenuItem item = new JMenuItem("Set breakpoint"); 131 popup.add(item); 132 final String cmd = "stop on " + source + ":" + l; 133 134 item.addActionListener(new ActionListener() { 136 public void actionPerformed(ActionEvent _) { 137 Integer ing = new Integer (l); 140 } 141 }); 142 popup.show(StackTable.this, 143 x + popup.getWidth()/2, 144 y + popup.getHeight()/2); 145 146 147 } else if (e.getClickCount() == 2) { 148 ComponentRepository.getSourcePane().showSourceForFileAndLine(s, l); 149 } 150 } 151 }; 152 } 153 } 154 } 155 156 class StackTableModel extends DefaultTableModel { 157 158 private final String [] colNames 159 = {"#", "Location"}; 160 private final Class [] colClasses 162 = {Integer .class, AJStackFrameFormatter.MethodAndSource.class}; 163 164 public StackTableModel(ThreadReference threadRef) { 165 if (threadRef != null) { 166 colNames[1] += ": " + AJThreadFormatter.format(threadRef); 167 } 168 setColumnIdentifiers(colNames); 169 if (threadRef != null) { 170 try { 171 List stack = ComponentRepository.getAJDebugger().frames(threadRef); 173 for (int i = 0; i < stack.size(); i++) { 174 Object [] os = { new Integer (i+1), 175 AJStackFrameFormatter.format((StackFrame) stack.get(i)) }; 176 addRow(os); 177 } 178 } catch (IncompatibleThreadStateException e) { 179 } 180 } 181 } 182 183 public Class getColumnClass(int col) { 184 return colClasses[col]; 185 } 186 187 public boolean isCellEditable(int row, int col) { 188 return false; 189 } 190 191 String format(StackFrame frame) { 192 if (frame == null) { 193 return "<BAD FRAME>"; 194 } 195 Location loc = frame.location(); 196 Method meth = loc.method(); 197 String str = meth.declaringType().name() + "." + meth.name() + " ("; 198 if (meth instanceof Method && ((Method)meth).isNative()) { 199 str += "native method"; 200 } else if (loc.lineNumber() > -1) { 201 try { 202 str += loc.sourceName(); 203 } catch (AbsentInformationException e) { 204 str += "<unknown>"; 205 } 206 str += ":"; 207 str += loc.lineNumber(); 208 } else { 209 str += "<unknown>"; 210 } 211 str += ")"; 212 return str; 213 } 214 215 public String toString() { 216 return "Stack Table Pane"; 217 } 218 } 219 220 class IntegerTableCellRenderer extends DefaultTableCellRenderer { 221 public Component getTableCellRendererComponent(JTable table, 222 Object value, 223 boolean isSelected, 224 boolean hasFocus, 225 int row, 226 int col) 227 { 228 super.getTableCellRendererComponent 229 (table, value, isSelected, hasFocus, row, col); 230 231 if (value != null) { 232 setHorizontalAlignment(SwingConstants.CENTER); 233 setText("[" + value + "]"); 234 } 235 return this; 236 } 237 } 238 | Popular Tags |