root/air/AS3UnitGUI/dev/AS3UnitGUI.mxml

リビジョン 293, 8.3 kB (コミッタ: yossy, コミット時期: 10 ヶ月 前)

Imported AS3Unit.

Line 
1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:WindowedApplication
3         xmlns:mx="http://www.adobe.com/2006/mxml"
4         xmlns:as3unit="org.libspark.as3unit.components.*"
5         layout="absolute"
6         title="AS3UnitGUI"
7         applicationComplete="applicationCompleteHandler()">
8     <mx:Script>
9         <![CDATA[
10             import mx.controls.Alert;
11             import mx.events.FileEvent;
12             import flash.filesystem.*;
13            
14             private var so:SharedObject;
15             private var defaultFile:File;
16             private var source:File;
17             private var testSwf:Loader;
18             private var testClass:Class;
19            
20             private function applicationCompleteHandler():void
21             {
22                 var soData:Object;
23                
24                 try {
25                     so = SharedObject.getLocal("AS3UnitGUI");
26                     soData = so.data;
27                 }
28                 catch (e:Error) {
29                     so = null;
30                     soData = new Object();
31                 }
32                
33                 if ('swfPath' in soData) {
34                     swfPathField.text = soData.swfPath;
35                 }
36                 if ('className' in soData) {
37                     classNameField.text = soData.className;
38                 }
39                
40                 defaultFile = File.documentsDirectory.resolve("as3unit");
41                 updateRunButtonEnabled();
42                
43                 source = defaultFile.parent;
44                 source.addEventListener(Event.SELECT, fileSelectedHandler);
45                
46                 if ('reload' in soData) {
47                     reloadCheck.selected = soData.reload;
48                 }
49                
50                 var window:NativeWindow = stage.window;
51                 window.width = 'w' in soData ? soData.w : 500;
52                 window.height = 'h' in soData ? soData.h : 550;
53                 if ('x' in soData) {
54                     window.x = soData.x;
55                 }
56                 if ('y' in soData) {
57                     window.y = soData.y;
58                 }
59                 window.addEventListener(NativeWindowBoundsEvent.MOVE, windowMoveHandler);
60                 window.addEventListener(NativeWindowBoundsEvent.RESIZE, windowResizeHandler);
61                 window.addEventListener(Event.CLOSE, windowCloseHandler);
62                 window.visible = true;
63             }
64            
65             private function windowMoveHandler(event:Event):void
66             {
67                 if (so) {
68                     so.data.x = stage.window.x;
69                     so.data.y = stage.window.y;
70                 }
71             }
72            
73             private function windowResizeHandler(event:Event):void
74             {
75                if (so) {
76                    so.data.w = stage.window.width;
77                    so.data.h = stage.window.height;
78                }
79             }
80            
81             private function windowCloseHandler(event:Event):void
82             {
83                 if (so) {
84                     so.flush();
85                 }
86             }
87            
88             private function reloadCheckClickHandler():void
89             {
90                 if (so) {
91                     so.data.reload = reloadCheck.selected;
92                 }
93             }
94            
95             private function selectFile():void
96             {
97                 if (swfPathField.text.length > 0) {
98                     source.nativePath = swfPathField.text;
99                     source = source.parent;
100                 }
101                 if (!source || !source.exists || !source.isDirectory) {
102                     source = defaultFile.parent;
103                 }
104                 source.browseForOpen("SWF Selection", [new FileFilter("SWF (*.swf)", "*.swf")]);
105             }
106            
107             private function fileSelectedHandler(event:Event):void
108             {
109                 swfPathField.text = source.nativePath;
110             }
111            
112             private function swfPathFieldChangeHandler():void
113             {
114                 testSwf = null;
115                 updateRunButtonEnabled();
116                 if (so) {
117                     so.data.swfPath = swfPathField.text;
118                 }
119             }
120            
121             private function classNameFieldChangeHandler():void
122             {
123                 testClass = null;
124                 updateRunButtonEnabled();
125                 if (so) {
126                     so.data.className = classNameField.text;
127                 }
128             }
129            
130             private function updateRunButtonEnabled():void
131             {
132                 runButton.enabled = swfPathField.text.length > 0 && classNameField.text.length > 0;
133             }
134            
135             private function runButtonClickHandler():void
136             {
137                 if (!testSwf || reloadCheck.selected) {
138                     var stream:FileStream = new FileStream();
139                     var swfFile:File = new File(swfPathField.text);
140                     testSwf = new Loader();
141                     testSwf.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, swfLoadIOErrorHandler);
142                     testSwf.contentLoaderInfo.addEventListener(Event.COMPLETE, swfLoadCompleteHandler);
143                     try {
144                         stream.open(swfFile, FileMode.READ);
145                         var bytes:ByteArray = new ByteArray();
146                         stream.readBytes(bytes);
147                         testSwf.loadBytes(bytes);
148                     }
149                     catch (e:IOError) {
150                         Alert.show("Cat not load SWF file.");
151                     }
152                     finally {
153                         stream.close();
154                     }
155                 }
156                 else if (testClass) {
157                     runTests(testClass);
158                 }
159             }
160            
161             private function resetSwfHandler(dispatcher:EventDispatcher):void
162             {
163                 dispatcher.removeEventListener(IOErrorEvent.IO_ERROR, swfLoadIOErrorHandler);
164                 dispatcher.removeEventListener(Event.COMPLETE, swfLoadCompleteHandler);
165             }
166            
167             private function swfLoadIOErrorHandler(event:Event):void
168             {
169                 resetSwfHandler(testSwf.contentLoaderInfo);
170                 Alert.show("Can not load SWF file.");
171             }
172            
173             private function swfLoadCompleteHandler(event:Event):void
174             {
175                 resetSwfHandler(testSwf.contentLoaderInfo);
176                
177                 var appDomain:ApplicationDomain = testSwf.contentLoaderInfo.applicationDomain;
178                 var className:String = classNameField.text;
179                
180                 if (!appDomain.hasDefinition(className)) {
181                     Alert.show("Class<" + className + "> was not found in swf.");
182                     return;
183                 }
184                
185                 var clazz:Class = appDomain.getDefinition(className) as Class;
186                 if (!clazz) {
187                     Alert.show("Definition<" + className + "> is not Class.");
188                     return;
189                 }
190                
191                 testClass = clazz;
192                 runTests(clazz);
193             }
194            
195             private function runTests(testClass:Class):void
196             {
197                 as3unit.run(testClass);
198             }
199         ]]>
200     </mx:Script>
201     <mx:VBox width="100%" height="100%"
202                 paddingBottom="10" paddingLeft="10"
203                 paddingRight="10" paddingTop="10">
204                 <mx:Label text="SWF file that contains test classes:"/>
205                 <mx:HBox width="100%">
206                         <mx:TextInput id="swfPathField" width="100%" change="swfPathFieldChangeHandler()"/>
207                         <mx:Button id="swfSelectButton" label="Select..." click="selectFile()"/>
208                 </mx:HBox>
209                
210                 <mx:Label text="Test class name:"/>
211                 <mx:HBox width="100%">
212                         <mx:TextInput id="classNameField" width="90%" change="classNameFieldChangeHandler()"/>
213                         <mx:Button id="runButton" label="Run" click="runButtonClickHandler()"/>
214                 </mx:HBox>
215                
216                 <mx:CheckBox id="reloadCheck" label="Reload classes every run" selected="true"
217                     click="reloadCheckClickHandler()"/>
218                
219                 <as3unit:AS3Unit id="as3unit"/>
220     </mx:VBox>
221 </mx:WindowedApplication>
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。