/jEdit/tags/jedit-4-0-pre6/bsh/commands/desktop.bsh

# · Unknown · 142 lines · 121 code · 21 blank · 0 comment · 0 complexity · 525ee96940f31d972cc246a923b69c3a MD5 · raw file

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