📄 menucomponent.java
字号:
/* * MenuComponent.java * * Created on January 28, 2001, 8:10 PM */package net.sf.navigator.menu;import java.util.ArrayList;import java.util.List;import java.util.Iterator;import java.io.Serializable;import org.apache.commons.lang.builder.EqualsBuilder;import org.apache.commons.lang.builder.HashCodeBuilder;import org.apache.commons.lang.builder.ToStringBuilder;import org.apache.commons.lang.builder.ToStringStyle;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;/** * This class extends {@link MenuBase} and basically contains helper methods * for adding and fetching children and parents. * * @author Scott Sayles, Matt Raible * @version $Revision: 1.6 $ $Date: 2004/03/14 04:16:58 $ */public class MenuComponent extends MenuBase implements Serializable { //~ Static fields/initializers ============================================= private static Log log = LogFactory.getLog(MenuComponent.class); protected static MenuComponent[] _menuComponent = new MenuComponent[0]; //~ Instance fields ======================================================== protected List menuComponents = new ArrayList(); protected MenuComponent parentMenu = null; //~ Constructors =========================================================== /** Creates new MenuComponent */ public MenuComponent() { super(); } //~ Methods ================================================================ public void addMenuComponent(MenuComponent menuComponent) { if ((menuComponent.getName() == null) || (menuComponent.getName().equals(""))) { menuComponent.setName(this.name + menuComponents.size()); } if (!menuComponents.contains(menuComponent)) { menuComponents.add(menuComponent); menuComponent.setParent(this); } } public MenuComponent[] getMenuComponents() { MenuComponent[] menus = (MenuComponent[]) menuComponents.toArray(_menuComponent); return menus; } public void setParent(MenuComponent parentMenu) { if (parentMenu != null) { // look up the parent and make sure that it has this menu as a child if (!parentMenu.getComponents().contains(this)) { parentMenu.addMenuComponent(this); } } this.parentMenu = parentMenu; } public MenuComponent getParent() { return parentMenu; } /** * Convenience method for Velocity templates */ public List getComponents() { return menuComponents; } public String toString() { return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); } /** * This method compares all attributes, except for parent and children * @param o * @return */ public boolean equals(Object o) { if (!(o instanceof MenuComponent)) { return false; } MenuComponent m = (MenuComponent) o; // Compare using StringUtils to avoid NullPointerExceptions return StringUtils.equals(m.getAction(), this.action) && StringUtils.equals(m.getAltImage(), this.altImage) && StringUtils.equals(m.getDescription(), this.description) && StringUtils.equals(m.getForward(), this.forward) && StringUtils.equals(m.getHeight(), this.height) && StringUtils.equals(m.getImage(), this.image) && StringUtils.equals(m.getLocation(), this.location) && StringUtils.equals(m.getName(), this.name) && StringUtils.equals(m.getOnclick(), this.onclick) && StringUtils.equals(m.getOnmouseout(), this.onmouseout) && StringUtils.equals(m.getOnmouseover(), this.onmouseover) && StringUtils.equals(m.getPage(), this.page) && StringUtils.equals(m.getRoles(), this.roles) && StringUtils.equals(m.getTarget(), this.target) && StringUtils.equals(m.getTitle(), this.title) && StringUtils.equals(m.getToolTip(), this.toolTip) && StringUtils.equals(m.getWidth(), this.width); } public int hashCode(Object o) { return HashCodeBuilder.reflectionHashCode(this); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -