[virtualcommons-svn] SF.net SVN: virtualcommons:[167] mentalmodels/trunk/flex/src
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-06-27 06:28:31
|
Revision: 167 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=167&view=rev Author: kjonas Date: 2009-06-27 06:28:28 +0000 (Sat, 27 Jun 2009) Log Message: ----------- OneDecision.mxml and TotalDisplay.mxml created for use in day-by-day decision component. These could be used as an Item Renderer, but it seems that it would be rather difficult, as the renderer would appear to need customization that is not possible with a single component? Modified Paths: -------------- mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml mentalmodels/trunk/flex/src/_InstructionsTest.mxml mentalmodels/trunk/flex/src/customComponents/InstructionPage.mxml mentalmodels/trunk/flex/src/customComponents/SocioDemographicPage.mxml mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml Added Paths: ----------- mentalmodels/trunk/flex/src/customComponents/questions/components/OneDecision.mxml mentalmodels/trunk/flex/src/customComponents/questions/components/TotalDisplay.mxml Modified: mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml =================================================================== --- mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml 2009-06-24 09:28:09 UTC (rev 166) +++ mentalmodels/trunk/flex/src/FisheryExperimentKalin.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -7,7 +7,9 @@ <mx:states> <mx:State name="socioDemographic"> <mx:AddChild relativeTo="{content}"> - <comp:SocioDemographicPage id="socioDemographic" x="265" y="100"/> + <comp:SocioDemographicPage id="socioDemographic" + x="{(content.width-socioDemographic.width)/2}" + y="{(content.height-socioDemographic.height)/2}"/> </mx:AddChild> <mx:SetProperty target="{content}" name="x"/> <mx:SetStyle target="{content}" name="horizontalCenter" value="0"/> @@ -29,12 +31,12 @@ <!-- <mx:Canvas id="content" x="5" y="5" width="750" height="470"/> --> - <mx:Canvas id="content" x="5" y="5" width="1000" height="470"/> + <mx:Canvas id="content" x="0" y="0" width="100%" height="100%"/> <mx:Canvas id="expiredContent" x="-1" y="-1" width="1" height="1" visible="false"/> - <mx:Button id="btnBack" label="« Back" click="back()" left="8" bottom="8"/> + <mx:Button id="btnBack" label="« Back" click="back()" left="8" bottom="8" enabled="false"/> <mx:Button id="btnAccept" label="Accept" click="accept()" left="{(width-btnAccept.width)/2}" bottom="10"/> - <mx:Button id="btnForward" label="Forward »" click="forward()" right="8" bottom="8"/> + <mx:Button id="btnForward" label="Forward »" click="forward()" right="8" bottom="8" enabled="false"/> <mx:RemoteObject id="ss" destination="studentService" fault="faultHandler(event)" result="resultHandler(event)"/> <mx:Producer id="producer" destination="DataPush" acknowledge="ack(event)"/> @@ -240,10 +242,16 @@ //consumer.subscribe(); returnValue = true; } + else + { + Alert.show("Cannot advance.\nTry looking at every page."); + } } catch(err:Error){} } + btnBack.enabled = btnForward.enabled = currentState == "instructions"; + return returnValue; } Modified: mentalmodels/trunk/flex/src/_InstructionsTest.mxml =================================================================== --- mentalmodels/trunk/flex/src/_InstructionsTest.mxml 2009-06-24 09:28:09 UTC (rev 166) +++ mentalmodels/trunk/flex/src/_InstructionsTest.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -1,7 +1,28 @@ <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="customComponents.*" xmlns:as="actionscript.*" - layout="vertical"> - + layout="vertical" xmlns:compQ="customComponents.questions.components.*"> + + <compQ:OneDecision id="test1" lbsFished="12" initialize="initQ()"/> + <compQ:TotalDisplay id="test2" lbsFished="12" initialize="test2.redraw()"/> + + <mx:DataGrid id="myGrid" + dataProvider="{initDG}" + variableRowHeight="true"> + <mx:columns> + <mx:DataGridColumn dataField="Day"/> + <mx:DataGridColumn dataField="Harbor" + itemRenderer="customComponents.questions.components.OneDecision"/> + <mx:DataGridColumn dataField="Bay1" + itemRenderer="customComponents.questions.components.OneDecision"/> + <mx:DataGridColumn dataField="Bay2" + itemRenderer="customComponents.questions.components.OneDecision"/> + <mx:DataGridColumn dataField="Bay3" + itemRenderer="customComponents.questions.components.OneDecision"/> + <mx:DataGridColumn dataField="Total" + itemRenderer="customComponents.questions.components.TotalDisplay"/> + </mx:columns> + </mx:DataGrid> + <mx:Script> <![CDATA[ import customComponents.questions.CategoricalQuestionC; @@ -17,6 +38,16 @@ public var block1:Block = new Block(); + [Bindable] + private var initDG:ArrayCollection = new ArrayCollection([ + {1:'Pavement', 2:'Slanted and Enchanted'}, + {1:'Pavement', 2:'Brighten the Corners'}]); + public function initQ():void + { + test1.peopleFishing = new ArrayCollection([1,2,3]); + test1.redraw(); + } + public function fillBlock():void { try{ Modified: mentalmodels/trunk/flex/src/customComponents/InstructionPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/InstructionPage.mxml 2009-06-24 09:28:09 UTC (rev 166) +++ mentalmodels/trunk/flex/src/customComponents/InstructionPage.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -3,6 +3,8 @@ <mx:Script> <![CDATA[ + import customComponents.questions.ForecastingFishQuestionC; + import customComponents.questions.ForecastingPeopleQuestionC; import mx.controls.Alert; import actionscript.Block; import actionscript.PageDisplay; @@ -13,6 +15,8 @@ [Bindable] public var numPages:int = 1; [Bindable] public var currPage:int = 0; + public var savedForecastPeople:ArrayCollection = null; + public function init(newBlock:Block):void { block = newBlock; @@ -50,31 +54,54 @@ public function back():Boolean { + preTurn(); var pageSuccess:Boolean = pageDisplay.prevPage(); if(pageSuccess) { - currPage = pageDisplay.currentPageNumber; - currPageLabel.text = "Page " + (currPage+1) + " / " + numPages; - - content.removeAllChildren(); - content.addChild(pageDisplay.currentPage); + postTurn(); } return pageSuccess; } public function forward():Boolean { + preTurn(); var pageSuccess:Boolean = pageDisplay.nextPage(); if(pageSuccess) { - currPage = pageDisplay.currentPageNumber; - currPageLabel.text = "Page " + (currPage+1) + " / " + numPages; - - content.removeAllChildren(); - content.addChild(pageDisplay.currentPage); + postTurn(); } return pageSuccess; } + private function preTurn():void + { + var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); + for(var i:int = 0; i < currPageArray.length; i++) + { + if(currPageArray[i] is ForecastingPeopleQuestionC) + { + savedForecastPeople = (currPageArray[i] as ForecastingPeopleQuestionC).save(); + } + } + } + private function postTurn():void + { + currPage = pageDisplay.currentPageNumber; + currPageLabel.text = "Page " + (currPage+1) + " / " + numPages; + + content.removeAllChildren(); + content.addChild(pageDisplay.currentPage); + + var currPageArray:Array = (pageDisplay.currentPage as VBox).getChildren(); + for(var i:int = 0; i < currPageArray.length; i++) + { + if(currPageArray[i] is ForecastingFishQuestionC) + { + (currPageArray[i] as ForecastingFishQuestionC).loadPeopleOnly(savedForecastPeople); + } + } + + } public function accept():Boolean { Modified: mentalmodels/trunk/flex/src/customComponents/SocioDemographicPage.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/SocioDemographicPage.mxml 2009-06-24 09:28:09 UTC (rev 166) +++ mentalmodels/trunk/flex/src/customComponents/SocioDemographicPage.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -38,7 +38,7 @@ boxGender.setStyle(bgcolor, red); ready=false; }else{ - boxGender.setStyle(bgcolor, white); + boxGender.setStyle(bgcolor, ""); } if(getYear().length != 4 || Number(getYear()) < 1900) Modified: mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml 2009-06-24 09:28:09 UTC (rev 166) +++ mentalmodels/trunk/flex/src/customComponents/questions/ForecastingFishQuestionC.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -50,6 +50,11 @@ loadPeople = newPeopleDisplay; init(); } + public function loadPeopleOnly(newPeopleDisplay:ArrayCollection):void + { + loadPeople = newPeopleDisplay; + init(); + } public function loadFromQuestion(question:ForecastingFishQuestion):void { description = question.question; Added: mentalmodels/trunk/flex/src/customComponents/questions/components/OneDecision.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/components/OneDecision.mxml (rev 0) +++ mentalmodels/trunk/flex/src/customComponents/questions/components/OneDecision.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Text xmlns:mx="http://www.adobe.com/2006/mxml" initialize="redraw()"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + + [Bindable] public var lbsFished:Number = 0.0; + [Bindable] public var peopleFishing:ArrayCollection = null; + + public function getLbs():String + { + var zeroDec:String = ""; + if(lbsFished as int == lbsFished) + { + zeroDec = ".0"; + } + var lbString:String = String(lbsFished).substr(0,5) + zeroDec + " lbs"; + return lbString; + } + + public function findPeople():String + { + var listStr:String = ""; + + if(peopleFishing == null || peopleFishing.length == 0) + { + listStr = "-"; + } + else + { + for(var i:int=0; i<peopleFishing.length; i++) + { + if(listStr.length != 0) + { + listStr += ", "; + } + listStr += peopleFishing.getItemAt(i); + } + } + + return listStr; + } + + public function redraw():void + { + htmlText = "Fished: "+getLbs()+"<br>People: "+findPeople(); + } + + ]]> + </mx:Script> + +</mx:Text> \ No newline at end of file Added: mentalmodels/trunk/flex/src/customComponents/questions/components/TotalDisplay.mxml =================================================================== --- mentalmodels/trunk/flex/src/customComponents/questions/components/TotalDisplay.mxml (rev 0) +++ mentalmodels/trunk/flex/src/customComponents/questions/components/TotalDisplay.mxml 2009-06-27 06:28:28 UTC (rev 167) @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Text xmlns:mx="http://www.adobe.com/2006/mxml" initialize="redraw()"> + + <mx:Script> + <![CDATA[ + + [Bindable] public var lbsFished:Number = 0.0; + [Bindable] public var dollarPerLb:Number = 3.99; + + public function getLbs():String + { + var zeroDec:String = ""; + if(lbsFished as int == lbsFished) + { + zeroDec = ".0"; + } + var lbString:String = String(lbsFished).substr(0,5) + zeroDec + " lbs"; + return lbString; + } + + public function getMoney():String + { + var moneyMade:Number = lbsFished * dollarPerLb; + var zeroDec:String = ""; + if(moneyMade as int == moneyMade) + { + zeroDec = ".0"; + } + var moneyString:String = "$" + String(moneyMade).substr(0,5) + zeroDec; + return moneyString; + } + + public function redraw():void + { + htmlText = getLbs()+"<br>"+getMoney(); + } + + ]]> + </mx:Script> + +</mx:Text> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |