From: Tay R. C. <rc...@us...> - 2005-07-15 12:19:42
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15681/actionstep/org/actionstep/test Added Files: ASTestSheet.as Log Message: Simple sheet test --- NEW FILE: ASTestSheet.as --- /* * Copyright (c) 2005, InfoEther, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: * * 1) Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2) Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3) The name InfoEther, Inc. may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ import org.actionstep.*; import org.actionstep.test.*; import org.actionstep.constants.* class org.actionstep.test.ASTestSheet { public static var self = ASTestSheet, app:NSApplication = NSApplication.sharedApplication(), main:NSWindow, error:NSWindow, other:NSWindow, view1, view2,// view3, begin:NSButton, end:NSButton, textField:NSTextField, textField2:NSTextField public static function test() { TRACE("app: "+app); main= (new NSWindow()).initWithContentRectStyleMask(new NSRect(50,50,250,250), NSWindow.NSTitledWindowMask); main.setTitle("Main"); //error = (new NSWindow()).initWithContentRectStyleMask(new NSRect(125,100,250,250), NSWindow.NSTitledWindowMask); //error.setTitle("Error"); other = (new NSWindow()).initWithContentRectStyleMask(new NSRect(400,100,250,250), NSWindow.NSTitledWindowMask); other.setTitle("Some Other Window"); view1 = (new ASTestView()).initWithFrame(new NSRect(0,0,25,25)); view1.setBorderColor(new NSColor(0xFFF000)); view2 = (new ASTestView()).initWithFrame(new NSRect(0,0,250,250)); view2.setBorderColor(new NSColor(0xFF0000)); //view3 = (new ASTestView()).initWithFrame(new NSRect(0,0,250,250)); //view3.setBorderColor(new NSColor(0xFF0000)); begin = (new NSButton()).initWithFrame(new NSRect(10,80,70,30)); begin.setTitle("Error..."); begin.sendActionOn(NSEvent.NSLeftMouseUpMask); begin.setBezelStyle(NSBezelStyle.NSShadowlessSquareBezelStyle); end = (new NSButton()).initWithFrame(new NSRect(10,80,70,30)); end.setTitle("OK"); end.sendActionOn(NSEvent.NSLeftMouseUpMask); end.setBezelStyle(NSBezelStyle.NSShadowlessSquareBezelStyle); textField = (new NSTextField()).initWithFrame(new NSRect(10,160,120,30)); textField2 = (new NSTextField()).initWithFrame(new NSRect(10,160,120,30)); view1.addSubview(begin); view1.addSubview(textField); view2.addSubview(end); view2.addSubview(textField2); begin.setTarget(self); begin.setAction("trigger"); end.setTarget(self); end.setAction("stop"); main.setContentView(view1); error.setContentView(view2); //other.setContentView(view3); view2.setHidden(true); app.run(); } static var alert:NSAlert; //tracking starts before modal can start posing! public static function trigger(button) { TRACE("Starting sheet..."); alert = (new NSAlert()).init(); alert.addButtonWithTitle("OK"); alert.addButtonWithTitle("Cancel"); alert.addButtonWithTitle("Don't Save"); alert.setMessageText("Delete the record"); alert.setInformativeText("Deleted records cannot be restored."); alert.setAlertStyle(NSAlertStyle.NSWarning) main.resignKeyWindow(); view2.setHidden(false); alert.beginSheetModalForWindowModalDelegateDidEndSelectorContextInfo(main, self, "alertDidEndReturnCodeContextInfo", null); } public static function alertDidEndReturnCodeContextInfo(sheet, ret, ctxt) { var ans = ASUtils.findMatch([NSAlertReturn], ret); TRACE("button clicked: "+ans.prop); TRACE("releasing sheet... "+(sheet.release() ? "successful!" : "failed!")); } //look like NSObject public static function respondsToSelector(sel:String):Boolean { return self.hasOwnProperty(sel); } public static function toString():String { return "Test::ASTestPanel" } } |