AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
aud.util.SingleStepper Class Reference

Simple framework for single stepping code. More...

+ Inheritance diagram for aud.util.SingleStepper:

Public Member Functions

 SingleStepper (JFrame parent)
 create new instance More...
 
 SingleStepper (String caption)
 create new instance More...
 
JFrame parent ()
 get parent widget More...
 
void halt (String text, int timeout)
 display text and wait for user or timeout
More...
 
void setTimeout (int timeout)
 Set global timeout. More...
 
SingleStepper whereAmI ()
 print location of calling code More...
 
SingleStepper showSource ()
 jmp to caller's location in editor (emacs only) More...
 
void halt (String text)
 display text and wait for user (or global timeout) More...
 
void halt ()
 wait for user More...
 

Static Public Member Functions

static void main (String[] args)
 

Protected Member Functions

JComponent createComponents ()
 
void onNext ()
 call on button pressed More...
 
void println (String text)
 print to both, text area and stdout More...
 
void onHalt ()
 

Protected Attributes

JFrame frame
 
JTextArea history
 
JButton next
 
Object monitor = new Object()
 
int timeout = 0
 

Detailed Description

Simple framework for single stepping code.

The SingleStepper widget consists of a text area that displays messages and a push button that triggers the next step.

The idea is to include calls to halt in your code: this prints a message and waits for the user to push the button to continue execution.

The following environment variables are recognized envionment variables.

environment variables
environment variable

purpose

AUD_TIMEOUT set global timeout for halt in milliseconds setTimeout

DotViewer can be used to visualize the state of an algorithm that is run with
SingleStepper
. GraphDemo shows an example.

See also
DotViewer TODO: link GraphDemo

Definition at line 44 of file SingleStepper.java.

Constructor & Destructor Documentation

◆ SingleStepper() [1/2]

create new instance

Definition at line 53 of file SingleStepper.java.

53 {
55 parent.getContentPane().add(createComponents());
56 if (Sys.env("AUD_TIMEOUT")!=null) {
57 try {
58 timeout=Integer.parseInt(Sys.env("AUD_TIMEOUT"));
59 } catch (NumberFormatException e) {}
60 }
61 }
JFrame parent()
get parent widget
JComponent createComponents()

References aud.util.SingleStepper.createComponents(), aud.util.Sys.env(), aud.util.SingleStepper.frame, aud.util.SingleStepper.parent(), and aud.util.SingleStepper.timeout.

+ Here is the call graph for this function:

◆ SingleStepper() [2/2]

create new instance

Definition at line 63 of file SingleStepper.java.

63 {
64 this(new JFrame(caption!=null ? caption : "aud.util.SingleStepper"));
65 JFrame f=parent();
66
67 // TODO: read geometry and font size from environment variable(s);
68 // and hide spinner (below) in case
69 f.setSize(400,400);
70 f.setVisible(true);
71
72 // exit on close
73 f.addWindowListener(new WindowAdapter() {
74 public void windowClosing(WindowEvent e) {
75 System.exit(0);
76 }
77 });
78 }

References aud.util.SingleStepper.parent().

+ Here is the call graph for this function:

Member Function Documentation

◆ createComponents()

JComponent aud.util.SingleStepper.createComponents ( )
protected

Definition at line 84 of file SingleStepper.java.

84 {
85 final JSpinner spinner=new JSpinner();
86 spinner.setValue(20);
87
88 final JPanel panel=new JPanel(new BorderLayout());
89
90 history=new JTextArea();
91 history.setFont(new Font("",Font.BOLD,(int) spinner.getValue()));
92 history.setEditable(false);
93 history.setLineWrap(false);
94
95 final JScrollPane historyPane = new JScrollPane(history);
96 historyPane.setPreferredSize(new Dimension(400, 300));
97
98 next=new JButton("continue");
99
100 next.addActionListener(new ActionListener() {
101 public void actionPerformed(ActionEvent ae) {
102 onNext();
103 }
104 });
105
106 spinner.addChangeListener(new ChangeListener(){
107 @Override
108 public void stateChanged(ChangeEvent arg0) {
109 // TODO Auto-generated method stub
110 if ((int) spinner.getValue()<10)
111 spinner.setValue(10);
112 if ((int) spinner.getValue()>40)
113 spinner.setValue(40);
114
115 history.setFont(new Font("",Font.BOLD,(int)spinner.getValue()));
116 }
117 });
118
119 panel.add("North",spinner);
120 panel.add("Center", historyPane);
121 panel.add("South", next);
122 return panel;
123 }
void onNext()
call on button pressed

References aud.util.SingleStepper.history, aud.util.SingleStepper.next, and aud.util.SingleStepper.onNext().

Referenced by aud.util.SingleStepper.SingleStepper().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ halt() [1/3]

◆ halt() [2/3]

void aud.util.SingleStepper.halt ( String  text)

display text and wait for user (or global timeout)

Definition at line 183 of file SingleStepper.java.

183 {
184 halt(text,timeout);
185 }

References aud.util.SingleStepper.halt(), and aud.util.SingleStepper.timeout.

