From: Scott H. <sco...@us...> - 2005-07-20 08:00:15
|
Update of /cvsroot/actionstep/actionstep/src/org/actionstep/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19739/src/org/actionstep/test Modified Files: ASTestMatrix.as Log Message: Added some things to help test keys and inserts Index: ASTestMatrix.as =================================================================== RCS file: /cvsroot/actionstep/actionstep/src/org/actionstep/test/ASTestMatrix.as,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** ASTestMatrix.as 1 Jun 2005 02:44:00 -0000 1.8 --- ASTestMatrix.as 20 Jul 2005 08:00:06 -0000 1.9 *************** *** 32,36 **** --- 32,44 ---- import org.actionstep.NSMatrix; import org.actionstep.constants.NSButtonType; + import org.actionstep.constants.NSAlertStyle; import org.actionstep.*; + import org.actionstep.NSWindow; + import org.actionstep.NSButton; + import org.actionstep.NSArray; + import org.actionstep.NSView; + import org.actionstep.NSTextField; + import org.actionstep.NSAlert; + import org.actionstep.NSPanel; /** *************** *** 41,51 **** class org.actionstep.test.ASTestMatrix { public static function test():Void { ! TRACE("application start"); ! var app:NSApplication = NSApplication.sharedApplication(); ! var window:NSWindow = (new NSWindow()).initWithContentRect(new NSRect(0,0,500,500)); ! var view:NSView = (new NSView()).initWithFrame(new NSRect(0,0,500,500)); var cell:NSButtonCell = (new NSButtonCell()).initTextCell("test"); cell.setButtonType(NSButtonType.NSRadioButton); --- 49,75 ---- class org.actionstep.test.ASTestMatrix { + public static var g_app:NSApplication; + public static var g_win:NSWindow; + public static function test():Void { ! var app:NSApplication; ! var window:NSWindow; ! var view:NSView; ! var addColumnButton:NSButton, addRowButton:NSButton, remColButton:NSButton, remRowButton:NSButton, ! insertColButton:NSButton, insertRowButton:NSButton; ! var insertColIdxInput:NSTextField, insertColTitleInput:NSTextField, insertRowIdxInput:NSTextField, ! insertRowTitleInput:NSTextField; + // + // Setup + // + app = g_app = NSApplication.sharedApplication(); + window = g_win = (new NSWindow()).initWithContentRect(new NSRect(0,0,800,600)); + view = (new NSView()).initWithFrame(new NSRect(0,0,500,500)); + + // + // Create matrix + // var cell:NSButtonCell = (new NSButtonCell()).initTextCell("test"); cell.setButtonType(NSButtonType.NSRadioButton); *************** *** 73,77 **** { var i = matrix.numberOfRows(); ! if(i==0) return; matrix.removeRow(i - 1); matrix.sizeToCells(); --- 97,105 ---- { var i = matrix.numberOfRows(); ! if(i==0) ! { ! ASTestMatrix.showErrorBox("No rows to remove."); ! return; ! } matrix.removeRow(i - 1); matrix.sizeToCells(); *************** *** 80,89 **** { var i = matrix.numberOfColumns(); ! if(i==0) return; matrix.removeColumn(i - 1); matrix.sizeToCells(); } ! var addColumnButton:NSButton = (new NSButton()).initWithFrame(new NSRect(10,10,100,30)); addColumnButton.setTitle("Add Column"); addColumnButton.setTarget(target); --- 108,150 ---- { var i = matrix.numberOfColumns(); ! if(i==0) ! { ! ASTestMatrix.showErrorBox("No columns to remove."); ! return; ! } ! matrix.removeColumn(i - 1); matrix.sizeToCells(); } + target.insertColumn = function() + { + var insert:Number = parseInt(insertColIdxInput.stringValue()); + + if (isNaN(insert) || insert < 0) + { + ASTestMatrix.showErrorBox("Insert index is out of range."); + return; + } + + cell = (new NSButtonCell()).initTextCell(insertColTitleInput.stringValue()); + matrix.insertColumnWithCells(insert, NSArray.arrayWithObject(cell)); + matrix.sizeToCells(); + } + target.insertRow = function() + { + var insert:Number = parseInt(insertRowIdxInput.stringValue()); + + if (isNaN(insert) || insert < 0) + { + ASTestMatrix.showErrorBox("Insert index is out of range."); + return; + } + + cell = (new NSButtonCell()).initTextCell(insertRowTitleInput.stringValue()); + matrix.insertRowWithCells(insert, NSArray.arrayWithObject(cell)); + matrix.sizeToCells(); + } ! addColumnButton = (new NSButton()).initWithFrame(new NSRect(10,10,100,30)); addColumnButton.setTitle("Add Column"); addColumnButton.setTarget(target); *************** *** 91,95 **** view.addSubview(addColumnButton); ! var addRowButton:NSButton = (new NSButton()).initWithFrame(new NSRect(120,10,100,30)); addRowButton.setTitle("Add Row"); addRowButton.setTarget(target); --- 152,156 ---- view.addSubview(addColumnButton); ! addRowButton = (new NSButton()).initWithFrame(new NSRect(120,10,100,30)); addRowButton.setTitle("Add Row"); addRowButton.setTarget(target); *************** *** 97,101 **** view.addSubview(addRowButton); ! var remRowButton:NSButton = (new NSButton()).initWithFrame(new NSRect(120,50,100,30)); remRowButton.setTitle("Remove Row"); remRowButton.setTarget(target); --- 158,162 ---- view.addSubview(addRowButton); ! remRowButton = (new NSButton()).initWithFrame(new NSRect(120,50,100,30)); remRowButton.setTitle("Remove Row"); remRowButton.setTarget(target); *************** *** 103,107 **** view.addSubview(remRowButton); ! var remColButton:NSButton = (new NSButton()).initWithFrame(new NSRect(10,50,100,30)); remColButton.setTitle("Remove Column"); remColButton.setTarget(target); --- 164,168 ---- view.addSubview(remRowButton); ! remColButton = (new NSButton()).initWithFrame(new NSRect(10,50,100,30)); remColButton.setTitle("Remove Column"); remColButton.setTarget(target); *************** *** 109,114 **** --- 170,232 ---- view.addSubview(remColButton); + insertColButton = (new NSButton()).initWithFrame(new NSRect(340,10,100,30)); + insertColButton.setTitle("Insert Column"); + insertColButton.setTarget(target); + insertColButton.setAction("insertColumn"); + view.addSubview(insertColButton); + + insertColIdxInput = (new NSTextField()).initWithFrame(new NSRect(230, 13, 20, 23)); + view.addSubview(insertColIdxInput); + + insertColTitleInput = (new NSTextField()).initWithFrame(new NSRect(250, 13, 80, 23)); + view.addSubview(insertColTitleInput); + + insertRowButton = (new NSButton()).initWithFrame(new NSRect(340,50,100,30)); + insertRowButton.setTitle("Insert Row"); + insertRowButton.setTarget(target); + insertRowButton.setAction("insertRow"); + view.addSubview(insertRowButton); + + insertRowIdxInput = (new NSTextField()).initWithFrame(new NSRect(230, 53, 20, 23)); + view.addSubview(insertRowIdxInput); + + insertRowTitleInput = (new NSTextField()).initWithFrame(new NSRect(250, 53, 80, 23)); + view.addSubview(insertRowTitleInput); + window.setContentView(view); + + // + // tabbing + // + window.setInitialFirstResponder(addColumnButton); + addColumnButton.setNextKeyView(addRowButton); + addRowButton.setNextKeyView(insertColIdxInput); + insertColIdxInput.setNextKeyView(insertColTitleInput); + insertColTitleInput.setNextKeyView(insertColButton); + insertColButton.setNextKeyView(remColButton); + remColButton.setNextKeyView(remRowButton); + remRowButton.setNextKeyView(insertRowIdxInput); + insertRowIdxInput.setNextKeyView(insertRowTitleInput); + insertRowTitleInput.setNextKeyView(insertRowButton); + insertRowButton.setNextKeyView(matrix); + matrix.setNextKeyView(addColumnButton); + app.run(); } + + + public static function showErrorBox(message:String):Void + { + var alert:NSAlert = (new NSAlert()).init(); + alert.addButtonWithTitle("OK"); + alert.setMessageText(message); + alert.setAlertStyle(NSAlertStyle.NSWarning); + alert.beginSheetModalForWindowModalDelegateDidEndSelectorContextInfo + (g_win, ASTestMatrix, "alertCallback", null); + } + + public static function alertCallback(sheet, ret:NSArray, ctxt:Object) + { + sheet.close(); + } } |