4 * @author Roman Blazevic
8 package xelfi.debugger;
11 import xelfi.top.TopLevel;
12 import xelfi.top.TopDialog;
14 public class CallStackView extends TopDialog
16 private Debugger document;
18 private RemoteStackFrame[] csf = null; // used for call stack choosing
20 static final int KEY_ENTER = 10;
22 static final int HINT_COMPLETE_UPDATE = 0;
25 * CallStackView constructor.
27 * debugger - the document for this view
29 CallStackView(Debugger debugger)
31 super(TopLevel.getMenu(), false);
32 setTitle("Call Stack");
33 //super("Call Stack");
34 setBackground(Color.lightGray);
42 * My handleEvent() implementation.
44 public boolean handleEvent(Event event)
46 // items with index csf.length-i-2 contains info about stack frame with index i (variable csf[i])
47 int selectedIndex = list.getSelectedIndex();
49 if ((event.id == Event.KEY_PRESS && event.key == KEY_ENTER)
50 || (event.id == Event.ACTION_EVENT))
52 if (selectedIndex != -1)
54 int stackFrameIndex = csf.length-selectedIndex-2;
56 document.stackFrameChosen(csf[stackFrameIndex]);
61 return super.handleEvent(event);
65 * This method is called when the content of the view must be
68 void update(int hint, int index)
73 if (hint != HINT_COMPLETE_UPDATE)
75 System.out.println("unsupported hint");
79 csf = document.getCurrentStackFrames();
87 int indexOfSelected = list.getSelectedIndex();
88 if (indexOfSelected != -1)
89 list.deselect(indexOfSelected);
91 int currentStackFrameIndex = document.getCurrentStackFrameIndex();
92 int numberOfLines = csf.length-currentStackFrameIndex-1; // without "system" frame
93 // int numberOfLines = csf.length-currentStackFrameIndex;
95 if (numberOfLines < list.countItems())
96 list.delItems(numberOfLines, list.countItems()-1);
98 for(int i = csf.length-2; i >= currentStackFrameIndex; i--) // without "system" frame
100 // for(int i = csf.length-1; i >= currentStackFrameIndex; i--)
101 // "system" frame is that one with index csf.length-1
105 RemoteStackVariable lv[] = csf[i].getLocalVariables();
106 String string = new String();
107 int lastParameterIndex = -1;
109 for(int j = lv.length-1; j >= 0; j--)
110 if (lv[j].methodArgument())
112 lastParameterIndex = j; // the last method argument is here
116 for(int j = 0; j <= lastParameterIndex; j++)
117 if (lv[j].methodArgument())
119 String name = lv[j].getName();
121 string += name+": "+document.getCurrentValue(name /*, i*/);
122 if (j != lastParameterIndex)
126 // put one call stack line into the 'string' variable
127 string = " ["+(csf.length-i-1)+"] "+csf[i].getRemoteClass().getName()+"."
128 +csf[i].getMethodName()+"("+string+")";
130 if (csf.length-i-1 > list.countItems())
131 list.addItem(string);
133 if (list.getItem(csf.length-i-2).compareTo(string) != 0)
134 list.replaceItem(string, csf.length-i-2);
138 System.out.println(e);
144 * My show() implementation.
150 document.callStackViewShown();