Package com.extjs.gxt.desktop.client

Source Code of com.extjs.gxt.desktop.client.StartMenu

/*
* Ext GWT - Ext for GWT
* Copyright(c) 2007, 2008, Ext JS, LLC.
* licensing@extjs.com
*
* http://extjs.com/license
*/
package com.extjs.gxt.desktop.client;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.event.ComponentEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.util.Rectangle;
import com.extjs.gxt.ui.client.widget.ComponentHelper;
import com.extjs.gxt.ui.client.widget.menu.Item;
import com.extjs.gxt.ui.client.widget.menu.Menu;
import com.extjs.gxt.ui.client.widget.menu.SeparatorMenuItem;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.Event;

/**
* A start menu component. Menu items can be added to the main region of the
* start menu, or to the "tool" area, which is located to the right.
*/
public class StartMenu extends Menu {

  private List<Item> tools = new ArrayList<Item>();;
  private String heading;
  private String iconStyle;
  private El header, headerText, menuBWrap, menuPanel, toolsPanel;

  public StartMenu() {
    addStyleName("ux-start-menu");
  }

  /**
   * Adds a item to the "tool" area of the start menu.
   *
   * @param item the item to add
   */
  public void addTool(Item item) {
    tools.add(item);
  }

  /**
   * Adds a seperator to the "too" area.
   */
  public void addToolSeperator() {
    SeparatorMenuItem sep = new SeparatorMenuItem();
    sep.setStyleName("ux-toolmenu-sep");
    addTool(sep);
  }

  /**
   * Returns the start menu's heading.
   *
   * @return the heading
   */
  public String getHeading() {
    return heading;
  }

  /**
   * Returns the menu's icon style.
   *
   * @return the icon style
   */
  public String getIconStyle() {
    return iconStyle;
  }

  /**
   * Sets the menu's heading text.
   *
   * @param heading the heading
   */
  public void setHeading(String heading) {
    this.heading = heading;
  }

  /**
   * Sets the menu's icon style.
   *
   * @param iconStyle the icon style
   */
  public void setIconStyle(String iconStyle) {
    this.iconStyle = iconStyle;
  }

  @Override
  public void show(Element elem, String pos) {
    super.show(elem, pos);
    el().updateZIndex(0);
    int tPanelWidth = 100;
    Rectangle box = menuBWrap.getBounds();
    menuPanel.setWidth(box.width - tPanelWidth);
    menuPanel.setHeight(box.height);
    toolsPanel.setWidth(tPanelWidth);
    toolsPanel.setX(box.x + box.width - tPanelWidth);
    toolsPanel.setHeight(box.height);
  }

  @Override
  public Item findItem(Element elem) {
    Item item = super.findItem(elem);
    if (item == null) {
      for (Item c : tools) {
        if (DOM.isOrHasChild(c.getElement(), elem)) {
          return c;
        }
      }
    } else {
      return item;
    }
    return null;
  }

  @Override
  protected void doAttachChildren() {
    super.doAttachChildren();
    for (Item item : tools) {
      ComponentHelper.doAttach(item);
    }
  }

  @Override
  protected void doDetachChildren() {
    super.doDetachChildren();
    for (Item item : tools) {
      ComponentHelper.doDetach(item);
    }
  }

  @Override
  protected void onRender(Element target, int index) {
    setElement(DOM.createDiv(), target, index);
    el().setStyleName("x-menu ux-start-menu");
    el().setWidth(300);
    El tl = el().createChild("<div class='ux-start-menu-tl'></div>");
    El tr = tl.createChild("<div class='ux-start-menu-tr'></div>");
    El tc = tr.createChild("<div class='ux-start-menu-tc'></div>");
    header = tc.createChild("<div class='x-window-header x-unselectable x-panel-icon " + iconStyle
        + "'></div>");
    headerText = header.createChild("<span class='x-window-header-text'></span>");
    headerText.setInnerHtml(heading);

    El bwrap = el().createChild("<div class='x-window-bwrap'></div>");

    El ml = bwrap.createChild("<div class='ux-start-menu-ml'></div>");
    El mc = ml.createChild("<div class='x-window-mc ux-start-menu-bwrap' style='border:none'></div>");

    El bl = bwrap.createChild("<div class='ux-start-menu-bl x-panel-nofooter'></div>");
    El br = bl.createChild("<div class='ux-start-menu-br'></div>");
    br.createChild("<div class='ux-start-menu-bc'></div>");

    menuBWrap = mc.createChild("<div class='x-window-body ux-start-menu-body' style='position:relative;border: none'></div>");
    menuBWrap.setHeight(300);

    menuPanel = menuBWrap.createChild("<div class='x-panel x-border-panel ux-start-menu-apps-panel' style='border: none;padding: 2px'></div>");
    toolsPanel = menuBWrap.createChild("<div class='x-panel x-border-panel ux-start-menu-tools-panel' style='padding: 2px'></div>");

    El ul = menuPanel.createChild("<ul class='x-menu-list'></ul>");
    El toolsUl = toolsPanel.createChild("<ul class='x-menu-list'></ul>");

    for (Item item : getItems()) {
      Element li = DOM.createElement("li");
      li.setClassName("x-menu-list-item");
      ul.dom.appendChild(li);
      item.render(li);
    }

    for (Item item : tools) {
      Element li = DOM.createElement("li");
      li.setClassName("x-menu-list-item");
      toolsUl.dom.appendChild(li);
      item.render(li);
      item.addSelectionListener(new SelectionListener<ComponentEvent>() {

        @Override
        public void componentSelected(ComponentEvent ce) {
          hide();
        }
      });
    }

    eventPreview.getIgnoreList().add(getElement());
    el().addEventsSunk(Event.ONCLICK | Event.MOUSEEVENTS | Event.KEYEVENTS);
  }

  @Override
  protected void onShow() {
    el().setVisible(true);
  }

}
TOP

Related Classes of com.extjs.gxt.desktop.client.StartMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.