X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FEmbmenuFrame.java;h=005f4a33c225a05b857577b0b4b5e372d422aff2;hb=863467bf6c59c0bc5368c8f3a03d9d5a4f10700d;hp=23f6aa2c1b7a67c36baf023f89c9a28c50fd6eed;hpb=07dde9901f660659e46183f1455fc4dcea720e2d;p=jalview.git
diff --git a/src/jalview/appletgui/EmbmenuFrame.java b/src/jalview/appletgui/EmbmenuFrame.java
index 23f6aa2..005f4a3 100644
--- a/src/jalview/appletgui/EmbmenuFrame.java
+++ b/src/jalview/appletgui/EmbmenuFrame.java
@@ -1,3 +1,20 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * 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.
+ *
+ * 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 .
+ */
package jalview.appletgui;
import java.awt.BorderLayout;
@@ -19,18 +36,19 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Enumeration;
import java.util.Hashtable;
+
/**
- * This class implements a pattern form embedding toolbars as a panel with popups
- * for situations where the system menu bar is either invisible or inappropriate.
- * It was derived from the code for embedding the jalview applet alignFrame as
- * a component on the web-page, which requires the local alignFrame menu to be
- * attached to that panel rather than placed on the parent (which isn't allowed
- * anyhow).
- * TODO: try to modify the embeddedMenu display so it looks like a real toolbar menu
- * TODO: modify click/mouse handler for embeddedMenu so it behaves more like a real pulldown menu toolbar
+ * This class implements a pattern form embedding toolbars as a panel with
+ * popups for situations where the system menu bar is either invisible or
+ * inappropriate. It was derived from the code for embedding the jalview applet
+ * alignFrame as a component on the web-page, which requires the local
+ * alignFrame menu to be attached to that panel rather than placed on the parent
+ * (which isn't allowed anyhow). TODO: try to modify the embeddedMenu display so
+ * it looks like a real toolbar menu TODO: modify click/mouse handler for
+ * embeddedMenu so it behaves more like a real pulldown menu toolbar
*
* @author Jim Procter and Andrew Waterhouse
- *
+ *
*/
public class EmbmenuFrame extends Frame implements MouseListener
{
@@ -38,9 +56,10 @@ public class EmbmenuFrame extends Frame implements MouseListener
* map from labels to popup menus for the embedded menubar
*/
protected Hashtable embeddedPopup;
+
/**
- * the embedded menu is built on this and should be
- * added to the frame at the appropriate position.
+ * the embedded menu is built on this and should be added to the frame at the
+ * appropriate position.
*
*/
protected Panel embeddedMenu;
@@ -49,20 +68,25 @@ public class EmbmenuFrame extends Frame implements MouseListener
{
super();
}
+
public EmbmenuFrame(String title) throws HeadlessException
{
super(title);
}
+
/**
- * Check if the applet is running on a platform that requires the Frame menuBar to be embedded,
- * and if so, embeds it.
- * @param tobeAdjusted the panel that is to be reduced to make space for the embedded menu bar
+ * Check if the applet is running on a platform that requires the Frame
+ * menuBar to be embedded, and if so, embeds it.
+ *
+ * @param tobeAdjusted
+ * the panel that is to be reduced to make space for the embedded
+ * menu bar
* @return true if menuBar was embedded and tobeAdjusted's height modified
*/
protected boolean embedMenuIfNeeded(Panel tobeAdjusted)
{
MenuBar topMenuBar = getMenuBar();
- if (topMenuBar==null)
+ if (topMenuBar == null)
{
return false;
}
@@ -70,43 +94,53 @@ public class EmbmenuFrame extends Frame implements MouseListener
if (new jalview.util.Platform().isAMac())
{
// Build the embedded menu panel
- embeddedMenu = makeEmbeddedPopupMenu(topMenuBar, "Arial", Font.PLAIN, 10, true); // try to pickup system font.
+ embeddedMenu = makeEmbeddedPopupMenu(topMenuBar, "Arial", Font.PLAIN,
+ 10, true); // try to pickup system font.
setMenuBar(null);
// add the components to the TreePanel area.
add(embeddedMenu, BorderLayout.NORTH);
- tobeAdjusted.setSize(getSize().width,
- getSize().height
- - embeddedMenu.HEIGHT);
+ tobeAdjusted.setSize(getSize().width, getSize().height
+ - embeddedMenu.HEIGHT);
return true;
}
return false;
}
+
/**
- * move all menus on menuBar onto embeddedMenu.
- * embeddedPopup is used to store the popups for each menu removed from the menuBar and added
- * to the panel.
- * NOTE: it is up to the caller to remove menuBar from the Frame if it is already attached.
+ * move all menus on menuBar onto embeddedMenu. embeddedPopup is used to store
+ * the popups for each menu removed from the menuBar and added to the panel.
+ * NOTE: it is up to the caller to remove menuBar from the Frame if it is
+ * already attached.
+ *
* @param menuBar
* @param fn
* @param fstyle
* @param fsz
- * @param overrideFonts true if we take the menuBar fonts in preference to the supplied defaults
+ * @param overrideFonts
+ * true if we take the menuBar fonts in preference to the supplied
+ * defaults
* @return the embedded menu instance to be added to the frame.
*/
protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,
int fstyle, int fsz, boolean overrideFonts)
{
- return makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts, false);
+ return makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts,
+ false);
}
+
/**
- * Create or add elements to the embedded menu from menuBar. This removes all menu from
- * menuBar and it is up to the caller to remove the now useless menuBar from the Frame if it is already attached.
+ * Create or add elements to the embedded menu from menuBar. This removes all
+ * menu from menuBar and it is up to the caller to remove the now useless
+ * menuBar from the Frame if it is already attached.
+ *
* @param menuBar
* @param fn
* @param fstyle
* @param fsz
- * @param overrideFonts
- * @param append true means existing menu will be emptied before adding new elements
+ * @param overrideFonts
+ * @param append
+ * true means existing menu will be emptied before adding new
+ * elements
* @return
*/
protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,
@@ -117,59 +151,71 @@ public class EmbmenuFrame extends Frame implements MouseListener
if (embeddedPopup != null)
{
embeddedPopup.clear(); // TODO: check if j1.1
- }
- if (embeddedMenu!=null)
+ }
+ if (embeddedMenu != null)
{
- embeddedMenu.removeAll();
+ embeddedMenu.removeAll();
}
}
- if (embeddedPopup==null)
+ if (embeddedPopup == null)
{
embeddedPopup = new Hashtable();
}
-
- embeddedMenu = makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz, overrideFonts, embeddedPopup, new Panel(), this);
+
+ embeddedMenu = makeEmbeddedPopupMenu(menuBar, fn, fstyle, fsz,
+ overrideFonts, embeddedPopup, new Panel(), this);
return embeddedMenu;
}
+
/**
- * Generic method to move elements from menubar onto embeddedMenu using the existing or the supplied font,
- * and adds binding from panel to attached menus in embeddedPopup
- * This removes all menu from
- * menuBar and it is up to the caller to remove the now useless menuBar from the Frame if it is already attached.
- * @param menuBar must be non-null
+ * Generic method to move elements from menubar onto embeddedMenu using the
+ * existing or the supplied font, and adds binding from panel to attached
+ * menus in embeddedPopup This removes all menu from menuBar and it is up to
+ * the caller to remove the now useless menuBar from the Frame if it is
+ * already attached.
+ *
+ * @param menuBar
+ * must be non-null
* @param fn
* @param fstyle
* @param fsz
* @param overrideFonts
- * @param embeddedPopup must be non-null
- * @param embeddedMenu if null, a new panel will be created and returned
- * @param clickHandler - usually the instance of EmbmenuFrame that holds references to embeddedPopup and embeddedMenu
+ * @param embeddedPopup
+ * must be non-null
+ * @param embeddedMenu
+ * if null, a new panel will be created and returned
+ * @param clickHandler
+ * - usually the instance of EmbmenuFrame that holds references to
+ * embeddedPopup and embeddedMenu
* @return the panel instance for convenience.
*/
protected Panel makeEmbeddedPopupMenu(MenuBar menuBar, String fn,
- int fstyle, int fsz, boolean overrideFonts, Hashtable embeddedPopup, Panel embeddedMenu, MouseListener clickHandler)
+ int fstyle, int fsz, boolean overrideFonts,
+ Hashtable embeddedPopup, Panel embeddedMenu,
+ MouseListener clickHandler)
{
- if (embeddedPopup==null)
+ if (embeddedPopup == null)
{
- throw new Error("Implementation error - embeddedPopup must be non-null");
+ throw new Error(
+ "Implementation error - embeddedPopup must be non-null");
}
if (overrideFonts)
{
Font mbf = menuBar.getFont();
- if (mbf!=null)
+ if (mbf != null)
{
fn = mbf.getName();
fstyle = mbf.getStyle();
fsz = mbf.getSize();
}
}
- if (embeddedMenu==null)
+ if (embeddedMenu == null)
embeddedMenu = new Panel();
FlowLayout flowLayout1 = new FlowLayout();
embeddedMenu.setBackground(Color.lightGray);
embeddedMenu.setLayout(flowLayout1);
// loop thru
- for (int mbi = 0,nMbi=menuBar.getMenuCount(); mbi