dsto.dfc.swing.commands
Class CommandMenus

java.lang.Object
  extended by dsto.dfc.swing.commands.CommandMenus

public final class CommandMenus
extends Object

Utility for generating menus from command views.

Version:
$Revision$

Method Summary
static Command getCommandForMenuItem(JComponent menuComponent)
           
static Point getMenuLocation(Component parent, JPopupMenu menu, int x, int y)
          Compute best location for menu, bumping location from (x, y) if necessary to fit menu on screen.
static void installContextMenu(Component target, CommandView view)
          Install a context menu based on a given command view to popup when the right mouse button is pressed on a component.
static void installContextMenu(Component target, CommandView view, boolean attachToScrollPane)
          Install a context menu based on a given command view to popup when the right mouse button is pressed on a component.
static void makeMenuBar(JMenuBar menuBar, CommandView commandView)
          Create a menu bar from a command view.
static void makePopupMenu(JPopupMenu menu, CommandView commandView)
           
static void makePopupMenu(JPopupMenu menu, CommandView commandView, CommandViewNode node)
           
static boolean showContextMenu(Component parent, int x, int y)
          Show the context menu (if any) installed on a component with installContextMenu().
static void showContextMenu(Component parent, JPopupMenu menu, int x, int y)
          Show a context menu at a given suggested location, bumping menu to fit on screen as necessary.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

makeMenuBar

public static void makeMenuBar(JMenuBar menuBar,
                               CommandView commandView)
Create a menu bar from a command view.


makePopupMenu

public static void makePopupMenu(JPopupMenu menu,
                                 CommandView commandView)

makePopupMenu

public static void makePopupMenu(JPopupMenu menu,
                                 CommandView commandView,
                                 CommandViewNode node)

installContextMenu

public static void installContextMenu(Component target,
                                      CommandView view)
Install a context menu based on a given command view to popup when the right mouse button is pressed on a component.

Parameters:
target - The component to detect clicks on. If target is a JComponent, auto-attach-to-scrollpane is enabled.
view - The view for the context menu.

installContextMenu

public static void installContextMenu(Component target,
                                      CommandView view,
                                      boolean attachToScrollPane)
Install a context menu based on a given command view to popup when the right mouse button is pressed on a component.

Parameters:
target - The component to detect clicks on.
view - The view for the context menu.
attachToScrollPane - If true, enable auto-attach-to-scrollpane mode where the context menu pops up on right clicks in a scroll pane containing target as well as in the target itself.

showContextMenu

public static boolean showContextMenu(Component parent,
                                      int x,
                                      int y)
Show the context menu (if any) installed on a component with installContextMenu().

Parameters:
parent - The component to show the menu for.
x - The X coord of the menu.
y - The Y coord of the menu.
Returns:
True if the menu was displayed.

showContextMenu

public static void showContextMenu(Component parent,
                                   JPopupMenu menu,
                                   int x,
                                   int y)
Show a context menu at a given suggested location, bumping menu to fit on screen as necessary.

Parameters:
parent - The parent of the menu.
menu - The menu to show. If this menu has no compoments, then this method is a noop.
x - The suggested X coord of the menu.
y - The suggested Y coord of the menu.
See Also:
getMenuLocation(java.awt.Component, javax.swing.JPopupMenu, int, int)

getMenuLocation

public static Point getMenuLocation(Component parent,
                                    JPopupMenu menu,
                                    int x,
                                    int y)
Compute best location for menu, bumping location from (x, y) if necessary to fit menu on screen.


getCommandForMenuItem

public static Command getCommandForMenuItem(JComponent menuComponent)


Copyright © 2008 Commonwealth of Australia