commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbe...@apache.org
Subject svn commit: r1041740 - in /commons/sandbox/gsoc/2010/scxml-js/trunk: demo/drag-and-drop/ demo/drawing-tool/ demo/drawing-tool/behaviour/ src/javascript/scxml/cgf/layout/ src/xslt/layout/
Date Fri, 03 Dec 2010 09:15:23 GMT
Author: jbeard
Date: Fri Dec  3 09:15:22 2010
New Revision: 1041740

URL: http://svn.apache.org/viewvc?rev=1041740&view=rev
Log:
Changes to add drag-and-drop functionality to the drawing-tool-with-graphical-debugger prototype.
Also, removed console logging API from compiled behaviour model.

Added:
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml   (with
props)
Modified:
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop3.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/drawing-tool-with-graphical-debugger.html
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/layout/PrepLayout.js
    commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/layout/scxmlToSVG.xsl

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop3.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop3.js?rev=1041740&r1=1041739&r2=1041740&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop3.js (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drag-and-drop/drag-and-drop3.js Fri Dec
 3 09:15:22 2010
@@ -67,13 +67,11 @@ function StatechartExecutionContext() {
 
             this.enterAction = function() {
 
-                console.log("entering scxmlRoot");
 
             }
 
             this.exitAction = function() {
 
-                console.log("exiting scxmlRoot");
 
             }
 
@@ -117,14 +115,11 @@ function StatechartExecutionContext() {
 
             this.enterAction = function() {
 
-                console.log("entering scxmlRoot_initial");
 
             }
 
             this.exitAction = function() {
 
-                console.log("exiting scxmlRoot_initial");
-
             }
 
 
@@ -197,13 +192,11 @@ function StatechartExecutionContext() {
 
             this.enterAction = function() {
 
-                console.log("entering initial_default");
 
             }
 
             this.exitAction = function() {
 
-                console.log("exiting initial_default");
 
             }
 
@@ -279,13 +272,11 @@ function StatechartExecutionContext() {
 
             this.enterAction = function() {
 
-                console.log("entering idle");
 
             }
 
             this.exitAction = function() {
 
-                console.log("exiting idle");
 
             }
 
@@ -361,13 +352,11 @@ function StatechartExecutionContext() {
 
             this.enterAction = function() {
 
-                console.log("entering dragging");
 
             }
 
             this.exitAction = function() {
 
-                console.log("exiting dragging");
 
             }
 

Added: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml?rev=1041740&view=auto
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml (added)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml Fri
Dec  3 09:15:22 2010
@@ -0,0 +1,113 @@
+<scxml 
+	xmlns="http://www.w3.org/2005/07/scxml"
+	version="1.0"
+	profile="ecmascript"
+	id="scxmlRoot"
+	initial="initial_default"
+	name="PanAndZoom">
+
+	<script>
+		function getPointInArbitrarySpace(point,mat){
+			var cPt1 =  svgElement.createSVGPoint();
+			cPt1.x = point.x;
+			cPt1.y = point.y;
+			cPt1 = cPt1.matrixTransform(mat);
+				
+			return cPt1;
+		}
+
+
+		//FIXME: may need to convert to canvas coordinates
+		function computeTDelta(oldEvent,newEvent){
+			//summary:computes the offset between two events; to be later used with this.translate
+			var dx = newEvent.screenX - oldEvent.screenX;
+			var dy = newEvent.screenY - oldEvent.screenY;
+
+			//console.log(newEvent.screenX);
+
+			return {'dx':dx,'dy':dy};
+		}
+
+		function pan(tDelta){
+			var suspendId = svgElement.suspendRedraw(60000);
+
+			viewBox.x -= tDelta.dx;
+			viewBox.y -= tDelta.dy;
+
+			svgElement.unsuspendRedraw(suspendId); 
+		}
+	</script>
+
+	<datamodel>
+		<data id="firstEvent"/>
+		<data id="eventStamp"/>
+		<data id="tDelta"/>
+		<data id="viewBox"/>
+		<data id="svgElement"/>
+	</datamodel>
+
+	<state id="initial_default">
+		<transition event="init" target="idle">
+			<assign location="viewBox" expr="_event.data.viewBox"/>
+			<assign location="svgElement" expr="_event.data.svgElement"/>
+		</transition>
+	</state>
+
+	<state id="idle">
+		<transition event="mousedown" target="dragging">
+			<assign location="firstEvent" expr="_event.data"/>
+			<assign location="eventStamp" expr="_event.data"/>
+		</transition>
+		<!-- FIXME: these should be eventless transitions -->
+		<transition event="DOMMouseScroll" target="idle">
+			<script>
+				var suspendId = svgElement.suspendRedraw(60000);
+
+				viewBox.x -= _event.data.detail*scrollFactor;
+				viewBox.y -= _event.data.detail*scrollFactor;
+
+				viewBox.width += _event.data.detail*scrollFactor; 
+				viewBox.height += _event.data.detail*scrollFactor; 
+
+				svgElement.unsuspendRedraw(suspendId); 
+			</script>
+		</transition>
+		<transition event="keypress" target="idle">
+			<script>
+				var step;
+
+				if(_event.data.charCode==106){
+					step=3;
+				}else if(_event.data.charCode==107){
+					step=-3;
+				}else{
+					return;
+				}
+				
+				var suspendId = svgElement.suspendRedraw(60000);
+
+				viewBox.x -= step*scrollFactor;
+				viewBox.y -= step*scrollFactor;
+
+				viewBox.width += step*scrollFactor; 
+				viewBox.height += step*scrollFactor; 
+				
+				svgElement.unsuspendRedraw(suspendId); 
+			</script>
+		</transition>
+	</state>
+
+	<state id="dragging">
+		<transition event="mouseup" target="idle">
+		</transition>
+
+		<transition event="mousemove" target="dragging">
+			<assign location="tDelta" expr="computeTDelta(eventStamp,_event.data)"/>
+			<script>
+				pan(tDelta);
+			</script>
+			<assign location="eventStamp" expr="_event.data"/>
+		</transition>
+	</state>
+
+</scxml>

Propchange: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/behaviour/pan-zoom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/drawing-tool-with-graphical-debugger.html
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/drawing-tool-with-graphical-debugger.html?rev=1041740&r1=1041739&r2=1041740&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/drawing-tool-with-graphical-debugger.html
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/demo/drawing-tool/drawing-tool-with-graphical-debugger.html
Fri Dec  3 09:15:22 2010
@@ -169,9 +169,11 @@ $(document).ready(function(){
 							"xml!demo/drawing-tool/behaviour/canvas.xml",
 							"src/javascript/scxml/cgf/listener/GraphicalSimulator",
 							"src/javascript/scxml/cgf/layout",
-							"src/javascript/scxml/cgf/layout/hierarchical/HierarchicalLayout" ],
+							"src/javascript/scxml/cgf/layout/hierarchical/HierarchicalLayout",
+							"xml!demo/drawing-tool/behaviour/pan-zoom.xml" ],
 
-						function(compiler,svgTransformModule,canvasBehaviourSCXML,Simulator,layout,HierarchicalLayout){
+
+						function(compiler,svgTransformModule,canvasBehaviourSCXML,Simulator,layout,HierarchicalLayout,panZoomSCXML){
 
 							require( [window.DOMParser ?
 								"src/javascript/scxml/cgf/util/xsl/browser" :
@@ -189,14 +191,23 @@ $(document).ready(function(){
 											xslTransformer,
 											canvasBehaviourSCXML,
 											{heuristic:HierarchicalLayout.HEURISTICS_ENUM.MINIMUM_WIDTH_LAYERING},
-											w.document.body);
+											w);
 
 										var svgDoc = layoutInfo.svgDoc;
+
+										var scrollFactor=50;
+
+										var svgDocRoot=svgDoc.documentElement;
+										var viewBox = svgDoc.documentElement.viewBox.baseVal;
+
+										//add some zoom behaviour to the SVG doc
+
+										//add zoom behaviour
 								
 										var d = new Date();
 
 										compiler.compile({
-											inFiles:[canvasBehaviourSCXML],
+											inFiles:[canvasBehaviourSCXML,panZoomSCXML],
 											//debug:true,
 											backend:"state",
 											beautify:true,
@@ -213,6 +224,18 @@ $(document).ready(function(){
 												eval(scArr[i]);
 											}
 
+
+											//add pan behaviour to visualization
+											var sc = new PanAndZoomStatechartExecutionContext();
+											sc.initialize();
+										
+											sc.init({svgElement:svgDocRoot,
+												viewBox:viewBox});
+
+											["mousedown","mouseup","mousemove","DOMMouseScroll","keypress"].forEach(function(eventName){
+												svgDocRoot.addEventListener(eventName,function(e){e.preventDefault();sc[eventName](e)},false);
+											});
+
 											//hook up canvas behaviour
 											canvasSC = new CanvasStatechartExecutionContext(); 
 

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/layout/PrepLayout.js
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/layout/PrepLayout.js?rev=1041740&r1=1041739&r2=1041740&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/layout/PrepLayout.js
(original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/javascript/scxml/cgf/layout/PrepLayout.js
Fri Dec  3 09:15:22 2010
@@ -29,19 +29,22 @@ function(commonSVG,graphics,xpath){
 				function(svgDoc,attachPointNode){
 					attachPointNode = attachPointNode || document.body;
 
-					//in order to use this SVG document, it needs to be rendered, so we append the contents
to the current document,
-					//which works well in the html context in Firefox
-					var newDocumentElement = svgDoc.documentElement.cloneNode(true)
-					attachPointNode.appendChild(newDocumentElement)
-
-					/*
-					var impl = document.implementation;
-					var svgDoc2 = impl.createDocument(commonSVG.SVG_NS, "svg", null);
-					svgDoc2.replaceChild(svgDoc.documentElement.cloneNode(true), svgDoc2.documentElement);
-					*/
+					if(attachPointNode instanceof Window){	
+						attachPointNode.document.replaceChild(attachPointNode.document.importNode(svgDoc.documentElement,true),

+							attachPointNode.document.documentElement);
+						return attachPointNode.document;
+					} else{
+						//assume Node
+
+						//in order to use this SVG document, it needs to be rendered, so we append the contents
to the current document,
+						//which works well in the html context in Firefox
+						var newDocumentElement = svgDoc.documentElement.cloneNode(true)
+						attachPointNode.appendChild(newDocumentElement)
+						return newDocumentElement.ownerDocument;
+					}
+
 					//console.log(newDocumentElement.getBBox)
 					//console.log(newDocumentElement.getBBox())
-					return newDocumentElement.ownerDocument;
 
 				} :
 				function(svgDoc){

Modified: commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/layout/scxmlToSVG.xsl
URL: http://svn.apache.org/viewvc/commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/layout/scxmlToSVG.xsl?rev=1041740&r1=1041739&r2=1041740&view=diff
==============================================================================
--- commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/layout/scxmlToSVG.xsl (original)
+++ commons/sandbox/gsoc/2010/scxml-js/trunk/src/xslt/layout/scxmlToSVG.xsl Fri Dec  3 09:15:22
2010
@@ -115,8 +115,7 @@
 					markerUnits="strokeWidth"
 					markerWidth="10" markerHeight="10"
 					orient="auto">
-					<path d="M 0 0 L 10 5 L 0 10 z" 
-						transform="translate(-10,0)" class="triangle"/>
+					<path d="M 0 0 L 10 5 L 0 10 z" class="triangle"/>
 				</marker>
 			</defs>
 			<g class="scxml">
@@ -140,6 +139,11 @@
 							<path class="edge" d="M0,0 Q1,1 2,2" marker-end="url(#triangle)"/>
 							<text class="label" x="0" y="0">
 								<xsl:value-of select="../../@event"/>
+								<xsl:if test="../../@cond">
+									<xsl:text>[</xsl:text>
+										<xsl:value-of select="../../@cond"/>
+									<xsl:text>]</xsl:text>
+								</xsl:if>
 							</text>
 						</g>
 					</xsl:for-each>



Mime
View raw message