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