PageRenderTime 29ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/bsh/commands/makeWorkspace.bsh

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