merge from 2_4_Release branch
[jalview.git] / src / jalview / appletgui / EmbmenuFrame.java
index 23f6aa2..df59ef4 100644 (file)
@@ -1,3 +1,21 @@
+/*\r
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)\r
+ * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
+ * \r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this program; if not, write to the Free Software\r
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
+ */\r
 package jalview.appletgui;\r
 \r
 import java.awt.BorderLayout;\r
@@ -19,18 +37,19 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;\r
 import java.util.Enumeration;\r
 import java.util.Hashtable;\r
+\r
 /**\r
- * This class implements a pattern form embedding toolbars as a panel with popups\r
- * for situations where the system menu bar is either invisible or inappropriate.\r
- * It was derived from the code for embedding the jalview applet alignFrame as\r
- * a component on the web-page, which requires the local alignFrame menu to be\r
- * attached to that panel rather than placed on the parent (which isn't allowed\r
- * anyhow).\r
- * TODO: try to modify the embeddedMenu display so it looks like a real toolbar menu\r
- * TODO: modify click/mouse handler for embeddedMenu so it behaves more like a real pulldown menu toolbar\r
+ * This class implements a pattern form embedding toolbars as a panel with\r
+ * popups for situations where the system menu bar is either invisible or\r
+ * inappropriate. It was derived from the code for embedding the jalview applet\r
+ * alignFrame as a component on the web-page, which requires the local\r
+ * alignFrame menu to be attached to that panel rather than placed on the parent\r
+ * (which isn't allowed anyhow). TODO: try to modify the embeddedMenu display so\r
+ * it looks like a real toolbar menu TODO: modify click/mouse handler for\r
+ * embeddedMenu so it behaves more like a real pulldown menu toolbar\r
  * \r
  * @author Jim Procter and Andrew Waterhouse\r
- *\r
+ * \r
  */\r
 public class EmbmenuFrame extends Frame implements MouseListener\r
 {\r
@@ -38,9 +57,10 @@ public class EmbmenuFrame extends Frame implements MouseListener
    * map from labels to popup menus for the embedded menubar\r
    */\r
   protected Hashtable embeddedPopup;\r
+\r
   /**\r
-   * the embedded menu is built on this and should be \r
-   * added to the frame at the appropriate position.\r
+   * the embedded menu is built on this and should be added to the frame at the\r
+   * appropriate position.\r
    * \r
    */\r
   protected Panel embeddedMenu;\r
@@ -49,20 +69,25 @@ public class EmbmenuFrame extends Frame implements MouseListener
   {\r
     super();\r
   }\r
+\r
   public EmbmenuFrame(String title) throws HeadlessException\r
   {\r
     super(title);\r
   }\r
+\r
   /**\r
-   * Check if the applet is running on a platform that requires the Frame menuBar to be embedded,\r
-   * and if so, embeds it.\r
-   * @param tobeAdjusted the panel that is to be reduced to make space for the embedded menu bar\r
+   * Check if the applet is running on a platform that requires the Frame\r
+   * menuBar to be embedded, and if so, embeds it.\r
+   * \r
+   * @param tobeAdjusted\r
+   *                the panel that is to be reduced to make space for the\r
+   *                embedded menu bar\r
    * @return true if menuBar was embedded and tobeAdjusted's height modified\r
    */\r
   protected boolean embedMenuIfNeeded(Panel tobeAdjusted)\r
   {\r
     MenuBar topMenuBar = getMenuBar();\r
-    if (topMenuBar==null)\r
+    if (topMenuBar == null)\r
     {\r
       return false;\r
     }\r
@@ -70,43 +95,53 @@ public class EmbmenuFrame extends Frame implements MouseListener
     if (new jalview.util.Platform().isAMac())\r
     {\r
       // Build the embedded menu panel\r
-      embeddedMenu = makeEmbeddedPopupMenu(topMenuBar, "Arial", Font.PLAIN, 10, true); // try to pickup system font.\r
+      embeddedMenu = makeEmbeddedPopupMenu(topMenuBar, "Arial", Font.PLAIN,\r
+              10, true); // try to pickup system font.\r
       setMenuBar(null);\r
       // add the components to the TreePanel area.\r
       add(embeddedMenu, BorderLayout.NORTH);\r
-      tobeAdjusted.setSize(getSize().width,\r
-              getSize().height\r
-              - embeddedMenu.HEIGHT);        \r
+      tobeAdjusted.setSize(getSize().width, getSize().height\r
+              - embeddedMenu.HEIGHT);\r
       return true;\r
     }\r
     return false;\r
   }\r
+\r
   /**\r
-   * move all menus on menuBar onto embeddedMenu.\r
-   * embeddedPopup is used to store the popups for each menu removed from the menuBar and added\r
-   * to the panel.\r
-   * NOTE: it is up to the caller to remove menuBar from the Frame if it is already attached.\r
+   * move all menus on menuBar onto embeddedMenu. embeddedPopup is used to store\r
+   * the popups for each menu removed from the menuBar and added to the panel.\r
+   * NOTE: it is up to the caller to remove menuBar from the Frame if it is\r
+   * already attached.\r
+   * \r
    * @param menuBar\r
    * @param fn\r
    * @param fstyle\r
    * @param fsz\r
-   * @param overrideFonts true if we take the menuBar fonts in preference to the supplied defaults\r
+   * @param overrideFonts\r
+   *                true if we take the menuBar fonts in preference to the\r
+   *                supplied defaults\r
    * @return the embedded menu instance to be added to the frame.\r
    */\r
   protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,\r
           int fstyle, int fsz, boolean overrideFonts)\r
   {\r
-    return makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts, false);\r
+    return makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts,\r
+            false);\r
   }\r
