Thread: [virtualcommons-svn] SF.net SVN: virtualcommons:[172] mentalmodels/trunk/flex/src/custom/ questions
Status: Beta
Brought to you by:
alllee
From: <kj...@us...> - 2009-07-05 23:58:24
|
Revision: 172 http://virtualcommons.svn.sourceforge.net/virtualcommons/?rev=172&view=rev Author: kjonas Date: 2009-07-05 23:58:17 +0000 (Sun, 05 Jul 2009) Log Message: ----------- trying to re-commit restructured folders Added Paths: ----------- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDecision.mxml mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/TotalDisplay.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/psychometric/ mentalmodels/trunk/flex/src/custom/questions/psychometric/PsychometricQuestionC.mxml mentalmodels/trunk/flex/src/custom/questions/psychometric/Slider.mxml mentalmodels/trunk/flex/src/custom/questions/psychometric/SliderImage.png mentalmodels/trunk/flex/src/custom/questions/strategyDesign/ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml Added: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/DayByDayDecisionsQuestionC.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,172 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> + + <mx:String id="description"></mx:String> + + <mx:Label id="txtPrompt" text="It's Day {currentDay}. Where will you go to fish, or will you stay in the harbor?"/> + <mx:Label id="lblChosen" text="location chosen: {deciding}"/> + + <mx:HBox id="buttons"/> + <mx:HBox id="labels" verticalAlign="middle"/> + + <mx:VBox id="dayByDayContent" borderStyle="outset" minWidth="655" verticalGap="0" + height="300" verticalScrollPolicy="on"/> + + <mx:Label id="lblCumulative" text="So far, you have fished {getLbs(cumTotal)}, which is worth {getMoney(cumTotal,dollarPerLb)}."/> + + <mx:Script> + <![CDATA[ + import mx.controls.Button; + import mx.controls.Text; + import actionscript.questions.*; + import custom.questions.dayByDayDecisions.OneDay; + + public var numBays:int = 3; + [Bindable] public var deciding:int = 0; + [Bindable] public var currentDay:int = 1; + [Bindable] public var cumTotal:Number = 0; + [Bindable] public var dollarPerLb:Number = 3.99; + + public function init():void + { + buttons.removeAllChildren(); + labels.removeAllChildren(); + + var btnTemp:Button = new Button(); + btnTemp.label = "Harbor"; + btnTemp.id = "btnHarbor"; + btnTemp.addEventListener(MouseEvent.CLICK,clicked); + buttons.addChild(btnTemp); + + var txtTemp:Text = new Text(); + txtTemp = stylize(txtTemp); + txtTemp.minWidth = 50; + txtTemp.text = "Day"; + labels.addChild(txtTemp); + + txtTemp = new Text(); + txtTemp = stylize(txtTemp); + txtTemp.text = "Harbor"; + labels.addChild(txtTemp); + + for(var i:int = 0; i < numBays; i++) + { + btnTemp = new Button(); + btnTemp.label = "Bay" + (i+1); + btnTemp.id = "btn" + btnTemp.label; + btnTemp.addEventListener(MouseEvent.CLICK,clicked); + buttons.addChild(btnTemp); + + txtTemp = new Text(); + txtTemp = stylize(txtTemp); + txtTemp.text = "Bay" + (i+1); + labels.addChild(txtTemp); + } + + btnTemp = new Button(); + btnTemp.label = "Advance"; + btnTemp.id = "btnAdvance"; + btnTemp.addEventListener(MouseEvent.CLICK,advance); + buttons.addChild(btnTemp); + + txtTemp = new Text(); + txtTemp = stylize(txtTemp); + txtTemp.htmlText = "Cumulative<br>Total"; + txtTemp.minWidth = 60; + labels.addChild(txtTemp); + } + private function stylize(txtTemp:Text):Text + { + txtTemp.setStyle("textAlign", "center"); + txtTemp.setStyle("fontWeight","bold"); + txtTemp.minWidth = 125; + return txtTemp; + } + + public function clicked(event:MouseEvent):void + { + try + { + deciding = 0; + if(event != null && (event.target as Button).label != "Harbor") + { + var obj:Button = event.target as Button; + deciding = int(obj.label.substring(3)); + } + } + catch(err:Error) + { + // silent failure + deciding = 0; + } + } + + public function advance(event:MouseEvent=null):void + { + if(currentDay == 30) + { + return; + } + + var newDay:OneDay = new OneDay(); + newDay.numBays = numBays; + newDay.initialize(); + newDay.day = currentDay++; + newDay.dollarPerLb = dollarPerLb; + dayByDayContent.addChild(newDay.load(deciding)); + cumTotal += newDay.presentTotal; + +// try +// { +// var last:Object = dayByDayContent.getChildAt(dayByDayContent.numChildren - 1); +// if(last is OneDay) +// { +// cumTotal += (last as OneDay).presentTotal; +// } +// } +// catch(err:Error) +// { +// // silent failure +// } + + deciding = 0; + } + + public function loadFromQuestion(question:Question):void + { + description = question.question; + + initialize(); + init(); + } + + public function getLbs(lbsFished:Number):String + { + lbsFished = Math.round(lbsFished * 10.0) / 10.0; + + 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(lbsFished:Number, dollarPerLb:Number):String + { + var moneyMade:Number = lbsFished * dollarPerLb; + moneyMade = Math.floor(moneyMade * 100.0) / 100.0; + + var zeroDec:String = ""; + if(moneyMade as int == moneyMade) + { + zeroDec = ".00"; + } + var moneyString:String = "$" + moneyMade + zeroDec; + return moneyString; + } + + ]]> + </mx:Script> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDay.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()" borderStyle="inset"> + + <mx:Script> + <![CDATA[ + import mx.controls.Text; + import mx.controls.Label; + import mx.collections.ArrayCollection; + + [Bindable] public var numBays:int = 3; + [Bindable] public var decisions:ArrayCollection; + + public var previousTotal:Number = 0; + public var presentTotal:Number = 0; + public var day:int = 1; + public var dollarPerLb:Number = 3.99; + + public function init():void + { + if(decisions == null) + { + drawNull(); + } + else if(decisions.length < numBays+1) + { + drawPartial(); + } + else + { + drawFull(); + } + } + + public function drawNull():void + { + decisions = new ArrayCollection(); + + var temp:OneDecision = new OneDecision(); + temp.lbsFished = 0.0; + temp.initialize(); + temp.redraw(); + decisions.addItem(temp); + + drawPartial(); + } + + public function drawPartial():void + { + var temp:OneDecision; + for(var i:int = decisions.length; i < numBays+1; i++) + { + temp = new OneDecision(); + temp.active = false; + temp.initialize(); + temp.redraw(); + decisions.addItem(temp); + } + + drawFull(); + } + + public function drawFull():void + { + removeAllChildren(); + presentTotal = previousTotal; + + var dayText:Text = new Text(); + dayText.text = day + ""; + dayText.setStyle("textAlign","center"); + dayText.minWidth = 50; + addChild(dayText); + + for(var i:int = 0; i < numBays+1 && i < decisions.length; i++) + { + var temp:OneDecision = (decisions.getItemAt(i) as OneDecision); + presentTotal += temp.lbsFished; + addChild(temp.redraw()); + } + + var totalObject:TotalDisplay = new TotalDisplay(); + totalObject.lbsFished = presentTotal; + totalObject.dollarPerLb = dollarPerLb; + totalObject.initialize(); + addChild(totalObject.redraw()); + } + + public function load(locationChosen:int):OneDay + { + if(decisions == null || decisions.length != 0) + { + decisions = new ArrayCollection(); + } + + if(locationChosen == 0) + { + var temp:OneDecision = new OneDecision(); + temp.lbsFished = 0; + temp.initialize(); + decisions.addItem(temp); + } + else + { + for(var i:int = 0; i < locationChosen && i < numBays; i++) + { + var tempInactive:OneDecision = new OneDecision(); + tempInactive.active = false; + tempInactive.initialize(); + decisions.addItem(tempInactive); + } + + var tempActive:OneDecision = new OneDecision(); + tempActive.lbsFished = Math.round(Math.random()*50)/10.0; + tempActive.initialize(); + decisions.addItem(tempActive); + } + + drawPartial(); + + return this; + } + + ]]> + </mx:Script> + +</mx:HBox> Added: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDecision.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDecision.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/OneDecision.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Text xmlns:mx="http://www.adobe.com/2006/mxml" initialize="redraw()" textAlign="center" minWidth="125" minHeight="38"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + + [Bindable] public var active:Boolean = true; + [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():OneDecision + { + if(active) + { + htmlText = "Fished: "+getLbs()+"<br>People: "+findPeople(); + } + else + { + htmlText = "--"; + } + + return this; + } + + ]]> + </mx:Script> + +</mx:Text> \ No newline at end of file Added: mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/TotalDisplay.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/TotalDisplay.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/dayByDayDecisions/TotalDisplay.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Text xmlns:mx="http://www.adobe.com/2006/mxml" initialize="redraw()" textAlign="center" minWidth="60" minHeight="38"> + + <mx:Script> + <![CDATA[ + + [Bindable] public var lbsFished:Number = 0.0; + [Bindable] public var dollarPerLb:Number = 3.99; + + public function getLbs():String + { + lbsFished = Math.round(lbsFished * 10.0) / 10.0; + + 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; + moneyMade = Math.floor(moneyMade * 100.0) / 100.0; + + var zeroDec:String = ""; + if(moneyMade as int == moneyMade) + { + zeroDec = ".00"; + } + var moneyString:String = "$" + moneyMade + zeroDec; + return moneyString; + } + + public function redraw():TotalDisplay + { + htmlText = getLbs()+"<br>"+getMoney(); + return this; + } + + ]]> + </mx:Script> + +</mx:Text> Added: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastComponent.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,315 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()"> + + <mx:VBox id="labels" verticalGap="5" minWidth="{minimumWidth}" horizontalAlign="right"/> + + <mx:Script> + <![CDATA[ + import mx.controls.Alert; + import mx.events.FlexEvent; + import mx.controls.DataGrid; + import mx.collections.ArrayCollection; + import mx.controls.Label; + import mx.controls.dataGridClasses.DataGridColumn; + import mx.utils.StringUtil; + + // vital components + [Bindable] public var dataGrid:DataGrid; + [Bindable] public var dataProvider:ArrayCollection; + [Bindable] public var errorMessage:String = ""; + [Bindable] public var updaterObject:Object = null; + [Bindable] public var updater:Function = new Function(); + + [Bindable] public var currentColumn:int = 0; + + // Game Data + [Bindable] public var style:int = 0; // 0:People, 1:Fish, 2:Calculated + [Bindable] public var numBays:int = 3; + [Bindable] public var numColumns:int = -1; + [Bindable] public var numFields:int = 15; + [Bindable] public var minValue:int = 0; + [Bindable] public var maxValue:int = 5; + [Bindable] public var groupSize:int = 4; + [Bindable] public var finished:Boolean = false; + [Bindable] public var isEntry:Boolean = false; + + // for lining up grids + [Bindable] public var minimumWidth:int = 160; + + // + // public accessible functions + // + + public function init():void + { + labels.removeAllChildren(); + removeAllChildren(); + addChild(labels); + + createGrid(); + fillGridColumns(); + fillGridFields(); + setGridHeight(); + addChild(dataGrid); + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + for(var field:int = 0; field < dataProvider.length; field++) + { + saveArray.addItem(new ArrayCollection()); + for(var column:int = 0; column < dataGrid.columnCount; column++) + { + (saveArray.getItemAt(field) as ArrayCollection).addItem(getItem(field, column)); + } + } + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + for(var field:int = 0; field < loadArray.length && field < dataProvider.length; field++) + { + var loadSubArray:ArrayCollection = loadArray.getItemAt(field) as ArrayCollection; + for(var column:int = 0; column < loadSubArray.length && column < dataGrid.columnCount; column++) + { + setItem(field, column, loadSubArray.getItemAt(column)); + } + } + redraw(); + } + + public function changed(event:Object=null):void + { + if(isEntry && style != 2) // NOT 2:Calculated + { + errorCheck(); + } + try{updater.call(updaterObject);} + catch(err:Error){/* Alert.show(err.message+"\n"+err.getStackTrace()); */} + redraw(); + } + + public function getItem(field:Number, col:Number):Object + { + return dataProvider.getItemAt(field)["day"+(col+1)]; + } + public function setItem(field:Number, col:Number, value:Object):void + { + dataProvider.getItemAt(field)["day"+(col+1)] = value; + } + + public function redraw():void + { + dataGrid.invalidateList(); + } + + // + // private Utility functions + // + + private function addLabel(text:String="", html:Boolean=false):void + { + var newLabel:Label = new Label(); + if(text != "" && !html) + { + newLabel.text = text; + } + else if(html) + { + newLabel.htmlText = text; + } + labels.addChild(newLabel); + } + + private function addField():void + { + dataProvider.addItem(new Object()); + } + + private function createGrid():void + { + dataGrid = new DataGrid(); + dataGrid.id = "dataGrid"; + dataGrid.editable = true; + dataGrid.enabled = true; + dataGrid.addEventListener("change", changed); + } + + private function fillGridColumns():void + { + var columnArray:Array = dataGrid.columns; + for(var columnNumber:int = 0; columnNumber < numColumns; columnNumber++) + { + var newDataGridColumn:DataGridColumn = new DataGridColumn("day"+(columnNumber+1)); + newDataGridColumn.headerText = ""+(columnNumber+1); // 1, 2, 3, ... + newDataGridColumn.dataField = "day"+(columnNumber+1); // day1, day2, day3, ... + + newDataGridColumn.draggable = false; + newDataGridColumn.sortable = false; + newDataGridColumn.resizable = false; + newDataGridColumn.width = 30; + + newDataGridColumn.editable = (isEntry + && ((style == 0) || (style == 1)) + && columnNumber == 0); // 0:People, 1:Fish + if(newDataGridColumn.editable) + { + newDataGridColumn.setStyle("backgroundColor", "#FFFF00"); + } + + columnArray[columnNumber] = newDataGridColumn; + } + dataGrid.columns = columnArray; + + dataGrid.editable = (isEntry && ((style == 0) || (style == 1))); // 0:People, 1:Fish + } + + private function fillGridFields():void + { + dataProvider = new ArrayCollection(); + + addLabel(" <b>Day</b>:",true); + + var bayNumber:int = 0; + if(style==0) // 0:People + { + addLabel("# People in Harbor:"); + addField(); + + for(bayNumber=0; bayNumber<numBays; bayNumber++) + { + addLabel("# People in Bay " + (bayNumber+1) + ":"); + addField(); + } + } + else if(style==1) + { + for(bayNumber=0; bayNumber<numBays; bayNumber++) + { + addLabel("# Fish in Bay " + (bayNumber+1) + "(AM):"); + addField(); + } + } + else if(style==2) + { + addLabel("You will be in location #:"); + addField(); + addLabel("You will get USD:"); + addField(); + addLabel("Others will get USD:"); + addField(); + for(bayNumber=0; bayNumber<numBays; bayNumber++) + { + addLabel("# Fish in Bay " + (bayNumber+1) + "(PM):"); + addField(); + } + } + dataGrid.dataProvider = dataProvider; + numFields = dataProvider.length; + } + + private function setGridHeight():void + { + switch(style) + { + case(0): // 0:People + dataGrid.height = (23)*(numBays+2)-1; + break; + case(1): // 2:Fish + dataGrid.height = (23)*(numBays+1); + break; + case(2): // 3:Calculated + dataGrid.height = (23)*(numBays+4)-3; + break; + } + } + + private function errorCheck():Boolean + { + if(currentColumn >= dataGrid.columnCount) + { + errorMessage = "Click 'Forward' to continue to the next page."; + return true; + } + markNoError(); + errorMessage = "Click 'Update' to continue."; + var error:Boolean = false; + + var colSum:Number = 0; + for(var field:Number=0; field < numFields && !error; field++) + { + var value:Object = getItem(field, currentColumn); + if(!validNum(value)) + { + errorMessage = "Enter a value between "+minValue+" and "+maxValue+"."; + error = true; + } + else if(!inBounds(value)) + { + errorMessage = "Value must be between "+minValue+" and "+maxValue+"."; + error = true; + } + else if(style == 0) // 0:People + { + colSum += Number(value); + } + } + + if(!error && style == 0 && colSum != groupSize-1) // 0:People + { + errorMessage = "Sum of all columns must be exactly "+(groupSize-1)+"."; + error = true; + } + + + finished = !error; + return finished; + } + + private function validNum(n:Object):Boolean + { + if(n == null) return false; + var pattern:RegExp = /^\d+$/; //the entire string must be consecutive digits + var s:String = StringUtil.trim(String(n)); + return (n is Number) || pattern.test(s); + } + private function inBounds(n:Object):Boolean + { + return Number(n) >= minValue && Number(n) <= maxValue; + } + private function markNoError():void + { +// for(var column:Number=0; column < numColumns; column++) +// { +// DataGridColumn(dataGrid.columns[column]).setStyle("backgroundColor", "#FFFFFF"); +// } + dataGrid.selectedIndex = -1; + } + + public function updateNextColumn():void + { + if(errorCheck()) + { + dataGrid.columns[currentColumn].setStyle("backgroundColor", "#FFFFFF"); + dataGrid.columns[currentColumn].editable = false; + currentColumn = fix(currentColumn+1,0,dataGrid.columnCount) as int; + if(currentColumn < dataGrid.columnCount) + { + dataGrid.columns[currentColumn].editable = true; + dataGrid.columns[currentColumn].setStyle("backgroundColor", "#FFFF00"); + } + } + } + private function fix(n:Number,min:Number,max:Number):Number + { + if(n < min) return min; + if(n > max) return max; + return n; + } + + ]]> + </mx:Script> + +</mx:HBox> Added: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingFishQuestionC.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,99 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:components="custom.questions.forecasting.*"> + + <mx:String id="description"></mx:String> + + <components:ForecastComponent id="fishEntry" style="1" isEntry="true" + numBays="{numBays}" numColumns="{numColumns}" initialize="false" + updaterObject="{this}" updater="{recalculate}"/> + <components:ForecastComponent id="peopleDisplay" style="0" isEntry="false" + numBays="{numBays}" numColumns="15" initialize="false"/> + <components:ForecastComponent id="calculated" style="2" isEntry="false" + numBays="{numBays}" numColumns="{numColumns}" initialize="false"/> + + <mx:HBox> + <mx:Spacer width="160"/> + <mx:VBox> + <mx:Button id="btnUpdate" label="Update" click="fishEntry.updateNextColumn()"/> + <mx:Label id="lblError" text="{fishEntry.errorMessage}"/> + </mx:VBox> + </mx:HBox> + + <mx:Script> + <![CDATA[ + import mx.controls.Alert; + import actionscript.questions.ForecastingFish; + import mx.collections.ArrayCollection; + import custom.questions.forecasting.ForecastComponent; + + public var loadFish:ArrayCollection = null; + public var loadPeople:ArrayCollection = null; + + [Bindable] public var numBays:int = 3; + [Bindable] public var numColumns:int = 6; + + public function init():void + { + fishEntry.initialize(); fishEntry.init(); + peopleDisplay.initialize(); peopleDisplay.init(); + calculated.initialize(); calculated.init(); + + if(loadFish != null) + { + fishEntry.load(loadFish); + } + if(loadPeople != null) + { + peopleDisplay.load(loadPeople); + } + } + + public function save():ArrayCollection + { + return fishEntry.save(); + } + public function load(newFishEntry:ArrayCollection,newPeopleDisplay:ArrayCollection):void + { + loadFish = newFishEntry; + loadPeople = newPeopleDisplay; + init(); + } + public function loadPeopleOnly(newPeopleDisplay:ArrayCollection):void + { + loadPeople = newPeopleDisplay; + peopleDisplay.load(loadPeople); + } + public function loadFromQuestion(question:ForecastingFish):void + { + description = question.question; + + initialize(); + init(); + } + + public function recalculate():void + { + var currLoc:int = 0; + + var fishCols:int = fishEntry.dataGrid.columns.length; + var pplCols:int = peopleDisplay.dataGrid.columns.length; + var calcCols:int = calculated.dataGrid.columns.length; + + for(var column:int = 0; column < fishCols && column < pplCols && column < calcCols; column++) + { + calculated.setItem(0,column,currLoc); + calculated.setItem(1,column,0); + calculated.setItem(2,column,0); + + for(var bay:int = 0; bay < numBays; bay++) + { + calculated.setItem(3+bay,column,Number(fishEntry.getItem(bay,column)) * 0.9); + } + } + calculated.redraw(); + } + + ]]> + </mx:Script> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/forecasting/ForecastingPeopleQuestionC.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,58 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:components="custom.questions.forecasting.*"> + + <mx:String id="description"></mx:String> + + <components:ForecastComponent id="peopleEntry" style="0" isEntry="true" + numBays="{numBays}" numColumns="{numColumns}" initialize="false"/> + + <mx:HBox> + <mx:Spacer width="160"/> + <mx:VBox> + <mx:Button id="btnUpdate" label="Update" click="peopleEntry.updateNextColumn()"/> + <mx:Label id="lblError" text="{peopleEntry.errorMessage}"/> + </mx:VBox> + </mx:HBox> + + <mx:Script> + <![CDATA[ + import actionscript.questions.ForecastingPeople; + import mx.collections.ArrayCollection; + import custom.questions.forecasting.ForecastComponent; + + public var loadPeople:ArrayCollection = null; + + [Bindable] public var numBays:int = 3; + [Bindable] public var numColumns:int = 15; + + public function init():void + { + peopleEntry.initialize(); peopleEntry.init(); + + if(loadPeople != null) + { + peopleEntry.load(loadPeople); + } + } + + public function save():ArrayCollection + { + return peopleEntry.save(); + } + public function load(newPeopleDisplay:ArrayCollection):void + { + loadPeople = newPeopleDisplay; + init(); + } + public function loadFromQuestion(question:ForecastingPeople):void + { + description = question.question; + + initialize(); + init(); + } + + ]]> + </mx:Script> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/questions/psychometric/PsychometricQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/psychometric/PsychometricQuestionC.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/psychometric/PsychometricQuestionC.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,118 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:qComp="custom.questions.psychometric.*" initialize="false"> + + <mx:String id="description"></mx:String> + + <mx:Canvas id="content" minHeight="30" maxHeight="90"> + <!-- Used for bipolar psychometric scales --> + <mx:Label id="topleft" text="topleft" x="0" y="0" width="100" textAlign="left" visible="false"/> + <mx:Label id="topmid" text="topmid" x="150" y="0" width="100" textAlign="center" visible="false"/> + <mx:Label id="topright" text="topright" x="300" y="0" width="100" textAlign="right" visible="false"/> + + <!-- Used for unipolar psychometric scales --> + <mx:Label id="farleft" text="farleft" x="0" y="0" width="100" textAlign="center" visible="false"/> + <mx:Label id="farright" text="farright" x="300" y="0" width="100" textAlign="center" visible="false"/> + </mx:Canvas> + + <mx:Script> + <![CDATA[ + import actionscript.questions.PsychometricQuestion; + import mx.collections.ArrayCollection; + import custom.questions.psychometric.Slider; + + public var labels:ArrayCollection = new ArrayCollection(); + [Bindable] public var maxValue:Number; + [Bindable] public var slider1:Slider; + + public function init():void + { + if(labels != null) + { + slider1 = new Slider(); + + if(labels.length == 2) + { + farleft.text = (String)(labels.getItemAt(0)); + farright.text = (String)(labels.getItemAt(1)); + farleft.visible = true; + farright.visible = true; + content.removeChild(topleft); + content.removeChild(topmid); + content.removeChild(topright); + slider1.isBipolar = false; + slider1.x = 100; + slider1.y = 0; + } + else if(labels.length == 3) + { + topleft.text = (String)(labels.getItemAt(0)); + topmid.text = (String)(labels.getItemAt(1)); + topright.text = (String)(labels.getItemAt(2)); + topleft.visible = true; + topmid.visible = true; + topright.visible = true; + content.removeChild(farleft); + content.removeChild(farright); + slider1.isBipolar = true; + slider1.x = 0; + slider1.y = 36; + } + + initializeSlider(); + } + } + + public function initializeSlider():void + { + slider1.maxValue = maxValue; + slider1.initialize(); + slider1.init(); + if(!(content.contains(slider1))) + { + content.addChild(slider1); + } + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + saveArray.addItem(slider1.sliderButton.visible); + saveArray.addItem(slider1.sliderButton.x); + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + slider1.sliderButton.visible = loadArray.getItemAt(0) as Boolean; + slider1.sliderButton.move(loadArray.getItemAt(1) as Number, 0); + } + + public function loadFromQuestion(question:PsychometricQuestion):void + { + description = question.question; + + maxValue = question.numberOfIntervals; + labels = loadChoices(question); + + initialize(); + init(); + } + private function loadChoices(question:PsychometricQuestion):ArrayCollection + { + var choices:ArrayCollection = new ArrayCollection(); + + if(question.choices != null && question.choices.length >= 2) + { + for(var i:int = 0; i < question.choices.length; i++) + { + choices.addItem(question.choices.getItemAt(i)); + } + } + + return choices; + } + + ]]> + </mx:Script> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/questions/psychometric/Slider.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/psychometric/Slider.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/psychometric/Slider.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,117 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml"> + + <mx:Script> + <![CDATA[ + import mx.controls.Label; + import mx.controls.Text; + + [Bindable] + [Embed(source="SliderImage.png")] + private var sliderImage:Class; + + // Psychometric Variables - (Left = Positive, Right = Negative) + public var maxValue:Number = 10; // Leftmost value + public static var abstainValue:Number = -999; // Refusal to answer + private static var unipolarWidth:Number = 200; + private static var bipolarWidth:Number = 400; + private static var imageWidth:Number = 4; + + private var minValue:Number; // Rightmost value + private var value:Number; // value selected + + [Bindable] public var getVal:Number; // (for binding: same value as last getValue() method call) + public var isBipolar:Boolean; // double slider = true, single slider = false + + // prepare Slider in default (abstain) position + public function init():void + { + addEventListener(MouseEvent.MOUSE_DOWN, mouseMove); + addEventListener(MouseEvent.MOUSE_UP, mouseMove); + + if(isBipolar) + { + sliderBar.width = bipolarWidth + imageWidth; + minValue = -maxValue; + } + else + { + sliderBar.width = unipolarWidth + imageWidth; + minValue = 0; + } + + addTicks(); + reset(); + } + + private function addTicks():void + { + var numTicks:Number = maxValue - minValue + 1; + var separation:Number = (sliderBar.width - imageWidth) / (numTicks-1) + + var ticks:Array = new Array(numTicks); + + for(var i:Number = 0; i < numTicks; i++) + { + var tick:Label = new Label(); + tick.htmlText = "<b>.</b>"; + tick.x = i*separation - imageWidth/2; + tick.y = -10; + addChild(tick); + } + } + + private function mouseMove(event:MouseEvent):void + { + sliderButton.visible = true; + updateValue(); + } + + public function getValue():Number + { + if(sliderButton.visible) + { + getVal = value; + } + else + { + getVal = abstainValue; + } + return getVal; + } + + private function updateValue():void + { + var separation:Number = (sliderBar.width - imageWidth) / (maxValue - minValue) + var index:Number = Math.round((mouseX-imageWidth/2) / separation); // snap to nearest valid position + + value = maxValue - index; // flips scale so positive numbers on left + if(value > maxValue) value = maxValue; + if(value < minValue) value = minValue; + index = maxValue - value; + + getValue(); // updates the bindable "getVal" variable + + var xPos:Number = index * separation; + sliderButton.move(xPos, 0); + } + + public function reset():void + { + sliderButton.visible = false; + updateValue(); + sliderButton.move(0,0); + } + + ]]> + </mx:Script> + + <!-- change X value to 1/2 the width of the sliderButton image --> + <mx:HBox id="sliderBar" + height="3" x="0" y="15" + borderStyle="solid" borderColor="#000000" borderThickness="1" + /> + + <mx:Image id="sliderButton" x="0" y="0" source="{sliderImage}"/> + +</mx:Canvas> Added: mentalmodels/trunk/flex/src/custom/questions/psychometric/SliderImage.png =================================================================== (Binary files differ) Property changes on: mentalmodels/trunk/flex/src/custom/questions/psychometric/SliderImage.png ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/Planner.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,116 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="custom.*" initialize="init()" + width="350" height="200" + borderStyle="solid" verticalScrollPolicy="off" horizontalScrollPolicy="off"> + + <mx:Script> + <![CDATA[ + import mx.collections.ArrayCollection; + import mx.controls.Label; + + public var valueRequired:Boolean = false; + + private function init():void + { + if(valueRequired) + { + addRow(); + } + } + + public function childRemoved():void + { + numbers.removeChildAt(numbers.numChildren-1); + } + + public function addRow():PlannerRow + { + var newRow:PlannerRow = new PlannerRow(); + newRow.valueRequired = this.valueRequired; + var newNumber:Label = new Label(); + newNumber.text = "" + (numbers.numChildren+1); + newNumber.height = 22; + + grid.addChildAt(newRow, grid.numChildren); + numbers.addChild(newNumber); + + return newRow; + } + + public function getPlannerRow(index:Number):PlannerRow + { + if(index < grid.numChildren && index >= 0) + { + return (PlannerRow)(grid.getChildAt(index)); + } + return null; + } + public function getPlannerList(index:Number):ArrayCollection + { + var row:PlannerRow = getPlannerRow(index); + if(row == null) + { + return null; + } + var list:ArrayCollection = new ArrayCollection([row.getLocation(), row.getDays(), row.getThreshold()]); + return list; + } + public function setPlannerList(index:Number, newValues:ArrayCollection):void + { + var row:PlannerRow = getPlannerRow(index); + if(row == null) + { + row = addRow(); + } + row.setLocation(newValues.getItemAt(0) as String); + row.setDays(newValues.getItemAt(1) as Number); + row.setThreshold(newValues.getItemAt(2) as Number); + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + + for(var index:Number = 0; index < grid.numChildren; index++) + { + saveArray.addItem(getPlannerList(index)); + } + + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + grid.removeAllChildren(); + numbers.removeAllChildren(); + for(var index:Number = 0; index < loadArray.length; index++) + { + setPlannerList(index, loadArray.getItemAt(index) as ArrayCollection); + } + } + + ]]> + </mx:Script> + + <mx:HBox id="newButtonBox"> + <mx:Label text="" width="12"/> + <mx:Button id="newButton" label="New" click="addRow()" width="60"/> + <!--<mx:Label text="-" width="80" textAlign="center"/> + <mx:Label text="-" width="50" textAlign="center"/> + <mx:Label text="-" width="80" textAlign="center"/>--> + </mx:HBox> + + <mx:HBox id="headerBox"> + <mx:Label text="#" fontWeight="bold" paddingBottom="-3" width="12"/> + <mx:Label text="Remove" fontWeight="bold" paddingBottom="-3" width="60" textAlign="center"/> + <mx:Label text="Location" fontWeight="bold" paddingBottom="-3" width="80" textAlign="center"/> + <mx:Label text="Days" fontWeight="bold" paddingBottom="-3" width="50" textAlign="center"/> + <mx:Label text="Threshold" fontWeight="bold" paddingBottom="-3" width="80" textAlign="center"/> + </mx:HBox> + + <mx:HBox horizontalScrollPolicy="off" height="147" width="100%"> + <mx:VBox id="numbers" width="12"/> + <mx:VBox id="grid" childRemove="childRemoved()"/> + </mx:HBox> + +</mx:VBox> Added: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/PlannerRow.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,77 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"> + + <mx:Script> + <![CDATA[ + + public var valueRequired:Boolean = false; + + public function deleteMe():void + { + if(!valueRequired || parent.numChildren > 1) + { + parent.removeChild(this); + } + } + + public function changedLocation():void + { + threshold.visible = (location.selectedIndex != 0); + threshold.enabled = threshold.visible; + } + + public function getLocation():String + { + if(location.selectedIndex == 0) + { + return "Harbor"; + } + return "Bay " + location.selectedIndex; + } + public function setLocation(newValue:String):void + { + if(newValue == "Harbor") location.selectedIndex = 0; + if(newValue == "Bay 1") location.selectedIndex = 1; + if(newValue == "Bay 2") location.selectedIndex = 2; + if(newValue == "Bay 3") location.selectedIndex = 3; + changedLocation(); + } + public function getDays():Number + { + return days.value; + } + public function setDays(newValue:Number):void + { + days.value = newValue; + } + public function getThreshold():Number + { + if(location.selectedIndex == 0) + { + return -1; + } + return threshold.value; + } + public function setThreshold(newValue:Number):void + { + if(newValue == -1) return; + threshold.value = newValue; + } + + ]]> + </mx:Script> + + <mx:ArrayCollection id="locs"> + <mx:Object label="Harbor" data="Harbor"/> + <mx:Object label="Bay 1" data="Bay 1"/> + <mx:Object label="Bay 2" data="Bay 2"/> + <mx:Object label="Bay 3" data="Bay 3"/> + </mx:ArrayCollection> + + + <mx:Button id="deleteRow" label="Del" click="deleteMe()" width="60"/> + <mx:ComboBox id="location" dataProvider="{locs}" change="changedLocation()" width="80"/> + <mx:NumericStepper id="days" value="1" minimum="1" maximum="30" stepSize="1" width="50"/> + <mx:NumericStepper id="threshold" value="0.5" stepSize="0.1" minimum="0" maximum="100" enabled="false" visible="false" width="80"/> + +</mx:HBox> Added: mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml =================================================================== --- mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml (rev 0) +++ mentalmodels/trunk/flex/src/custom/questions/strategyDesign/StrategyDesignQuestionC.mxml 2009-07-05 23:58:17 UTC (rev 172) @@ -0,0 +1,75 @@ +<?xml version="1.0" encoding="utf-8"?> +<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:qComp="custom.questions.strategyDesign.*"> + + <mx:String id="description"></mx:String> + + <mx:HBox> + <mx:VBox> + <mx:Label text="Not Repeated decisions (start-up)" fontSize="18"/> + <qComp:Planner id="notRepeated"/> + </mx:VBox> + <mx:VBox> + <mx:Label text="Repeated decisions (after start-up)" fontSize="18"/> + <qComp:Planner id="repeated" valueRequired="true"/> + </mx:VBox> + </mx:HBox> + + <mx:HBox> + <mx:Label text="Suspend repetition:" fontWeight="bold" width="130"/> + <mx:Label text="If during one repetition"/> + <mx:NumericStepper id="suspendWeight" value="5" minimum="0.1" maximum="100" stepSize="0.1" height="20" width="50"/> + <mx:Label text="lbs could not be fished,"/> + </mx:HBox> + <mx:HBox> + <mx:Label width="113"/> + <mx:Label text="then stay in the harbor for"/> + <mx:NumericStepper id="suspendDays" value="1" minimum="0" maximum="30" stepSize="1" height="20" width="50"/> + <mx:Label text="days before starting the next repetition."/> + </mx:HBox> + + <mx:Script> + <![CDATA[ + import actionscript.questions.Question; + import mx.collections.ArrayCollection; + + public function getNotRepeated():ArrayCollection + { return notRepeated.save(); } + + public function getRepeated():ArrayCollection + { return repeated.save(); } + + public function accept():Boolean + { + return true; + } + + public function save():ArrayCollection + { + var saveArray:ArrayCollection = new ArrayCollection(); + saveArray.addItem(notRepeated.save()); + saveArray.addItem(repeated.save()); + saveArray.addItem(suspendWeight.value); + saveArray.addItem(suspendDays.value); + return saveArray; + } + + public function load(loadArray:ArrayCollection):void + { + notRepeated.load(loadArray.getItemAt(0) as ArrayCollection); + repeated.load(loadArray.getItemAt(1) as ArrayCollection); + suspendWeight.value = loadArray.getItemAt(2) as Number; + suspendDays.value = loadArray.getItemAt(3) as Number; + } + + public function loadFromQuestion(question:Question):void + { + description = question.question; + + initialize(); +// init(); + } + + ]]> + </mx:Script> + +</mx:VBox> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |