Skip to content

Commit 1a7cb38

Browse files
committed
getting the Java version readied
1 parent 59fecbb commit 1a7cb38

8 files changed

Lines changed: 364 additions & 56 deletions

File tree

‎README‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,12 @@ v4-cokapi/
158158
---
159159
Acknowledgments
160160

161-
John DeNero - for helping with the official Python 3 port and lots of code patches
161+
John DeNero - for helping with the official Python 3 port and LOTS of code patches
162162
Chris Horne - https://github.com/lahwran - for security tips
163163
Joshua Landau - joshua@landau.ws - for security tips
164-
Peter Wentworth and his students - for working on the original Python 3 fork
164+
Peter Wentworth and his students - for working on the original Python 3 fork circa 2011
165165
Brad Miller - for adding pop-up question dialogs to visualizations
166-
David Pritchard - for some enhancements to front-end
166+
David Pritchard and Will Gwozdz - for the Java frontend and other frontend enhancements
167167
Peter Robinson - for v3/make_visualizations.py
168168
Chris Meyers - for custom visualizations such as v3/matrix.py and v3/htmlFrame.py
169169
Irene Chen - for holistic visualization mode -- v3/js/holistic.js
@@ -187,3 +187,5 @@ Andrew Petersen
187187
David Pritchard
188188
Suzanne Rivoire
189189
David Wilkins
190+
191+
... and many more!

‎v3/index.html‎

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<head>
3333

34-
<title>Online Python Tutor - Learn programming by visualizing code execution</title>
34+
<title>Online Python Tutor - Visualize Python, Java, and JavaScript code</title>
3535

3636
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
3737

@@ -64,16 +64,7 @@
6464

6565
<div class="activityPane" id="learnPane">
6666

67-
<h1><span id="learnHeading">LEARN</span> <span class="smallH1">programming by visualizing code execution</span></h1>
68-
69-
<!--
70-
<p><a id="optLink" href="visualize.html">Online Python Tutor</a>
71-
enables teachers and students to write <a
72-
href="http://www.python.org/">Python</a> programs directly in the web
73-
browser, execute those programs, and then step forwards and backwards
74-
through execution to view the run-time state of data structures.</p>
75-
-->
76-
67+
<h1><span id="learnHeading">LEARN</span> <span class="smallH1">programming by visualizing Python, Java, and JavaScript code execution</span></h1>
7768

7869
<p><a id="optLink" href="visualize.html">Online Python Tutor</a> is a
7970
free educational tool created by <a href="http://www.pgbovine.net/">Philip Guo</a>
@@ -82,9 +73,8 @@ <h1><span id="learnHeading">LEARN</span> <span class="smallH1">programming by vi
8273
computer executes each line of a program's source code.</p>
8374

8475
<p>Using this
85-
tool, a teacher or student can write a <b>Python</b> or <b>JavaScript</b> program in the Web
86-
browser and visualize what the computer is doing step-by-step as it
87-
executes the program.</p>
76+
tool, a teacher or student can write <b>Python</b>, <b>Java</b>, and <b>JavaScript</b> programs in the Web
77+
browser and visualize what the computer is doing step-by-step as those programs execute.</p>
8878

8979
<p>Over 500,000 people in over 165 countries have used
9080
Online Python Tutor to understand and debug their programs, often as a
@@ -102,14 +92,13 @@ <h1><span id="learnHeading">LEARN</span> <span class="smallH1">programming by vi
10292
-->
10393

10494
<div id="startLink">
105-
<a href="visualize.html">Start using Online Python Tutor now</a>
95+
<a href="visualize.html">Start visualizing Python, Java, and JavaScript code now!</a>
10696
</div>
10797

10898

109-
<p>For instance, here is a visualization showing a program that <a
99+
<p>For instance, here is a visualization showing a Python program that <a
110100
href="http://en.wikipedia.org/wiki/Recursion_(computer_science)">recursively</a>
111-
finds the sum of a (<a
112-
href="http://en.wikipedia.org/wiki/Cons">cons-style</a>) linked list.
101+
finds the sum of a linked list.
113102
Click the &ldquo;Forward&rdquo; button to see what happens as the
114103
computer executes each line of code.</p>
115104

‎v3/js/ace/src-min-noconflict/mode-java.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎v3/js/opt-frontend-common.js‎

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ var python2crazy_backend_script = 'web_exec_py2-crazy.py';
5353
// crazy custom py2crazy CPython interpreter to get 2crazy mode
5454
//var python2crazy_backend_script = 'exec';
5555