+\r
   /**\r
-   * Create or add elements to the embedded menu from menuBar. This removes all menu from\r
-   * menuBar and it is up to the caller to remove the now useless menuBar from the Frame if it is already attached. \r
+   * Create or add elements to the embedded menu from menuBar. This removes all\r
+   * menu from menuBar and it is up to the caller to remove the now useless\r
+   * menuBar from the Frame if it is already attached.\r
+   * \r
    * @param menuBar\r
    * @param fn\r
    * @param fstyle\r
    * @param fsz\r
-   * @param overrideFonts \r
-   * @param append true means existing menu will be emptied before adding new elements\r
+   * @param overrideFonts\r
+   * @param append\r
+   *                true means existing menu will be emptied before adding new\r
+   *                elements\r
    * @return\r
    */\r
   protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,\r
@@ -117,59 +152,71 @@ public class EmbmenuFrame extends Frame implements MouseListener
       if (embeddedPopup != null)\r
       {\r
         embeddedPopup.clear(); // TODO: check if j1.1\r
-      } \r
-      if (embeddedMenu!=null)\r
+      }\r
+      if (embeddedMenu != null)\r
       {\r
-        embeddedMenu.removeAll(); \r
+        embeddedMenu.removeAll();\r
       }\r
     }\r
-    if (embeddedPopup==null)\r
+    if (embeddedPopup == null)\r
     {\r
       embeddedPopup = new Hashtable();\r
     }\r
-    \r
-    embeddedMenu = makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts, embeddedPopup, new Panel(), this);\r
+\r
+    embeddedMenu = makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz,\r
+            overrideFonts, embeddedPopup, new Panel(), this);\r
     return embeddedMenu;\r
   }\r
+\r
   /**\r
-   * Generic method to move elements from menubar onto embeddedMenu using the existing or the supplied font, \r
-   * and adds binding from panel to attached menus in embeddedPopup\r
-   * This removes all menu from\r
-   * menuBar and it is up to the caller to remove the now useless menuBar from the Frame if it is already attached.\r
-   * @param menuBar must be non-null\r
+   * Generic method to move elements from menubar onto embeddedMenu using the\r
+   * existing or the supplied font, and adds binding from panel to attached\r
+   * menus in embeddedPopup This removes all menu from menuBar and it is up to\r
+   * the caller to remove the now useless menuBar from the Frame if it is\r
+   * already attached.\r
+   * \r
+   * @param menuBar\r
+   *                must be non-null\r
    * @param fn\r
    * @param fstyle\r
    * @param fsz\r
    * @param overrideFonts\r
-   * @param embeddedPopup must be non-null\r
-   * @param embeddedMenu if null, a new panel will be created and returned\r
-   * @param clickHandler - usually the instance of EmbmenuFrame that holds references to embeddedPopup and embeddedMenu\r
+   * @param embeddedPopup\r
+   *                must be non-null\r
+   * @param embeddedMenu\r
+   *                if null, a new panel will be created and returned\r
+   * @param clickHandler -\r
+   *                usually the instance of EmbmenuFrame that holds references\r
+   *                to embeddedPopup and embeddedMenu\r
    * @return the panel instance for convenience.\r
    */\r
   protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,\r
