PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Unknown | 134 lines | 113 code | 21 blank | 0 comment | 0 complexity | 924dc4868f201c7049a3e01d779e279d 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. * 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. /*
  44. Notes: Careful not to print anything before returning sys io...
  45. console is now gone.
  46. */
  47. internalFrameClosing( e ) {
  48. if ( haveSysIO )
  49. returnSysIO();
  50. }
  51. internalFrameActivated(ife) {}
  52. internalFrameDeactivated(ife) {}
  53. internalFrameClosed(ife) {}
  54. internalFrameOpened(ife) {}
  55. internalFrameIconified(ife) {}
  56. internalFrameDeiconified(ife) {}
  57. frame.addInternalFrameListener(this);
  58. actionPerformed( e )
  59. {
  60. this.com = e.getActionCommand();
  61. if ( com.equals("Workspace Editor") )
  62. workspaceEditor( interpreter, name );
  63. else if ( com.equals("Capture System in/out/err") )
  64. captureSysIO();
  65. else if ( com.equals("Close") ) {
  66. frame.setClosed(true);
  67. }
  68. }
  69. this.menubar = new JMenuBar();
  70. this.menu=new JMenu("File");
  71. this.mi=new JMenuItem("Workspace Editor");
  72. mi.addActionListener(this);
  73. menu.add(mi);
  74. mi=new JMenuItem("Capture System in/out/err");
  75. mi.addActionListener(this);
  76. menu.add(mi);
  77. mi=new JMenuItem("Close");
  78. mi.addActionListener(this);
  79. menu.add(mi);
  80. menubar.add(menu);
  81. menu = fontMenu(console);
  82. menubar.add(menu);
  83. frame.setMenuBar(menubar);
  84. frame.getContentPane().add("Center", console);
  85. //frame.pack();
  86. this.thread = new Thread( interpreter );
  87. thread.start();
  88. frame.setBounds(5,5,600,300);
  89. // cascade windows?
  90. //off=bsh.system.desktop.windowCount*10;
  91. //frame.setLocation( off, off );
  92. //frame.validate();
  93. bsh.system.desktop.addInternalFrame( frame );
  94. frame.toFront();
  95. frame.setSelected(true);
  96. this.haveSysIO=false;
  97. this.sysIn = System.in;
  98. this.sysOut = System.out;
  99. this.sysErr = System.err;
  100. captureSysIO() {
  101. super.haveSysIO = true; // old scoping rules
  102. System.setIn( console.getInputStream() );
  103. System.setOut( console.getOut() );
  104. System.setErr( console.getErr() );
  105. }
  106. returnSysIO() {
  107. super.haveSysIO = false; // old scoping rules
  108. System.setIn( sysIn );
  109. System.setOut( sysOut );
  110. System.setErr( sysErr );
  111. }
  112. return this;
  113. }