jalview 2.5 release banner
[jalview.git] / src / jalview / gui / Desktop.java
index fa4e483..3ea93ce 100755 (executable)
@@ -1,20 +1,19 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
- * Copyright (C) 2009 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * This file is part of Jalview.
  * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
  */
 package jalview.gui;
 
@@ -104,8 +103,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     desktop.setDesktopManager(new DefaultDesktopManager());
 
     Rectangle dims = getLastKnownDimensions("");
-    if (dims!=null)
-    {      
+    if (dims != null)
+    {
       setBounds(dims);
     }
     else
@@ -116,14 +115,15 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     }
     jconsole = new Console(this);
     // immediately output essential build information
-    System.out.println("Jalview Desktop "+jalview.bin.Cache.getProperty("VERSION")+"\n"
-            +"Build Date: "
-            + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown")+"\n"
-            + "Java version: " + System.getProperty("java.version")
-            + "\n"+System.getProperty("os.arch") + " "
+    System.out.println("Jalview Desktop "
+            + jalview.bin.Cache.getProperty("VERSION") + "\n"
+            + "Build Date: "
+            + jalview.bin.Cache.getDefault("BUILD_DATE", "unknown") + "\n"
+            + "Java version: " + System.getProperty("java.version") + "\n"
+            + System.getProperty("os.arch") + " "
             + System.getProperty("os.name") + " "
             + System.getProperty("os.version"));
-    
+
     showConsole(showjconsole);
 
     this.addWindowListener(new WindowAdapter()
@@ -157,12 +157,15 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
     discoverer = new jalview.ws.Discoverer(); // Only gets started if gui is
     // displayed.
-    // Thread off a new instance of the file chooser - this reduces the time it takes to open it later on.
-    new Thread(new Runnable() {
-      public void run() {
+    // Thread off a new instance of the file chooser - this reduces the time it
+    // takes to open it later on.
+    new Thread(new Runnable()
+    {
+      public void run()
+      {
         Cache.log.debug("Filechooser init thread started.");
-        JalviewFileChooser chooser = new JalviewFileChooser(jalview.bin.Cache
-                .getProperty("LAST_DIRECTORY"),
+        JalviewFileChooser chooser = new JalviewFileChooser(
+                jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
                 jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
                 jalview.io.AppletFormatAdapter.READABLE_FNAMES,
                 jalview.bin.Cache.getProperty("DEFAULT_FILE_FORMAT"));
@@ -173,6 +176,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
   /**
    * recover the last known dimensions for a jalview window
+   * 
    * @param windowName
    *          - empty string is desktop, all other windows have unique prefix
    * @return null or last known dimensions scaled to current geometry (if last
@@ -197,21 +201,22 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         // attempt #1 - try to cope with change in screen geometry - this
         // version doesn't preserve original jv aspect ratio.
         // take ratio of current screen size vs original screen size.
-        double sw = ( (1f*screenSize.width)
-                / (1f*Integer.parseInt(jalview.bin.Cache
-                        .getProperty("SCREENGEOMETRY_WIDTH"))))
-                        ;
-        double sh = ( (1f*screenSize.height)
-                / (1f*Integer.parseInt(jalview.bin.Cache
+        double sw = ((1f * screenSize.width) / (1f * Integer
+                .parseInt(jalview.bin.Cache
+                        .getProperty("SCREENGEOMETRY_WIDTH"))));
+        double sh = ((1f * screenSize.height) / (1f * Integer
+                .parseInt(jalview.bin.Cache
                         .getProperty("SCREENGEOMETRY_HEIGHT"))));
         // rescale the bounds depending upon the current screen geometry.
         ix = (int) (ix * sw);
         iw = (int) (iw * sw);
         iy = (int) (iy * sh);
         ih = (int) (ih * sh);
-        jalview.bin.Cache.log.debug("Got last known dimensions for "+windowName+": x:"+ix + " y:"+iy + " width:"+iw+" height:"+ih);
+        jalview.bin.Cache.log.debug("Got last known dimensions for "
+                + windowName + ": x:" + ix + " y:" + iy + " width:" + iw
+                + " height:" + ih);
       }
-      // return dimensions for new instance 
+      // return dimensions for new instance
       return new Rectangle(ix, iy, iw, ih);
     }
     return null;
@@ -297,7 +302,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   }
 
   /**
-   * Adds and opens the given frame to the desktop 
+   * Adds and opens the given frame to the desktop
    * 
    * @param frame
    *          DOCUMENT ME!
@@ -333,7 +338,8 @@ public class Desktop extends jalview.jbgui.GDesktop implements
           boolean resizable)
   {
 
-    //TODO: allow callers to determine X and Y position of frame (eg. via bounds object).
+    // TODO: allow callers to determine X and Y position of frame (eg. via
+    // bounds object).
     // TODO: consider fixing method to update entries in the window submenu with
     // the current window title
 
@@ -690,11 +696,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
             .setProperty("SCREENGEOMETRY_WIDTH", screen.width + "");
     jalview.bin.Cache.setProperty("SCREENGEOMETRY_HEIGHT", screen.height
             + "");
-    storeLastKnownDimensions("",new Rectangle(getBounds().x,getBounds().y, getWidth(), getHeight()));
+    storeLastKnownDimensions("", new Rectangle(getBounds().x,
+            getBounds().y, getWidth(), getHeight()));
 
     if (jconsole != null)
     {
-      storeLastKnownDimensions("JAVA_CONSOLE_",jconsole.getBounds());
+      storeLastKnownDimensions("JAVA_CONSOLE_", jconsole.getBounds());
       jconsole.stopConsole();
     }
     System.exit(0);
@@ -702,13 +709,14 @@ public class Desktop extends jalview.jbgui.GDesktop implements
 
   private void storeLastKnownDimensions(String string, Rectangle jc)
   {
-    jalview.bin.Cache.log.debug("Storing last known dimensions for "+string+": x:"+jc.x + " y:"+jc.y + " width:"+jc.width+" height:"+jc.height);
-    
-    jalview.bin.Cache.setProperty(string+"SCREEN_X",jc.x + "");
-    jalview.bin.Cache.setProperty(string+"SCREEN_Y", jc.y + "");
-    jalview.bin.Cache.setProperty(string+"SCREEN_WIDTH", jc.width + "");
-    jalview.bin.Cache.setProperty(string+"SCREEN_HEIGHT", jc.height
-            + "");
+    jalview.bin.Cache.log.debug("Storing last known dimensions for "
+            + string + ": x:" + jc.x + " y:" + jc.y + " width:" + jc.width
+            + " height:" + jc.height);
+
+    jalview.bin.Cache.setProperty(string + "SCREEN_X", jc.x + "");
+    jalview.bin.Cache.setProperty(string + "SCREEN_Y", jc.y + "");
+    jalview.bin.Cache.setProperty(string + "SCREEN_WIDTH", jc.width + "");
+    jalview.bin.Cache.setProperty(string + "SCREEN_HEIGHT", jc.height + "");
   }
 
   /**
@@ -1673,11 +1681,12 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         if (percentUsage < 20)
           g.setColor(Color.red);
         FontMetrics fm = g.getFontMetrics();
-        if (fm!=null)
-        { g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
-                + "MB; Max Memory: " + df.format(maxMemory) + "MB; "
-                + df.format(percentUsage) + "%", 10, getHeight()
-                - fm.getHeight());
+        if (fm != null)
+        {
+          g.drawString("Total Free Memory: " + df.format(totalFreeMemory)
+                  + "MB; Max Memory: " + df.format(maxMemory) + "MB; "
+                  + df.format(percentUsage) + "%", 10, getHeight()
+                  - fm.getHeight());
         }
       }
     }