PageRenderTime 38ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre5/bsh/commands/makeWorkspace.bsh

#
Unknown | 126 lines | 100 code | 26 blank | 0 comment | 0 complexity | 7c08ab9f5e9569684f60adc8c9b4f3bd 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. import javax.swing.*;
  2. import bsh.Interpreter;
  3. import bsh.BshClassManager;
  4. import bsh.util.JConsole;
  5. import bsh.util.NameCompletionTable;
  6. makeWorkspace( String name ) {
  7. if ( bsh.system.desktop == void ) {
  8. print("No desktop...");
  9. return;
  10. }
  11. console = new JConsole();
  12. name="Bsh Workspace: "+name;
  13. interpreter = new Interpreter( console );
  14. // provide name completion for console, name source is global namespace
  15. // move this into JConsole?
  16. nct = new NameCompletionTable();
  17. nct.add( interpreter.getNameSpace() );
  18. try {
  19. bcm = BshClassManager.getClassManager();
  20. if ( bcm != null ) {
  21. classNamesSource = bcm.getClassPath();
  22. nct.add( classNamesSource );
  23. }
  24. } catch ( ClassPathException e ) {
  25. error("classpath exception in name compl:"+e);
  26. }
  27. console.setNameCompletion( nct );
  28. // end setup name completion
  29. // for convenience and backwards compatability
  30. interpreter.set( "bsh.desktop", bsh.system.desktop );
  31. frame = bsh.system.desktop.makeInternalFrame( name );
  32. frame.setDefaultCloseOperation( frame.DO_NOTHING_ON_CLOSE );
  33. internalFrameClosing( e ) {
  34. close();
  35. }
  36. frame.addInternalFrameListener(this);
  37. actionPerformed( e ) {
  38. com = e.getActionCommand();
  39. if ( com.equals("Workspace Editor") )
  40. workspaceEditor( interpreter, name );
  41. else if ( com.equals("Capture System in/out/err") )
  42. captureSysIO();
  43. else if ( com.equals("Close") ) {
  44. close();
  45. }
  46. }
  47. /*
  48. Notes: Careful not to print anything before returning sys io...
  49. console is now gone.
  50. */
  51. close() {
  52. frame.dispose();
  53. if ( haveSysIO )
  54. returnSysIO();
  55. }
  56. menubar = new JMenuBar();
  57. menu=new JMenu("File");
  58. mi=new JMenuItem("Workspace Editor");
  59. mi.addActionListener(this);
  60. menu.add(mi);
  61. mi=new JMenuItem("Capture System in/out/err");
  62. mi.addActionListener(this);
  63. menu.add(mi);
  64. mi=new JMenuItem("Close");
  65. mi.addActionListener(this);
  66. menu.add(mi);
  67. menubar.add(menu);
  68. menu = bsh.system.desktop.makeFontMenu( console );
  69. menubar.add(menu);
  70. frame.setMenuBar(menubar);
  71. frame.getContentPane().add("Center", console);
  72. //frame.pack();
  73. thread = new Thread( interpreter );
  74. thread.start();
  75. frame.setBounds(5,5,600,300);
  76. // cascade windows?
  77. //off=bsh.system.desktop.windowCount*10;
  78. //frame.setLocation( off, off );
  79. //frame.validate();
  80. bsh.system.desktop.addInternalFrame( frame );
  81. frame.toFront();
  82. frame.setSelected(true);
  83. haveSysIO=false;
  84. sysIn = System.in;
  85. sysOut = System.out;
  86. sysErr = System.err;
  87. captureSysIO() {
  88. super.haveSysIO = true;
  89. System.setIn( console.getInputStream() );
  90. System.setOut( console.getOut() );
  91. System.setErr( console.getErr() );
  92. }
  93. returnSysIO() {
  94. super.haveSysIO = false;
  95. System.setIn( sysIn );
  96. System.setOut( sysOut );
  97. System.setErr( sysErr );
  98. }
  99. return interpreter;
  100. }