-          int fstyle, int fsz, boolean overrideFonts, Hashtable embeddedPopup, Panel embeddedMenu, MouseListener clickHandler)\r
+          int fstyle, int fsz, boolean overrideFonts,\r
+          Hashtable embeddedPopup, Panel embeddedMenu,\r
+          MouseListener clickHandler)\r
   {\r
-    if (embeddedPopup==null)\r
+    if (embeddedPopup == null)\r
     {\r
-      throw new Error("Implementation error - embeddedPopup must be non-null");\r
+      throw new Error(\r
+              "Implementation error - embeddedPopup must be non-null");\r
     }\r
     if (overrideFonts)\r
     {\r
       Font mbf = menuBar.getFont();\r
-      if (mbf!=null)\r
+      if (mbf != null)\r
       {\r
         fn = mbf.getName();\r
         fstyle = mbf.getStyle();\r
         fsz = mbf.getSize();\r
       }\r
     }\r
-    if (embeddedMenu==null)\r
+    if (embeddedMenu == null)\r
       embeddedMenu = new Panel();\r
     FlowLayout flowLayout1 = new FlowLayout();\r
     embeddedMenu.setBackground(Color.lightGray);\r
     embeddedMenu.setLayout(flowLayout1);\r
     // loop thru\r
-    for (int mbi = 0,nMbi=menuBar.getMenuCount(); mbi<nMbi; mbi++)\r
+    for (int mbi = 0, nMbi = menuBar.getMenuCount(); mbi < nMbi; mbi++)\r
     {\r
       Menu mi = menuBar.getMenu(mbi);\r
       Label elab = new Label(mi.getLabel());\r
@@ -198,18 +245,19 @@ public class EmbmenuFrame extends Frame implements MouseListener
     PopupMenu popup = null;\r
     Label source = (Label) evt.getSource();\r
     popup = getPopupMenu(source);\r
-    if (popup!=null)\r
+    if (popup != null)\r
     {\r
       embeddedMenu.add(popup);\r
-      popup.show(embeddedMenu,\r
-               source.getBounds().x,\r
-               source.getBounds().y + source.getBounds().getSize().height);\r
+      popup.show(embeddedMenu, source.getBounds().x, source.getBounds().y\r
+              + source.getBounds().getSize().height);\r
     }\r
   }\r
 \r
   /**\r
    * get the menu for source from the hash.\r
-   * @param source what was clicked on.\r
+   * \r
+   * @param source\r
+   *                what was clicked on.\r
    */\r
   PopupMenu getPopupMenu(Label source)\r
   {\r
@@ -217,24 +265,28 @@ public class EmbmenuFrame extends Frame implements MouseListener
   }\r
 \r
   public void mouseClicked(MouseEvent evt)\r
-  {}\r
+  {\r
+  }\r
 \r
   public void mouseReleased(MouseEvent evt)\r
-  {}\r
+  {\r
+  }\r
 \r
   public void mouseEntered(MouseEvent evt)\r
-  {}\r
+  {\r
+  }\r
 \r
   public void mouseExited(MouseEvent evt)\r
-  {}\r
+  {\r
+  }\r
 \r
   /**\r
-   * called to clear the GUI resources taken up for embedding\r
-   * and remove any self references so we can be garbage collected.\r
+   * called to clear the GUI resources taken up for embedding and remove any\r
+   * self references so we can be garbage collected.\r
    */\r
   public void destroyMenus()\r
   {\r
-    if (embeddedPopup!=null)\r
+    if (embeddedPopup != null)\r
     {\r
       Enumeration e = embeddedPopup.keys();\r
       while (e.hasMoreElements())\r
@@ -244,18 +296,20 @@ public class EmbmenuFrame extends Frame implements MouseListener
       }\r
       embeddedPopup.clear();\r
     }\r
-    if (embeddedMenu!=null)\r
+    if (embeddedMenu != null)\r
     {\r
       embeddedMenu.removeAll();\r
     }\r
   }\r
+\r
   /**\r
    * calls destroyMenus()\r
    */\r
-  public void finalize() throws Throwable {\r
+  public void finalize() throws Throwable\r
+  {\r
     destroyMenus();\r
-    embeddedPopup=null;\r
-    embeddedMenu=null;\r
+    embeddedPopup = null;\r
+    embeddedMenu = null;\r
     super.finalize();\r
   }\r
-}
\ No newline at end of file
+}\r