///////////////////////////////////////////////////////////////////////////////// // // pushButton.fs // Created By: Tobin Isenberg // Date: 11/06/2001 // Version: 1.0 // // Purpose: // Utility to assist in building a dialog with multiple buttons // and a text window that can be written too. This is just an // example. // // Required Changes: // none // // Notes 1: // This script should be included in // // Exposed functions: // // public var createDialog( String titleOfDialogWindow ) // // Overview: // Creates a dialog with the title of the dialog based on the contents // of titleOfDialogWindow. // // Returns: // Will return a var that can be used to add text to the dialog at any // point after the dialog is created including after buttons are pressed. // Will attempt to return null if an error occurred. // // Example: // var textHandle = createDialog( "My Window" ); // textHandle.append( "Hello World" ); // // public void addButton( String theButton , function FunctionName ); // // OverView: // Adds a button with the text of the button being the contents of // "theButton". When the button is pressed, the function will be // called that is referenced by "FunctionName"; // // Returns: // n/a // // Example: // function myFunction() { info( "hello world" ); } // addButton( "MyButton", myFunction ); // // public void closeDialog() // Overview: // Closes the existing dialog // // Returns: // n/a // // Example: // createDialog( "Hello World" ); // closeDialog(); // // // Implementing: // 1) Copy pushButton.fs and pushButtonTest.fs to installDir/database/scripts // 2) Right-Click on Administration/Server/Operation Definitions and choose // Create Operation // 3) Use the following information... // Name: Push Button Test // Menu Text: Push Button Test // Context: Element or Alarm // Match By: name expression // next box: .* // Permission: View // Type: Client script // Operation: load( "pushButtonTest.fs" ); // // By performing the right-click, an example dialog will show up. importPackage( java.awt ); // setup the dialog JF = Packages.javax.swing.JFrame; JP = new Packages.javax.swing.JPanel(); JL = new Packages.javax.swing.JLabel(); TA = java.awt.TextArea; var theFrame; var display; function createDialog( title ) { display = null; // create the Frame with title (or default title if title==null) if( title == null ) { title = "Make your selection"; } theFrame = new JF( title ); // set the text area on the frame w/Scroll bars display = new TA( "", 0, 0,TA.SCROLLBARS_BOTH ); // snap the window to the center of the screen theFrame.getContentPane().add( display, java.awt.BorderLayout.NORTH ); // set the size of the window theFrame.setSize( 400, 300 ); // get the size of the screen var size = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); // get the size of the dialog var dlgsize = theFrame.getSize(); // figure out what the middle of the screen is based on the dialog size theFrame.setLocation( ( size.width / 2 ) - ( dlgsize.width /2 ), ( size.height / 2 ) - ( dlgsize.height / 2 ) ); // show the window we just contructed theFrame.show(); // give them the handle to the text window so they can write to it. return display; } // Call this function to close the dialog function closeDialog() { // close and kill window theFrame.dispose() } // Call this function over and over to add buttons to the dialog // The first parm is the text for the button and the second // is the name of the function you want called if the button is pressed. function addButton( buttonText, functionToCallWhenPressed ) { if( buttonText == null ) { buttonText = " "; } // Create the buttons button1 = new Packages.javax.swing.JButton( buttonText) // add them to the JPanel JP.add( button1 ); // apply them to the JPanel centered theFrame.getContentPane().add(JP, BorderLayout.SOUTH); // show the window we just contructed theFrame.show(); // assign function to button B1F = { actionPerformed: functionToCallWhenPressed } // create a listener button1Listener = java.awt.event.ActionListener(B1F) // assign the listener to the button button1.addActionListener(button1Listener) } // eof() pushButton.fs