PageRenderTime 52ms CodeModel.GetById 48ms app.highlight 1ms RepoModel.GetById 2ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/bsh/commands/frame.bsh

#
Unknown | 53 lines | 43 code | 10 blank | 0 comment | 0 complexity | 234e261da35887dc9c6ec77f3d1a6b0f MD5 | raw file
 1/**
 2    Show component in a frame, centered and packed, handling disposal with
 3	the close button.
 4	<p>
 5
 6	Display the component, centered and packed, in a Frame, JFrame, or 
 7	JInternalFrame.  Returns the frame.  If the GUI desktop is running then a 
 8	JInternaFrame will be used and automatically added to the desktop.  
 9	Otherwise if Swing is available a top level JFrame will be created.  
10	Otherwise a plain AWT Frame will be created.
11
12	@method Frame | JFrame | JInternalFrame frame( Component component )
13
14*/
15bsh.help.frame = "usage: frame( Component component )";
16 
17import java.awt.*;
18import bsh.Capabilities;
19
20frame( Component comp ) 
21{
22	// Ignore unhandled method invocations from listeners.
23	invoke( method, args ) { }
24
25    windowClosing( event ) {
26        frame.dispose();
27    }
28
29	// if the desktop is there make an internal frame
30	if ( bsh.system.desktop != void ) {
31		this.frame = bsh.system.desktop.makeInternalFrame("frame");
32		frame.setClosable(true);
33		frame.getContentPane().add( comp, "Center" );
34    	frame.pack();  // must pack before adding to desktop?
35		bsh.system.desktop.addInternalFrame( frame );
36	} else {
37		// make an external JFrame or Frame
38		if ( Capabilities.haveSwing() ) {
39			this.frame = new javax.swing.JFrame();
40			frame.getContentPane().add( comp, "Center" );
41		} else {
42			this.frame = new Frame();
43			frame.add( comp, "Center" );
44		}
45
46		frame.addWindowListener(this);
47    	frame.pack();
48	}
49
50    frame.show();
51    return frame;
52}
53