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

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

#
Unknown | 207 lines | 172 code | 35 blank | 0 comment | 0 complexity | 584475dd7da27cf620d79b9eaff48413 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 in a JFrame. A starter workspace is created
  3. * and added to the desktop.
  4. *
  5. * @method void desktop()
  6. *
  7. * @author Pat Niemeyer
  8. * @author Daniel Leuck
  9. */
  10. import javax.swing.*;
  11. import javax.swing.border.*;
  12. import bsh.util.JConsole;
  13. import bsh.util.Util;
  14. import bsh.Interpreter;
  15. import java.awt.Component;
  16. import bsh.Capabilities;
  17. desktop()
  18. {
  19. // need a way to set things to void again
  20. if ( bsh.system.desktop != void ) {
  21. print("There is already a desktop running...");
  22. return;
  23. } else
  24. bsh.system.desktop = this; // race condition (hah!)
  25. bsh.system.icons=object();
  26. bsh.system.icons.bean=
  27. new ImageIcon(getResource("/bsh/util/lib/icon.gif"));
  28. bsh.system.icons.workspace=
  29. new ImageIcon(getResource("/bsh/util/lib/workspace.gif"));
  30. bsh.system.icons.script=
  31. new ImageIcon(getResource("/bsh/util/lib/script.gif"));
  32. bsh.system.icons.eye=
  33. new ImageIcon(getResource("/bsh/util/lib/eye.jpg"));
  34. bsh.system.fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().
  35. getAvailableFontFamilyNames();
  36. JPanel stage=new JPanel(new BorderLayout());
  37. JPanel taskBar=new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1));
  38. taskBar.setBorder(new MatteBorder(1,0,0,0, taskBar.background.darker()));
  39. ButtonGroup taskBarButtonGroup = new ButtonGroup();
  40. // Ignore unhandled method invocations from listeners.
  41. invoke( method, args ) { }
  42. makeInternalFrame( String name )
  43. {
  44. // Closable by default
  45. this.frame = new JInternalFrame( name, true, true, true, true );
  46. frame.frameIcon=bsh.system.icons.bean;
  47. frame.visible=true;
  48. return frame;
  49. }
  50. this.frameMap=new Hashtable();
  51. taskBarButtonListener() {
  52. actionPerformed(ae) {
  53. this.iframe=frameMap.get(ae.source);
  54. if(iframe.icon)
  55. iframe.icon=false;
  56. if(iframe!=null && !iframe.selected)
  57. iframe.selected=true;
  58. }
  59. return this;
  60. }
  61. this.taskBarButtonListener=taskBarButtonListener();
  62. addInternalFrame( frame )
  63. {
  64. iframeListener=new InternalFrameListener() {
  65. internalFrameClosing(ife) {
  66. for(e:new Hashtable(frameMap).entrySet()) {
  67. if(e.value.equals(ife.source)) {
  68. taskBar.remove(e.key);
  69. taskBarButtonGroup.remove(e.key);
  70. frameMap.remove(e.key);
  71. taskBar.validate();
  72. taskBar.repaint();
  73. }
  74. }
  75. }
  76. internalFrameActivated(ife) {
  77. for(e:frameMap.entrySet()) if(e.value.equals(ife.source)) {
  78. if(!e.key.selected) e.key.selected=true;
  79. }
  80. }
  81. internalFrameDeactivated(ife) {}
  82. internalFrameClosed(ife) {}
  83. internalFrameOpened(ife) {}
  84. internalFrameIconified(ife) {}
  85. internalFrameDeiconified(ife) {}
  86. };
  87. bsh.system.desktop.pane.add( frame );
  88. frame.addInternalFrameListener(iframeListener);
  89. JToggleButton button = new JToggleButton(frame.title, frame.frameIcon);
  90. taskBarButtonGroup.add(button);
  91. button.border=new CompoundBorder((Border)thinBorder(),
  92. new EmptyBorder(2,2,2,3));
  93. button.addActionListener(taskBarButtonListener);
  94. taskBar.add(button);
  95. taskBar.validate();
  96. frameMap.put(button,frame);
  97. }
  98. this.windowCount=0;
  99. mousePressed( e ) {
  100. popup.show( pane, e.getX(), e.getY() );
  101. }
  102. shutdown() {
  103. /*
  104. ret = JOptionPane.showInternalConfirmDialog( pane,
  105. "This workspace has not been saved. Do you really want to exit?" );
  106. if ( ret == JOptionPane.YES_OPTION )
  107. exit();
  108. */
  109. frame.dispose();
  110. exit();
  111. }
  112. actionPerformed( e )
  113. {
  114. this.com = e.getActionCommand();
  115. if ( com.equals("New Bsh Workspace") )
  116. makeWorkspace( ""+ super.windowCount++);
  117. if ( com.equals("New Class Browser") )
  118. classBrowser();
  119. else if ( com.equals("Save Workspace") )
  120. JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
  121. else if ( com.equals("Exit") )
  122. shutdown();
  123. }
  124. this.pane=new JDesktopPane();
  125. this.popup=new JPopupMenu("Root Menu");
  126. this.mi=new JMenuItem("New Bsh Workspace");
  127. mi.addActionListener(this);
  128. popup.add( mi );
  129. mi=new JMenuItem("New Class Browser");
  130. mi.addActionListener(this);
  131. popup.add( mi );
  132. mi=new JMenuItem("Save Workspace");
  133. mi.addActionListener(this);
  134. popup.add( mi );
  135. mi=new JMenuItem("Exit");
  136. mi.addActionListener(this);
  137. popup.add( mi );
  138. pane.addMouseListener( this );
  139. this.frame=new JFrame("BeanShell Desktop 1.1");
  140. stage.add(pane);
  141. stage.add(taskBar, BorderLayout.SOUTH);
  142. frame.getContentPane().add(stage);
  143. windowClosing( e ) {
  144. bsh.system.desktop = null;
  145. shutdown();
  146. }
  147. frame.iconImage=bsh.system.icons.bean.image;
  148. frame.addWindowListener( this );
  149. /*
  150. If available, add a listener for classpath mapping
  151. I'm planning to implement a GUI progress indicator here
  152. if ( Capabilities.canGenerateInterfaces() )
  153. {
  154. import bsh.classpath.BshClassPath;
  155. classFeedbackListener = new BshClassPath.MappingFeedback()
  156. {
  157. startClassMapping() { }
  158. classMapping( msg ) { }
  159. errorWhileMapping( msg ) { }
  160. endClassMapping() { }
  161. };
  162. BshClassPath.addMappingFeedback( classFeedbackListener );
  163. }
  164. */
  165. // start one terminal
  166. workSpace=makeWorkspace( ""+windowCount++ );
  167. frame.setSize(800,600);
  168. frame.show();
  169. Util.endSplashScreen();
  170. frame.toFront();
  171. workSpace.frame.selected=true;
  172. }