/jEdit/tags/jedit-4-1-pre5/bsh/commands/frame.bsh
# · Unknown · 52 lines · 41 code · 11 blank · 0 comment · 0 complexity · d68b156d903e45fb9236ac5545748411 MD5 · raw file
- /**
- Show component in a frame, centered and packed. Handle disposal.
- <p>
- Display the component, centered and packed, in a Frame, JFrame, or
- JInternalFrame. Returns the frame. If the GUI desktop is running then a
- JInternaFrame will be used and automatically added to the desktop.
- Otherwise if Swing is available a top level JFrame will be created.
- Otherwise a plain AWT Frame will be created.
- @method Frame | JFrame | JInternalFrame frame( Component component )
- */
- bsh.help.frame = "usage: frame( Component component )";
-
- import java.awt.*;
- import bsh.Capabilities;
- frame( Component comp ) {
- // Ignore unhandled method invocations from listeners.
- invoke( method, args ) { }
- windowClosing( event ) {
- frame.dispose();
- }
- // if the desktop is there make an internal frame
- if ( bsh.system.desktop != void ) {
- frame = bsh.system.desktop.makeInternalFrame("frame");
- frame.setClosable(true);
- frame.getContentPane().add( comp, "Center" );
- frame.pack(); // must pack before adding to desktop?
- bsh.system.desktop.addInternalFrame( frame );
- } else {
- // make an external JFrame or Frame
- if ( Capabilities.haveSwing() ) {
- frame = new javax.swing.JFrame();
- frame.getContentPane().add( comp, "Center" );
- } else {
- frame = new Frame();
- frame.add( comp, "Center" );
- }
- frame.addWindowListener(this);
- frame.pack();
- }
- frame.show();
- return frame;
- }