PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /**
  2. Show component in a frame, centered and packed, handling disposal with
  3. the close button.
  4. <p>
  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. @method Frame | JFrame | JInternalFrame frame( Component component )
  11. */
  12. bsh.help.frame = "usage: frame( Component component )";
  13. import java.awt.*;
  14. import bsh.Capabilities;
  15. frame( Component comp )
  16. {
  17. // Ignore unhandled method invocations from listeners.
  18. invoke( method, args ) { }
  19. windowClosing( event ) {
  20. frame.dispose();
  21. }
  22. // if the desktop is there make an internal frame
  23. if ( bsh.system.desktop != void ) {
  24. this.frame = bsh.system.desktop.makeInternalFrame("frame");
  25. frame.setClosable(true);
  26. frame.getContentPane().add( comp, "Center" );
  27. frame.pack(); // must pack before adding to desktop?
  28. bsh.system.desktop.addInternalFrame( frame );
  29. } else {
  30. // make an external JFrame or Frame
  31. if ( Capabilities.haveSwing() ) {
  32. this.frame = new javax.swing.JFrame();
  33. frame.getContentPane().add( comp, "Center" );
  34. } else {
  35. this.frame = new Frame();
  36. frame.add( comp, "Center" );
  37. }
  38. frame.addWindowListener(this);
  39. frame.pack();
  40. }
  41. frame.show();
  42. return frame;
  43. }