PageRenderTime 80ms CodeModel.GetById 76ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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