home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 25 / FreelogHS25.iso / Dessin / ArtOfIllusion2.2.1 / ArtOfIllusion.jar / bsh / commands / desktop.bsh < prev    next >
Text File  |  2005-05-23  |  6KB  |  225 lines

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