PageRenderTime 42ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
Unknown | 224 lines | 185 code | 39 blank | 0 comment | 0 complexity | 45598ea24c32d4844058d4a52b2887f3 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 org.gjt.sp.jedit.bsh.util.JConsole;
  13. import org.gjt.sp.jedit.bsh.util.Util;
  14. import org.gjt.sp.jedit.bsh.Interpreter;
  15. import java.awt.Component;
  16. import org.gjt.sp.jedit.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. // Disallowed by applet security
  35. try {
  36. bsh.system.fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().
  37. getAvailableFontFamilyNames();
  38. } catch ( SecurityException se ) { }
  39. JPanel stage=new JPanel(new BorderLayout());
  40. JPanel taskBar=new JPanel(new FlowLayout(FlowLayout.LEFT, 1, 1));
  41. // For some insane reason, access to the JPanel background color object
  42. // is protected on the Mac
  43. borderColor = taskBar.background;
  44. try {
  45. borderColor = taskBar.background.darker();
  46. } catch ( SecurityException e ) { }
  47. taskBar.setBorder( new MatteBorder(1,0,0,0, borderColor) );
  48. ButtonGroup taskBarButtonGroup = new ButtonGroup();
  49. // Ignore unhandled method invocations from listeners.
  50. invoke( method, args ) { }
  51. makeInternalFrame( String name )
  52. {
  53. // Closable by default
  54. this.frame = new JInternalFrame( name, true, true, true, true );
  55. frame.frameIcon=bsh.system.icons.bean;
  56. frame.visible=true;
  57. return frame;
  58. }
  59. this.frameMap=new Hashtable();
  60. taskBarButtonListener() {
  61. actionPerformed(ae) {
  62. this.iframe=frameMap.get(ae.source);
  63. if(iframe.icon)
  64. iframe.icon=false;
  65. if(iframe!=null && !iframe.selected)
  66. iframe.selected=true;
  67. }
  68. return this;
  69. }
  70. this.taskBarButtonListener=taskBarButtonListener();
  71. addInternalFrame( frame )
  72. {
  73. iframeListener=new InternalFrameListener() {
  74. internalFrameClosing(ife) {
  75. for(e:new Hashtable(frameMap).entrySet()) {
  76. if(e.value.equals(ife.source)) {
  77. taskBar.remove(e.key);
  78. taskBarButtonGroup.remove(e.key);
  79. frameMap.remove(e.key);
  80. taskBar.validate();
  81. taskBar.repaint();
  82. }
  83. }
  84. }
  85. internalFrameActivated(ife) {
  86. for(e:frameMap.entrySet()) if(e.value.equals(ife.source)) {
  87. if(!e.key.selected) e.key.selected=true;
  88. }
  89. }
  90. internalFrameDeactivated(ife) {}
  91. internalFrameClosed(ife) {}
  92. internalFrameOpened(ife) {}
  93. internalFrameIconified(ife) {}
  94. internalFrameDeiconified(ife) {}
  95. };
  96. bsh.system.desktop.pane.add( frame );
  97. frame.addInternalFrameListener(iframeListener);
  98. JToggleButton button = new JToggleButton(frame.title, frame.frameIcon);
  99. taskBarButtonGroup.add(button);
  100. // For some insane rason access to some of the color objects is
  101. // protected on the Mac
  102. try {
  103. button.border=
  104. new CompoundBorder((Border)thinBorder(), new EmptyBorder(2,2,2,3));
  105. } catch ( SecurityException e ) { }
  106. button.addActionListener(taskBarButtonListener);
  107. taskBar.add(button);
  108. taskBar.validate();
  109. frameMap.put(button,frame);
  110. }
  111. this.windowCount=0;
  112. mousePressed( e ) {
  113. popup.show( pane, e.getX(), e.getY() );
  114. }
  115. shutdown() {
  116. /*
  117. ret = JOptionPane.showInternalConfirmDialog( pane,
  118. "This workspace has not been saved. Do you really want to exit?" );
  119. if ( ret == JOptionPane.YES_OPTION )
  120. exit();
  121. */
  122. frame.dispose();
  123. exit();
  124. }
  125. actionPerformed( e )
  126. {
  127. this.com = e.getActionCommand();
  128. if ( com.equals("New Bsh Workspace") )
  129. makeWorkspace( ""+ super.windowCount++);
  130. if ( com.equals("New Class Browser") )
  131. classBrowser();
  132. else if ( com.equals("Save Workspace") )
  133. JOptionPane.showInternalMessageDialog( pane, "Unimplemented" );
  134. else if ( com.equals("Exit") )
  135. shutdown();
  136. }
  137. this.pane=new JDesktopPane();
  138. this.popup=new JPopupMenu("Root Menu");
  139. this.mi=new JMenuItem("New Bsh Workspace");
  140. mi.addActionListener(this);
  141. popup.add( mi );
  142. mi=new JMenuItem("New Class Browser");
  143. mi.addActionListener(this);
  144. popup.add( mi );
  145. mi=new JMenuItem("Save Workspace");
  146. mi.addActionListener(this);
  147. popup.add( mi );
  148. mi=new JMenuItem("Exit");
  149. mi.addActionListener(this);
  150. popup.add( mi );
  151. pane.addMouseListener( this );
  152. this.frame=new JFrame("BeanShell Desktop 1.1");
  153. stage.add(pane);
  154. stage.add(taskBar, BorderLayout.SOUTH);
  155. frame.getContentPane().add(stage);
  156. windowClosing( e ) {
  157. bsh.system.desktop = null;
  158. shutdown();
  159. }
  160. frame.iconImage=bsh.system.icons.bean.image;
  161. frame.addWindowListener( this );
  162. /*
  163. If available, add a listener for classpath mapping
  164. I'm planning to implement a GUI progress indicator here
  165. if ( Capabilities.canGenerateInterfaces() )
  166. {
  167. import org.gjt.sp.jedit.bsh.classpath.BshClassPath;
  168. classFeedbackListener = new BshClassPath.MappingFeedback()
  169. {
  170. startClassMapping() { }
  171. classMapping( msg ) { }
  172. errorWhileMapping( msg ) { }
  173. endClassMapping() { }
  174. };
  175. BshClassPath.addMappingFeedback( classFeedbackListener );
  176. }
  177. */
  178. // start one terminal
  179. workSpace=makeWorkspace( ""+windowCount++ );
  180. frame.setSize(800,600);
  181. frame.show();
  182. Util.endSplashScreen();
  183. frame.toFront();
  184. workSpace.frame.selected=true;
  185. }