Skip to content

Commit

Permalink
Re-organizing the examples and their tests, adding a build and copy s…
Browse files Browse the repository at this point in the history
…cript and adding combo box without label support, and DateChooser/DateField support
  • Loading branch information
admc committed Nov 5, 2010
1 parent 13fc5e9 commit 4450e13
Show file tree
Hide file tree
Showing 18 changed files with 635 additions and 80 deletions.
5 changes: 5 additions & 0 deletions build_and_copy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh

./build.py -t all
cp org/flex_pilot/FlexPilot.swf tests
(cd tests && ./build.py -t all)
10 changes: 9 additions & 1 deletion src/org/flex_pilot/FPController.as
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package org.flex_pilot {
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
import mx.events.*
import mx.controls.DateField;

public class FPController {
public function FPController():void {}
Expand Down Expand Up @@ -325,7 +326,14 @@ package org.flex_pilot {
// Do nothing
}
}


public static function date(params:Object):void {
// Look up the item to write to
var obj:* = FPLocator.lookupDisplayObject(params);
obj.selectedDate = DateField.stringToDate(params.date, "MM/DD/YYYY");
Events.triggerCalendarLayoutChangeEvent(obj);
}

public static function getTextValue(params:Object):String {
// Look up the item where we want to get the property
var obj:* = FPLocator.lookupDisplayObject(params);
Expand Down
34 changes: 28 additions & 6 deletions src/org/flex_pilot/FPRecorder.as
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ package org.flex_pilot {
import flash.events.KeyboardEvent;
import flash.external.ExternalInterface;
import mx.events.ListEvent;
import mx.events.CalendarLayoutChangeEvent;
import mx.controls.ComboBox;
import mx.controls.List;
import mx.controls.DateField;
import mx.core.IRawChildrenContainer;

public class FPRecorder {
Expand Down Expand Up @@ -69,6 +71,10 @@ package org.flex_pilot {
FPRecorder.listItems.push(item);
item.addEventListener(ListEvent.CHANGE, FPRecorder.handleEvent);
}
if (item is DateField) {
FPRecorder.listItems.push(item);
item.addEventListener(CalendarLayoutChangeEvent.CHANGE, FPRecorder.handleEvent);
}
if (item is DisplayObjectContainer) {
if (item is IRawChildrenContainer) {
count = item.rawChildren.numChildren;
Expand Down Expand Up @@ -98,7 +104,6 @@ package org.flex_pilot {
stage.addEventListener(MouseEvent.DOUBLE_CLICK, FPRecorder.handleEvent);
stage.addEventListener(TextEvent.LINK, FPRecorder.handleEvent);
stage.addEventListener(KeyboardEvent.KEY_DOWN, FPRecorder.handleEvent);

FPRecorder.running = true;
}

Expand All @@ -109,17 +114,28 @@ package org.flex_pilot {
stage.removeEventListener(MouseEvent.DOUBLE_CLICK, FPRecorder.handleEvent);
stage.removeEventListener(TextEvent.LINK, FPRecorder.handleEvent);
stage.removeEventListener(KeyboardEvent.KEY_DOWN, FPRecorder.handleEvent);

var list:Array = FPRecorder.listItems;
for each (var item:* in list) {
item.removeEventListener(ListEvent.CHANGE, FPRecorder.handleEvent);
if (item is ComboBox || item is List) {
item.removeEventListener(ListEvent.CHANGE, FPRecorder.handleEvent);
}
if (item is DateField) {
item.removeEventListener(CalendarLayoutChangeEvent.CHANGE, FPRecorder.handleEvent);
}
}
}

private static function handleEvent(e:*):void {
if (!FPRecorder.running) { return; }
var targ:* = e.target;
var _this:* = FPRecorder;
var chain:String = FPLocator.generateLocator(targ);


if (e.target is DateField) {
_this.generateAction("date", targ, {date: DateField.dateToString(e.newDate, "MM/DD/YYYY")});
return;
}
switch (e.type) {
// Keyboard input -- append to the stored string reference
case KeyboardEvent.KEY_DOWN:
Expand Down Expand Up @@ -239,9 +255,15 @@ package org.flex_pilot {
case 'select':
var sel:* = targ.selectedItem;
// Can set a custom label field via labelField attr
var labelField:String = targ.labelField ?
targ.labelField : 'label';
params.label = sel[labelField];
try {
var labelField:String = targ.labelField ?
targ.labelField : 'label';
params.label = sel[labelField];
}
catch (e:Error) {
var idx:* = targ.selectedIndex;
params.index = idx;
}
break;
case 'type':
break;
Expand Down
2 changes: 1 addition & 1 deletion src/org/flex_pilot/FlexPilot.as
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Copyright 2009, Matthew Eernisse ([email protected]) and Slide, Inc.

package org.flex_pilot {
import com.adobe.serialization.json.JSON;

import org.flex_pilot.astest.ASTest;
import org.flex_pilot.FPLocator;
import org.flex_pilot.FPController;
Expand Down
15 changes: 15 additions & 0 deletions src/org/flex_pilot/events/Events.as
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ package org.flex_pilot.events {
p.ctrlKey, p.altKey, p.shiftKey);
obj.dispatchEvent(ev);
}

public static function triggerListEvent(obj:*, type:String,
...args):void {
// AS3 Object keys don't iterate in insertion order
Expand All @@ -163,6 +164,20 @@ package org.flex_pilot.events {
p.itemRenderer);
obj.dispatchEvent(ev);
}

public static function triggerCalendarLayoutChangeEvent(obj:*,
...args):void {
var defaults:Array = [
['bubbles', false], // Don't override -- the real one doesn't bubble
['cancelable', false],
['newDate', null],
['triggerEvent', new Event("change")]
];
var p:Object = Events.normalizeParams(defaults, args);
var ev:CalendarLayoutChangeEvent = new CalendarLayoutChangeEvent("change",
p.bubbles, p.cancelable, p.newDate, p.triggerEvent);
obj.dispatchEvent(ev);
}
}
}

106 changes: 106 additions & 0 deletions tests/GetDocumentName.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
package
{

import flash.display.DisplayObject;
import flash.events.MouseEvent;

import mx.containers.ControlBar;
import mx.containers.Panel;
import mx.containers.VBox;
import mx.controls.Button;
import mx.controls.Label;
import mx.controls.Spacer;
import mx.controls.TextInput;
import mx.managers.PopUpManager;
import mx.styles.StyleManager;

public class GetDocumentName
{
private var panel:Panel;
private var parent:DisplayObject;
private var textInput:TextInput;


public function GetDocumentName(parent:DisplayObject) : void
{
var vb:VBox = new VBox();
vb.percentWidth = 100;
var label:Label = new Label();
var subHeader:Label = new Label();
textInput = new TextInput();

var cb:ControlBar = new ControlBar();
cb.percentWidth = 100;
var s:Spacer = new Spacer();
var b1:Button = new Button();
var b2:Button = new Button();

this.parent = parent;

s.width = 100;

textInput.maxChars = 50;
textInput.percentWidth = 100;
textInput.automationName = "modalSaveCancelButton";

b1.label = "Save";
b1.addEventListener(MouseEvent.CLICK, setName);
b1.automationName = "modalSaveSaveButton";
b1.width = 80;
b2.label = "Cancel";
b2.automationName = "modalSaveCancelButton";
b2.addEventListener(MouseEvent.CLICK, closePopUp);
b2.width = 80;

cb.addChild(s);
cb.addChild(b2);
cb.addChild(b1);

label.text = "Project Name:";
label.percentWidth = 100;

subHeader.text = "Enter your project name, and then click Save.";
subHeader.percentWidth = 100;


vb.setStyle("paddingBottom", 5);
vb.setStyle("paddingLeft", 5);
vb.setStyle("paddingRight", 5);
vb.setStyle("paddingTop", 5);
vb.addChild(subHeader);
vb.addChild(label);
vb.addChild(textInput);

panel = new Panel();
panel.title = "Save Your Project";
panel.width = 300;
panel.height = 175;
panel.addChild(vb);
panel.addChild(cb);
panel.automationName = "modalDialogSave";
}

private function setName(evt:MouseEvent):void
{

PopUpManager.removePopUp(panel);
}

private function closePopUp(evt:MouseEvent):void
{
PopUpManager.removePopUp(panel);
}

public function ShowPopUp(defaultName:String="Untitled Project") : void
{
var projName:String;

PopUpManager.addPopUp(panel, parent, true);
PopUpManager.centerPopUp(panel);
this.textInput.text = defaultName;
this.textInput.selectionBeginIndex = 0;
this.textInput.selectionEndIndex = textInput.length;
this.textInput.setFocus();
}
}
}
44 changes: 44 additions & 0 deletions tests/TestAccordion.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta http-equiv="pragma" content="no-cache">
<title>
</title>
<script type="text/javascript">
var testApp;
function init() {
var html = '';
var swfName = 'TestAccordion.swf';
if (document.all) {
html = '<object type="application/x-shockwave-flash"' +
' width="100%" height="100%" id="testApp">' +
' <param name="movie" value="' + swfName + '">' +
' <param name="quality" value="high">' +
' <param name="bgcolor" value="#ffffff">' +
'</object>';
}
else {
html = '<embed id="testApp" height="100%" width="100%"' +
' name="testApp" src="' + swfName + '"' +
' type="application/x-shockwave-flash"/>';
}
document.getElementById('testAppContainer').innerHTML = html;
testApp = document.getElementById('testApp')
}
/*function wmClick(p) {
testApp.wm_click(p);
}*/
window.onload = init;
</script>
<style type="text/css">
body {
overflow: hidden;
}
</style>
</head>
<body>
<div id="testAppContainer" style="width: 760px;
height: 340px; border: 1px solid #ccc;">
</div>
</body>
</html>
6 changes: 3 additions & 3 deletions tests/accordion.html → tests/TestBasic.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var testApp;
function init() {
var html = '';
var swfName = 'TestAccordion.swf';
var swfName = 'TestBasic.swf';
if (document.all) {
html = '<object type="application/x-shockwave-flash"' +
' width="100%" height="100%" id="testApp">' +
Expand All @@ -25,9 +25,9 @@
document.getElementById('testAppContainer').innerHTML = html;
testApp = document.getElementById('testApp')
}
/*function wmClick(p) {
function wmClick(p) {
testApp.wm_click(p);
}*/
}
window.onload = init;
</script>
<style type="text/css">
Expand Down
File renamed without changes.
44 changes: 44 additions & 0 deletions tests/TestCalendar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta http-equiv="pragma" content="no-cache">
<title>
</title>
<script type="text/javascript">
var testApp;
function init() {
var html = '';
var swfName = 'TestCalendar.swf';
if (document.all) {
html = '<object type="application/x-shockwave-flash"' +
' width="100%" height="100%" id="testApp">' +
' <param name="movie" value="' + swfName + '">' +
' <param name="quality" value="high">' +
' <param name="bgcolor" value="#ffffff">' +
'</object>';
}
else {
html = '<embed id="testApp" height="100%" width="100%"' +
' name="testApp" src="' + swfName + '"' +
' type="application/x-shockwave-flash"/>';
}
document.getElementById('testAppContainer').innerHTML = html;
testApp = document.getElementById('testApp')
}
/*function wmClick(p) {
testApp.wm_click(p);
}*/
window.onload = init;
</script>
<style type="text/css">
body {
overflow: hidden;
}
</style>
</head>
<body>
<div id="testAppContainer" style="width: 760px;
height: 340px; border: 1px solid #ccc;">
</div>
</body>
</html>
30 changes: 30 additions & 0 deletions tests/TestCalendar.mxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0"?>
<!-- controls\date\DateFieldFormat.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" applicationComplete="init();">
<mx:Script>
<![CDATA[
import org.flex_pilot.FPBootstrap;
private function init():void {
FPBootstrap.flex_pilotLibPath = 'FlexPilot.swf';
FPBootstrap.init(stage);
}
]]>
</mx:Script>
<mx:HBox>
<mx:ComboBox id="cb1">
<mx:ArrayCollection>
<mx:String>MM/DD/YY</mx:String>
<mx:String>MM/DD/YYYY</mx:String>
<mx:String>DD/MM/YY</mx:String>
<mx:String>DD/MM/YYYY</mx:String>
<mx:String>DD MM, YYYY</mx:String>
</mx:ArrayCollection>
</mx:ComboBox>

<mx:DateField id="date2"
editable="true"
width="100"
formatString="{cb1.selectedItem}"
/>
</mx:HBox>
</mx:Application>
Loading

0 comments on commit 4450e13

Please sign in to comment.