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

/jEdit/tags/jedit-4-1-pre5/bsh/commands/desktop.bsh

#
Unknown | 147 lines | 125 code | 22 blank | 0 comment | 0 complexity | f0e19e9e0ec339557a7d96ee511044e1 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. Start the BeanShell GUI desktop.
  3. @method void desktop()
  4. */
  5. import javax.swing.*;
  6. import bsh.util.JConsole;
  7. import bsh.util.Util;
  8. import bsh.Interpreter;
  9. import java.awt.Component;
  10. import bsh.Capabilities;
  11. desktop() {
  12. // need a way to set things to void again
  13. if ( bsh.system.desktop != void ) {
  14. print("There is already a desktop running...");
  15. return;
  16. } else
  17. bsh.system.desktop = this; // race condition (hah!)
  18. // Ignore unhandled method invocations from listeners.
  19. invoke( method, args ) { }
  20. makeFontMenu( Component component ) {
  21. menu = new JMenu("Font");
  22. mi = new JMenuItem("Normal");
  23. mi.addActionListener(this);
  24. menu.add(mi);
  25. mi = new JMenuItem("Big");
  26. mi.addActionListener(this);
  27. menu.add(mi);
  28. mi = new JMenuItem("Bigger");
  29. mi.addActionListener(this);
  30. menu.add(mi);
  31. actionPerformed(e) {
  32. com = e.getActionCommand();
  33. if ( com.equals("Normal") )
  34. setFont( component, 12 );
  35. else if ( com.equals("Big") )
  36. setFont( component, 16 );
  37. else if ( com.equals("Bigger") )
  38. setFont( component, 20 );
  39. }
  40. return menu;
  41. }
  42. makeInternalFrame( String name ) {
  43. // Closable by default
  44. frame = new JInternalFrame( name, true, true, true, true);
  45. frame.setVisible( true );
  46. return frame;
  47. }
  48. addInternalFrame( frame ) {
  49. bsh.system.desktop.pane.add( frame );
  50. /*
  51. frame.pack();
  52. frame.show();
  53. frame.toFront();
  54. */
  55. }
  56. windowCount=0;
  57. mousePressed( e ) {
  58. popup.show( pane, e.getX(), e.getY() );
  59. }
  60. shutdown() {
  61. /*
  62. ret = JOptionPane.showInternalConfirmDialog( pane,
  63. "This workspace has not been saved. Do you really want to exit?" );
  64. if ( ret == JOptionPane.YES_OPTION )
  65. exit();
  66. */
  67. frame.dispose();
  68. exit();
  69. }
  70. actionPerformed( e ) {
  71. com = e.getActionCommand();
  72. if ( com.equals("New Bsh Workspace") )
  73. makeWorkspace( ""+ super.windowCount++);
  74. if ( com.equals("New Class Browser") )
  75. classBrowser();
  76. else if ( com.equals("Save Workspace") )
  77. JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
  78. else if ( com.equals("Exit") )
  79. shutdown();
  80. }
  81. pane=new JDesktopPane();
  82. popup=new JPopupMenu("Root Menu");
  83. mi=new JMenuItem("New Bsh Workspace");
  84. mi.addActionListener(this);
  85. popup.add( mi );
  86. mi=new JMenuItem("New Class Browser");
  87. mi.addActionListener(this);
  88. popup.add( mi );
  89. mi=new JMenuItem("Save Workspace");
  90. mi.addActionListener(this);
  91. popup.add( mi );
  92. mi=new JMenuItem("Exit");
  93. mi.addActionListener(this);
  94. popup.add( mi );
  95. pane.addMouseListener( this );
  96. frame=new JFrame("BeanShell Desktop 1.0");
  97. frame.getContentPane().add("Center", pane);
  98. windowClosing( e ) {
  99. bsh.system.desktop = null;
  100. shutdown();
  101. }
  102. frame.addWindowListener( this );
  103. /*
  104. If available, add a listener for classpath mapping
  105. I'm planning to implement a GUI progress indicator here
  106. if ( Capabilities.canGenerateInterfaces() )
  107. {
  108. import bsh.classpath.BshClassPath;
  109. classFeedbackListener = new BshClassPath.MappingFeedback()
  110. {
  111. startClassMapping() { }
  112. classMapping( msg ) { }
  113. errorWhileMapping( msg ) { }
  114. endClassMapping() { }
  115. };
  116. BshClassPath.addMappingFeedback( classFeedbackListener );
  117. }
  118. */
  119. // start one terminal
  120. makeWorkspace( ""+windowCount++ );
  121. frame.setSize(800,600);
  122. frame.show();
  123. frame.toFront();
  124. Util.endSplashScreen();
  125. }