56+
// empty dummy just to do logging on the Apache's server
5657
var js_backend_script = 'web_exec_js.py';
58+
var java_backend_script = 'web_exec_java.py';
5759

60+
// these are the REAL endpoints, accessed via jsonp. code is in ../../v4-cokapi/
5861
var JS_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_js_jsonp'; // for deployment
59-
//var JS_JSONP_ENDPOINT = 'http://localhost:3000/exec_js_jsonp'; // for local testing
62+
var JAVA_JSONP_ENDPOINT = 'http://104.237.139.253:3000/exec_java_jsonp'; // for deployment
6063

6164
var domain = "http://pythontutor.com/"; // for deployment
6265

@@ -135,8 +138,18 @@ function setAceMode() {
135138
var mod = 'python';
136139
if ($('#pythonVersionSelector').val() === 'js') {
137140
mod = 'javascript';
141+
} else if ($('#pythonVersionSelector').val() === 'java') {
142+
mod = 'java';
143+
144+
// if empty, initialize to a Java skeleton:
145+
if ($.trim(pyInputGetValue()) == '') {
146+
pyInputSetValue('public class YourClassNameHere {\n\
147+
public static void main(String[] args) {\n\
148+
\n\
149+
}\n\
150+
}');
151+
}
138152
}
139-
assert(mod === 'python' || mod === 'javascript');
140153
var s = pyInputAceEditor.getSession();
141154
s.setMode("ace/mode/" + mod);
142155
}
@@ -1285,6 +1298,8 @@ function executePythonCode(pythonSourceCode,
12851298
frontendOptionsObj.lang = 'py3';
12861299
} else if (backendScript === js_backend_script) {
12871300
frontendOptionsObj.lang = 'js';
1301+
} else if (backendScript === java_backend_script) {
1302+
frontendOptionsObj.lang = 'java';
12881303
}
12891304

12901305
if (backendScript === js_backend_script) {
@@ -1307,7 +1322,26 @@ function executePythonCode(pythonSourceCode,
13071322
data: {user_script : pythonSourceCode},
13081323
success: execCallback,
13091324
});
1325+
} else if (backendScript === java_backend_script) {
1326+
// hack for Java execution! should just be a dummy script for logging only
1327+
$.get(backendScript,
1328+
{user_script : pythonSourceCode,
1329+
user_uuid: supports_html5_storage() ? localStorage.getItem('opt_uuid') : undefined,
1330+
// if we don't have any deltas, then don't bother sending deltaObj:
1331+
diffs_json: deltaObj && (deltaObj.deltas.length > 0) ? JSON.stringify(deltaObj) : null},
1332+
function(dat) {} /* don't do anything since this is a dummy call */, "text");
13101333

1334+
// the REAL call uses JSONP
1335+
// some JSONP action!
1336+
// http://learn.jquery.com/ajax/working-with-jsonp/
1337+
$.ajax({
1338+
url: JAVA_JSONP_ENDPOINT,
1339+
// The name of the callback parameter, as specified by the YQL service
1340+
jsonp: "callback",
1341+
dataType: "jsonp",
1342+
data: {user_script : pythonSourceCode},
1343+
success: execCallback,
1344+
});
13111345
} else {
13121346
$.get(backendScript,
13131347
{user_script : pythonSourceCode,

‎v3/js/opt-frontend.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
126126
else if ($('#pythonVersionSelector').val() == 'js') {
127127
backend_script = js_backend_script;
128128
}
129+
else if ($('#pythonVersionSelector').val() == 'java') {
130+
backend_script = java_backend_script;
131+
}
129132
assert(backend_script);
130133

131134
var backendOptionsObj = {cumulative_mode: ($('#cumulativeModeSelector').val() == 'true'),
@@ -170,11 +173,6 @@ function executeCode(forceStartingInstr, forceRawInputLst) {
170173

171174

172175
function initAceAndOptions() {
173-
if ($('#pythonVersionSelector').val() === 'js') {
174-
$('#optionsPane').hide();
175-
} else {
176-
$('#optionsPane').show();
177-
}
178176
setAceMode(); // update syntax highlighting mode
179177
}
180178

@@ -200,7 +198,6 @@ var PY2_EXAMPLES = {
200198
filterExampleLink: "example-code/filter.txt",
201199
insSortExampleLink: "example-code/ins_sort.txt",
202200
aliasExampleLink: "example-code/aliasing.txt",
203-
firstExampleDupLink: "example-code/aliasing.txt",
204201
happyExampleLink: "example-code/happy.txt",
205202
newtonExampleLink: "example-code/sqrt.txt",
206203
oopSmallExampleLink: "example-code/oop_small.txt",

0 commit comments

Comments
 (0)