Author: jbeard
Date: Tue Jun 22 15:45:32 2010
New Revision: 956926
URL: http://svn.apache.org/viewvc?rev=956926&view=rev
Log:
Added small demo to provide example of a GUI for the browser-based compiler
front-end.
Added:
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html
(with props)
Added:
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html
URL:
http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html?rev=956926&view=auto
==============================================================================
---
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html
(added)
+++
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html
Tue Jun 22 15:45:32 2010
@@ -0,0 +1,139 @@
+<html>
+ <head>
+ <style type="text/css">
+ body {
+ height:95%;
+ }
+
+ table {
+ width:100%;
+ height:100%;
+ }
+
+ td {
+ height:50%;
+ }
+
+ textarea{
+ width:100%;
+ height:85%;
+ }
+
+ div{ height:100% }
+ </style>
+ <script src="../../lib/js/requirejs/require.js"
type="text/javascript">true;</script>
+ <script src="../../lib/js/requirejs/require/xml.js"
type="text/javascript">true;</script>
+ <script src="../../lib/js/requirejs/require/text.js"
type="text/javascript">true;</script>
+ </head>
+ <body>
+ <table>
+ <tr>
+ <td colspan="2">
+ <em>SCXML Input</em>
+ <textarea id="scxml_input"></textarea>
+ <button id="compile_button">Compile
SCXML</button>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <em>Compiled JS Output</em>
+ <textarea id="js_output"
disabled></textarea>
+ </td>
+ <td>
+ <em>SCXML Console</em>
+ <textarea id="sc_console"></textarea>
+ <input type="text"
id="event_name_field"/>
+ <button id="send_event_button">Send
Event</button>
+ </td>
+ </tr>
+ </table>
+
+ <script>
+ var resultText;
+
+ require(
+ {
+ "baseUrl":"/"
+ },
+ [ "src/javascript/scxml/cgf/SCXMLCompiler",
+
"text!test/kitchen_sink/KitchenSink_executableContent.xml",
+ "src/javascript/scxml/cgf/util/xml"],
+
+
function(compiler,KitchenSink_executableContent,xmlUtil){
+
+ var compiledStatechartConstructor,
compiledStatechartInstance;
+
+ function ccToString(conf){return
conf.map(function(s){return s.toString()})}
+
+ //pull UI controls from DOM
+ var scxml_input =
document.getElementById("scxml_input");
+ var js_output =
document.getElementById("js_output");
+ var sc_console =
document.getElementById("sc_console");
+ var event_name_field =
document.getElementById("event_name_field");
+ var send_event_button =
document.getElementById("send_event_button");
+ var compile_button =
document.getElementById("compile_button");
+
+ //set initial content of scxml_input
+ scxml_input.textContent =
KitchenSink_executableContent;
+
+ //prepopulate stuff with stuff.
+
compile_button.addEventListener("click",function(e){
+
+ //TODO: provide a UI for
setting these options
+ var compileLog = true;
+ var backend = "state";
+
+ //parse textArea into xml
+ var textInput =
xmlUtil.parseFromString(scxml_input.textContent);
+
+ compiler.compile({
+ inFiles:[textInput],
+ backend:backend,
+ beautify:true,
+ verbose:false,
+ log:compileLog,
+ ie:false
+ }, function(scArr){
+ var transformedJs =
scArr[0];
+
+ //eval
+
console.log(transformedJs);
+ eval(transformedJs);
+
compiledStatechartConstructor = StatechartExecutionContext;
+
compiledStatechartInstance = new compiledStatechartConstructor();
+
+ sc_console.textContent
+= "Initializing new statechart instance...\n"
+
+ //initialize
+
compiledStatechartInstance.initialize();
+
+ //update DOM
+ js_output.textContent =
transformedJs;
+
+ /*
+
sc_console.removeAttribute("disabled");
+
event_name_field.removeAttribute("disabled");
+
send_event_button.removeAttribute("disabled");
+ */
+
+ sc_console.textContent
+= ccToString(compiledStatechartInstance.getCurrentConfiguration()) + ">";
+ });
+ },false);
+
+
send_event_button.addEventListener("click",function(e){
+ var eventToSend =
event_name_field.value;
+
+ sc_console.textContent +=
eventToSend + "\n";
+
+ //we use synchronous API
+
compiledStatechartInstance[eventToSend]();
+
+ sc_console.textContent +=
ccToString(compiledStatechartInstance.getCurrentConfiguration()) + ">";
+ },false);
+ }
+ );
+
+ </script>
+
+ </body>
+</html>
Propchange:
commons/sandbox/gsoc/2010/scxml-js/branches/browser-tests.1.ie/demo/sandbox/sandbox.html
------------------------------------------------------------------------------
svn:eol-style = native