memory monitor, garbage collection and changed menu item for groovy console opening
authorjprocter <Jim Procter>
Fri, 11 Jan 2008 13:51:37 +0000 (13:51 +0000)
committerjprocter <Jim Procter>
Fri, 11 Jan 2008 13:51:37 +0000 (13:51 +0000)
src/jalview/bin/Cache.java
src/jalview/gui/Desktop.java
src/jalview/jbgui/GDesktop.java

index acf1499..ef37ebd 100755 (executable)
@@ -84,6 +84,7 @@ import org.apache.log4j.*;
  * </li><li>DAS_REGISTRY_URL the registry to query
  * </li><li>DEFAULT_BROWSER for unix
  * </li><li>DAS_ACTIVE_SOURCE list of active sources
+ * </li><li>SHOW_MEMUSAGE boolean show memory usage and warning indicator on desktop (false) 
  * </li><li> 
  * </li>
  * 
index be05b48..cdb18e7 100755 (executable)
@@ -45,8 +45,8 @@ public class Desktop
 
   //Need to decide if the Memory Usage is to be included in
   //Next release or not.
- // public static MyDesktopPane desktop;
-   public static JDesktopPane desktop;
+  public static MyDesktopPane desktop;
+  // public static JDesktopPane desktop;
 
 
   static int openFrameCount = 0;
@@ -71,8 +71,9 @@ public class Desktop
 
     setTitle("Jalview " + jalview.bin.Cache.getProperty("VERSION"));
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-
-    desktop = new JDesktopPane();
+    boolean selmemusage = jalview.bin.Cache.getDefault("SHOW_MEMUSAGE",false);
+    desktop = new MyDesktopPane(selmemusage);
+    showMemusage.setSelected(selmemusage);
     desktop.setBackground(Color.white);
     getContentPane().setLayout(new BorderLayout());
     getContentPane().add(desktop, BorderLayout.CENTER);
@@ -663,6 +664,25 @@ public class Desktop
     reorderAssociatedWindows(false, true);
   }
 
+  /* (non-Javadoc)
+   * @see jalview.jbgui.GDesktop#garbageCollect_actionPerformed(java.awt.event.ActionEvent)
+   */
+  protected void garbageCollect_actionPerformed(ActionEvent e)
+  {
+    // We simply collect the garbage
+    jalview.bin.Cache.log.debug("Collecting garbage...");
+    System.gc();
+    jalview.bin.Cache.log.debug("Finished garbage collection.");
+  }
+
+  /* (non-Javadoc)
+   * @see jalview.jbgui.GDesktop#showMemusage_actionPerformed(java.awt.event.ActionEvent)
+   */
+  protected void showMemusage_actionPerformed(ActionEvent e)
+  {
+    desktop.showMemoryUsage(showMemusage.isSelected());
+  }
+
   void reorderAssociatedWindows(boolean minimize, boolean close)
   {
     JInternalFrame[] frames = desktop.getAllFrames();
@@ -739,7 +759,6 @@ public class Desktop
       }
     }
   }
-
   /**
    * DOCUMENT ME!
    *
@@ -1200,10 +1219,15 @@ public class Desktop
     UserQuestionnaireCheck jvq = new UserQuestionnaireCheck(url);
     javax.swing.SwingUtilities.invokeLater(jvq);
   }
-
-  /*DISABLED
-   class  MyDesktopPane extends JDesktopPane implements Runnable
+  /**
+   * Proxy class for JDesktopPane which optionally 
+   * displays the current memory usage and highlights 
+   * the desktop area with a red bar if free memory runs low.
+   * @author AMW
+   */
+  class  MyDesktopPane extends JDesktopPane implements Runnable
   {
+    
     boolean showMemoryUsage = false;
     Runtime runtime;
     java.text.NumberFormat df;
@@ -1271,13 +1295,16 @@ public class Desktop
                      getHeight() - g.getFontMetrics().getHeight());
       }
     }
-  }*/
+
+    
+    
+  }
   protected JMenuItem groovyShell;
   public void doGroovyCheck() {
     if (jalview.bin.Cache.groovyJarsPresent())
     {
       groovyShell = new JMenuItem();
-      groovyShell.setText("Groovy Shell...");
+      groovyShell.setText("Groovy Console...");
       groovyShell.addActionListener(new ActionListener()
       {
           public void actionPerformed(ActionEvent e) {
index 2a7cab8..aa86809 100755 (executable)
@@ -58,6 +58,8 @@ public class GDesktop
   JMenuItem closeAll = new JMenuItem();
   JMenuItem raiseRelated = new JMenuItem();
   JMenuItem minimizeAssociated = new JMenuItem();
+  protected JCheckBoxMenuItem showMemusage = new JCheckBoxMenuItem();
+  JMenuItem garbageCollect = new JMenuItem();
 
   /**
    * Creates a new GDesktop object.
@@ -251,6 +253,22 @@ public class GDesktop
         minimizeAssociated_actionPerformed(e);
       }
     });
+    garbageCollect.setText("Collect Garbage");
+    garbageCollect.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        garbageCollect_actionPerformed(e);
+      }
+    });
+    showMemusage.setText("Show Memory Usage");
+    showMemusage.addActionListener(new ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        showMemusage_actionPerformed(e);
+      }
+    });
     desktopMenubar.add(FileMenu);
     desktopMenubar.add(toolsMenu);
     VamsasMenu.setVisible(false);
@@ -273,6 +291,8 @@ public class GDesktop
     VamsasMenu.add(vamsasSave);
     VamsasMenu.add(vamsasStop);
     toolsMenu.add(preferences);
+    toolsMenu.add(showMemusage);
+    toolsMenu.add(garbageCollect);
     inputMenu.add(inputLocalFileMenuItem);
     inputMenu.add(inputURLMenuItem);
     inputMenu.add(inputTextboxMenuItem);
@@ -283,6 +303,18 @@ public class GDesktop
     //    inputMenu.add(vamsasLoad);
   }
 
+  protected void showMemusage_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
+  protected void garbageCollect_actionPerformed(ActionEvent e)
+  {
+    // TODO Auto-generated method stub
+    
+  }
+
   protected void vamsasStMenu_actionPerformed()
   {
   }