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

# · Unknown · 140 lines · 118 code · 22 blank · 0 comment · 0 complexity · c243c0b20c205eb7a380338baaa13e5b MD5 · raw file

  1. /**
  2. * Creates a JConsole in a JInternalFrame and adds it to the desktop
  3. *
  4. * @return this (the workspace scripted object for allowing access to the
  5. * frame, interpreter, etc.)
  6. *
  7. * @author Pat Niemeyer
  8. * @author Daniel Leuck (bug fixes)
  9. */
  10. import javax.swing.*;
  11. import bsh.Interpreter;
  12. import bsh.BshClassManager;
  13. import bsh.util.JConsole;
  14. import bsh.util.NameCompletionTable;
  15. makeWorkspace( String name )
  16. {
  17. if ( bsh.system.desktop == void ) {
  18. print("No desktop...");
  19. return;
  20. }
  21. this.console = new JConsole();
  22. this.name="Bsh Workspace: "+name;
  23. this.interpreter = new Interpreter( console );
  24. // provide name completion for console, name source is global namespace
  25. // move this into JConsole?
  26. this.nct = new NameCompletionTable();
  27. nct.add( interpreter.getNameSpace() );
  28. try {
  29. this.bcm = this.caller.namespace.getClassManager();
  30. if ( bcm != null ) {
  31. classNamesSource = bcm.getClassPath();
  32. nct.add( classNamesSource );
  33. }
  34. } catch ( ClassPathException e ) {
  35. error("classpath exception in name compl:"+e);
  36. }
  37. console.setNameCompletion( nct );
  38. // end setup name completion
  39. // for convenience and backwards compatability
  40. interpreter.set( "bsh.desktop", bsh.system.desktop );
  41. this.frame = bsh.system.desktop.makeInternalFrame( name );
  42. frame.frameIcon=bsh.system.icons.workspace;
  43. frame.setDefaultCloseOperation( frame.DO_NOTHING_ON_CLOSE );
  44. internalFrameClosing( e ) {
  45. close();
  46. }
  47. frame.addInternalFrameListener(this);
  48. actionPerformed( e )
  49. {
  50. this.com = e.getActionCommand();
  51. if ( com.equals("Workspace Editor") )
  52. workspaceEditor( interpreter, name );
  53. else if ( com.equals("Capture System in/out/err") )
  54. captureSysIO();
  55. else if ( com.equals("Close") ) {
  56. close();
  57. }
  58. }
  59. internalFrameActivated(ife) {}
  60. internalFrameDeactivated(ife) {}
  61. internalFrameClosed(ife) {}
  62. internalFrameOpened(ife) {}
  63. internalFrameIconified(ife) {}
  64. internalFrameDeiconified(ife) {}
  65. /*
  66. Notes: Careful not to print anything before returning sys io...
  67. console is now gone.
  68. */
  69. close() {
  70. frame.dispose();
  71. if ( haveSysIO )
  72. returnSysIO();
  73. }
  74. this.menubar = new JMenuBar();
  75. this.menu=new JMenu("File");
  76. this.mi=new JMenuItem("Workspace Editor");
  77. mi.addActionListener(this);
  78. menu.add(mi);
  79. mi=new JMenuItem("Capture System in/out/err");
  80. mi.addActionListener(this);
  81. menu.add(mi);
  82. mi=new JMenuItem("Close");
  83. mi.addActionListener(this);
  84. menu.add(mi);
  85. menubar.add(menu);
  86. menu = fontMenu(console);
  87. menubar.add(menu);
  88. frame.setMenuBar(menubar);
  89. frame.getContentPane().add("Center", console);
  90. //frame.pack();
  91. this.thread = new Thread( interpreter );
  92. thread.start();
  93. frame.setBounds(5,5,600,300);
  94. // cascade windows?
  95. //off=bsh.system.desktop.windowCount*10;
  96. //frame.setLocation( off, off );
  97. //frame.validate();
  98. bsh.system.desktop.addInternalFrame( frame );
  99. frame.toFront();
  100. frame.setSelected(true);
  101. this.haveSysIO=false;
  102. this.sysIn = System.in;
  103. this.sysOut = System.out;
  104. this.sysErr = System.err;
  105. captureSysIO() {
  106. super.haveSysIO = true; // old scoping rules
  107. System.setIn( console.getInputStream() );
  108. System.setOut( console.getOut() );
  109. System.setErr( console.getErr() );
  110. }
  111. returnSysIO() {
  112. super.haveSysIO = false; // old scoping rules
  113. System.setIn( sysIn );
  114. System.setOut( sysOut );
  115. System.setErr( sysErr );
  116. }
  117. return this;
  118. }