Menu
object is a pull-down menu component that is deployed from a menu bar. A menu can optionally be a tear-off menu. A tear-off menu can be opened and dragged away from its parent menu bar or menu. It remains on the screen after the mouse button has been released. The mechanism for tearing off a menu is platform dependent, since the look and feel of the tear-off menu is determined by its peer. On platforms that do not support tear-off menus, the tear-off property is ignored.
Each item in a menu must belong to the MenuItem
class. It can be an instance of MenuItem
, a submenu (an instance of Menu
), or a check box (an instance of CheckboxMenuItem
).
@author Sami Shaio
@see ae.java.awt.MenuItem
@see ae.java.awt.CheckboxMenuItem
@since JDK1.0
Represents a hierarchical menu (tree) structure.
All items in the menu can be sorted using a Comparator, the same Comparator can be applied to all submenus in the tree. By default no comparator is attached and items will be sorted according to the natural order of their title.
Alternatively a Menu can be set as Ordered, in which case sorting will have no effect. The Ordered property must be set on all submenus separately, as it is not inherited. This means it is possible to provide an inheritable Comparator on the menu, but sort the menu itself manually and only use the Comparator for all submenus.
Note that sorting needs to be done explicitly, see {@link #sort()} method.The following features are supported:
User: Zhang Kaitao
Date: 13-4-9 下午4:20
Version: 1.0
A Menu is initialized with an Array of items, specified as menu.data, each of which represents one row in the menu's display and specifies the action to take when that menu item is selected.
Generally to create a context menu for a component, provide a Menu instance for the contextMenu
property. Note that some components have special context menu support because they have distinct regions or because they have a default set of context menu actions available.
If you want a button that pops up a menu when clicked, or a bar of such buttons, see the MenuButton and MenuBar classes. @see com.smartgwt.client.widgets.menu.Menu#getData @see com.smartgwt.client.widgets.Canvas#getContextMenu @see com.smartgwt.client.widgets.menu.MenuButton @see com.smartgwt.client.widgets.menu.MenuBar
NOTE: the deprecated menu type is accessible from the style properties associated with this menu.
@mock.generateMenu
object.
@author Antonella Giachino (antonella.giachino@eng.it)
Menu
object is a pull-down menu component that is deployed from a menu bar. A menu can optionally be a tear-off menu. A tear-off menu can be opened and dragged away from its parent menu bar or menu. It remains on the screen after the mouse button has been released. The mechanism for tearing off a menu is platform dependent, since the look and feel of the tear-off menu is determined by its peer. On platforms that do not support tear-off menus, the tear-off property is ignored.
Each item in a menu must belong to the MenuItem
class. It can be an instance of MenuItem
, a submenu (an instance of Menu
), or a check box (an instance of CheckboxMenuItem
).
@version 1.78, 04/07/06
@author Sami Shaio
@see java.awt.MenuItem
@see java.awt.CheckboxMenuItem
@since JDK1.0
Menu
class represents a displayable, interactive menu. It is abstract, so it can never be instantiated on its own. Instead, users should call the constructor of one of its subclasses, such as Toolbar
or Dock
. The main purpose for the Menu
class is to hold a large amount of generic structure and logic for managing and displaying a menu-type object within Processing. This includes: dealing with mouse events, keeping track of which menu item is currently hovered, selected, and open, and creating and drawing to an off-screen buffer when necessary (to allow us to use Java2D functions within a P3D or OpenGL PApplet).
The Menu
class is the base class for all other menu objects within this package. It inherits from the MenuItem
class, because a Menu should act like a well-behaved MenuItem as well (this way, we can cascade menus within other menus). It also helped keep down the amount of code repetition.
The side effect of this completely inherited organization is, of course, some complexity in thinking about the recursive method calls. You need to keep in mind that when the Menu
class calls super.someMethod()
, it's calling the method defined in the MenuItem
class.
There is also a slight issue with the fact that a Menu
should not be strictly considered a MenuItem
, because more often than not, the Menu
object itself does not "act" like a menu. Rather, its sub-items are what is shown to the screen and what interacts with the user. See the classes that extend the Menu
class for examples of how to deal with this code organization.
Important information for developers: if you plan to create a new type of menu using the Menu
class as a base class, you should keep in mind the following:
Dock
, Toolbar
, and VerticalMenu
. Examining how these classes interact with the Menu
structure will be very helpful when designing a novel Menu type.setOptions()
within your new class as a place to define your new menu's behavioral and display options. Particularly important are useCameraCoordinates
and usesJava2D
. See each option's javadoc for more information.
@author Greg
@see org.andrewberman.ui.menu.MenuItem
@see org.andrewberman.ui.menu.Dock
@see org.andrewberman.ui.menu.Toolbar
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <menu> <menu label="Home" path="user/home.htm" roles="tomcat, role1"/> <menu label="User" path="user/home.htm" roles="tomcat, role1"> <menu label="User Page 1" path="user/user-1.htm" roles="tomcat, role1"/> <menu label="User Page 2" path="user/user-2.htm" roles="tomcat, role1"/> </menu> <menu label="Admin" path="admin/admin-1.htm" roles="role1"> <menu label="Admin Page 1" path="admin/admin-1.htm" roles="tomcat, role1"/> <menu label="Admin Page 2" path="admin/admin-2.htm" roles="tomcat, role1"/> </menu> </menu>To include the root menu item in your page, simply use the default Menu constructor:
public class MenuPage extends Page { public Menu rootMenu = Menu.getRootMenu(); public ActionLink logoutLink = new ActionLink(this, "onLogoutClick"); }To render the configured Menu hierarchy you will need to use a Velocity #macro or Velocity code in your page. For example:
#writeMenu($rootMenu)An example menu Velocity macro is provided below:
#macro( writeMenu $rootMenu ) <table id="menuTable" border="0" width="100%" cellspacing="0" cellpadding="0" style="margin-top: 2px;"> <tr> <td> <div id="searchbar"> <div class="menustyle" id="menu"> <ul class="menubar" id="dmenu"> #foreach ($topMenu in $rootMenu.children) #if ($topMenu.isUserInRoles() || $topMenu.isUserInChildMenuRoles()) #if ($topMenu.children.empty) <li class="topitem">$topMenu</li> #else <li class="topitem">$topMenu <ul class="submenu" #foreach ($subMenu in $topMenu.children) #if ($subMenu.isUserInRoles()) ><li>$subMenu</li #end #end ></ul> </li> #end #end #end #if ($request.remoteUser) <li class="topitem"><a href="$logoutLink.href">Logout</a></li> #end </ul> </div> </div> </td> </tr> </table> #endThis example uses role path based security to only display the menu items the user is authorized to see. If you not using this security feature in your application you should remove the macro {@link #isUserInRoles()} checks sothe menu items will be rendered. Note individual menu items will render themselves as simple anchor tags using their {@link #toString()} method. For more fine grain control you shouldextend your Velocity macro to render individual menu items.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <menu> <menu label="Home" path="user/home.htm" roles="user,admin"> <menu label="Home" path="user/home.htm" roles="user,admin"/> <menu label="Search" path="user/search.htm" roles="user,admin"/> </menu> <menu label="Admin" path="admin/admin.htm"> <menu label="Home" path="admin/admin.htm" roles="admin"/> </menu> </menu>The underlying implementation of isUserInRoles() method is provided by an {@link AccessController} interface. The default AccessController is providedby the {@link RoleAccessController} which uses the JEE container is user inrole facility. By providing your own AccessController you can have menu access control using other security frameworks such as JSecurity or Spring Security (Acegi).
<!-- The Menu (menu.xml) Document Type Definition. --> <!ELEMENT menu (menu*)> <!ATTLIST menu label CDATA #IMPLIED> <!ATTLIST menu path CDATA #IMPLIED> <!ATTLIST menu target CDATA #IMPLIED> <!ATTLIST menu title CDATA #IMPLIED> <!ATTLIST menu imageSrc CDATA #IMPLIED> <!ATTLIST menu external (true|false) "false"> <!ATTLIST menu separator (true|false) "false"> <!ATTLIST menu roles CDATA #IMPLIED> <!ATTLIST menu pages CDATA #IMPLIED>
Default {@link #getZclass}: z-mean. (since 3.5.0) @author tomyeh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|