+ Here is the call graph for this function:

◆ halt() [3/3]

void aud.util.SingleStepper.halt ( String  text,
int  timeout 
)

display text and wait for user or timeout

Definition at line 138 of file SingleStepper.java.

138 {
139 println(text);
140 try {
141 onHalt();
142 synchronized(monitor) {
143 monitor.wait(timeout>=0 ? timeout : 0);
144 }
145
146 } catch (InterruptedException e) {
147 System.err.println(e);
148 history.append("--- interrupted ---\n");
149 } catch (IllegalMonitorStateException e) {
150 System.err.println("ERROR: "+e);
151 System.exit(-1);
152 }
153 }
void println(String text)
print to both, text area and stdout

References aud.util.SingleStepper.history, aud.util.SingleStepper.monitor, aud.util.SingleStepper.onHalt(), aud.util.SingleStepper.println(), and aud.util.SingleStepper.timeout.

Referenced by aud.util.SingleStepperDemo.main(), aud.example.BinaryTreeTraversal.main(), aud.example.expr.ExpressionTreeTraversal.main(), and aud.util.SingleStepper.main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ main()

static void aud.util.SingleStepper.main ( String[]  args)
static

Reimplemented in aud.util.SingleStepperDemo, aud.example.BinaryTreeTraversal, and aud.example.expr.ExpressionTreeTraversal.

Definition at line 190 of file SingleStepper.java.

190 {
191 SingleStepper s=new SingleStepper("aud.util.SingleStepper");
192
193 for (int i=0;i<4;++i) {
194 System.out.println(i);
195 s.halt("some message "+i);
196 }
197 s.halt("QUIT");
198 System.exit(0);
199 }
SingleStepper(JFrame parent)
create new instance

References aud.util.SingleStepper.halt().

+ Here is the call graph for this function:

◆ onHalt()

void aud.util.SingleStepper.onHalt ( )
protected

Reimplemented in aud.example.BinaryTreeTraversal, aud.example.expr.ExpressionTreeTraversal, and aud.util.SingleStepperDemo.

Definition at line 161 of file SingleStepper.java.

161{}

Referenced by aud.util.SingleStepper.halt().

+ Here is the caller graph for this function:

◆ onNext()

void aud.util.SingleStepper.onNext ( )
protected

call on button pressed

Definition at line 126 of file SingleStepper.java.

126 {
127 try {
128 synchronized (monitor) {
129 monitor.notify();
130 }
131 } catch (IllegalMonitorStateException e) {
132 System.err.println("ERROR: "+e);
133 System.exit(-1);
134 }
135 }

References aud.util.SingleStepper.monitor.

Referenced by aud.util.SingleStepper.createComponents().

+ Here is the caller graph for this function:

◆ parent()

JFrame aud.util.SingleStepper.parent ( )

get parent widget

Definition at line 81 of file SingleStepper.java.

81{ return frame; }

References aud.util.SingleStepper.frame.

Referenced by aud.util.SingleStepper.SingleStepper().

+ Here is the caller graph for this function:

◆ println()

void aud.util.SingleStepper.println ( String  text)
protected

print to both, text area and stdout

Definition at line 156 of file SingleStepper.java.

156 {
157 history.append(text+"\n");
158 System.out.println(text);
159 }

References aud.util.SingleStepper.history.

Referenced by aud.util.SingleStepper.halt(), and aud.util.SingleStepper.whereAmI().

+ Here is the caller graph for this function:

◆ setTimeout()

void aud.util.SingleStepper.setTimeout ( int  timeout)

Set global timeout.

Continue halt after timeout milliseconds.

Parameters
timeoutin milliseconds

Definition at line 167 of file SingleStepper.java.

167 {
168 this.timeout=timeout;
169 }

References aud.util.SingleStepper.timeout.

◆ showSource()

SingleStepper aud.util.SingleStepper.showSource ( )

jmp to caller's location in editor (emacs only)

Definition at line 177 of file SingleStepper.java.

177 {
178 Sys.openCallersSourceInEmacs(1);
179 return this;
180 }

References aud.util.Sys.openCallersSourceInEmacs().

+ Here is the call graph for this function:

◆ whereAmI()

SingleStepper aud.util.SingleStepper.whereAmI ( )

print location of calling code

Definition at line 172 of file SingleStepper.java.

172 {
173 println(Sys.whereAmI(1));
174 return this;
175 }

References aud.util.SingleStepper.println(), and aud.util.Sys.whereAmI().

+ Here is the call graph for this function:

Member Data Documentation

◆ frame

JFrame aud.util.SingleStepper.frame
protected

◆ history

JTextArea aud.util.SingleStepper.history
protected

◆ monitor

Object aud.util.SingleStepper.monitor = new Object()
protected

◆ next

JButton aud.util.SingleStepper.next
protected

Definition at line 48 of file SingleStepper.java.

Referenced by aud.util.SingleStepper.createComponents().

◆ timeout

int aud.util.SingleStepper.timeout = 0
protected

The documentation for this class was generated from the following file: