123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- /*
- @VaadinApache2LicenseForJavaFiles@
- */
-
- package com.vaadin.terminal.gwt.client.ui;
-
- /*
- * Copyright 2007 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-
- // COPIED HERE DUE package privates in GWT
- import com.google.gwt.user.client.Command;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.ui.HasHTML;
- import com.google.gwt.user.client.ui.UIObject;
-
- /**
- * A widget that can be placed in a
- * {@link com.google.gwt.user.client.ui.MenuBar}. Menu items can either fire a
- * {@link com.google.gwt.user.client.Command} when they are clicked, or open a
- * cascading sub-menu.
- *
- * @deprecated
- */
- @Deprecated
- public class MenuItem extends UIObject implements HasHTML {
-
- private static final String DEPENDENT_STYLENAME_SELECTED_ITEM = "selected";
-
- private Command command;
- private MenuBar parentMenu, subMenu;
-
- /**
- * Constructs a new menu item that fires a command when it is selected.
- *
- * @param text
- * the item's text
- * @param cmd
- * the command to be fired when it is selected
- */
- public MenuItem(String text, Command cmd) {
- this(text, false);
- setCommand(cmd);
- }
-
- /**
- * Constructs a new menu item that fires a command when it is selected.
- *
- * @param text
- * the item's text
- * @param asHTML
- * <code>true</code> to treat the specified text as html
- * @param cmd
- * the command to be fired when it is selected
- */
- public MenuItem(String text, boolean asHTML, Command cmd) {
- this(text, asHTML);
- setCommand(cmd);
- }
-
- /**
- * Constructs a new menu item that cascades to a sub-menu when it is
- * selected.
- *
- * @param text
- * the item's text
- * @param subMenu
- * the sub-menu to be displayed when it is selected
- */
- public MenuItem(String text, MenuBar subMenu) {
- this(text, false);
- setSubMenu(subMenu);
- }
-
- /**
- * Constructs a new menu item that cascades to a sub-menu when it is
- * selected.
- *
- * @param text
- * the item's text
- * @param asHTML
- * <code>true</code> to treat the specified text as html
- * @param subMenu
- * the sub-menu to be displayed when it is selected
- */
- public MenuItem(String text, boolean asHTML, MenuBar subMenu) {
- this(text, asHTML);
- setSubMenu(subMenu);
- }
-
- MenuItem(String text, boolean asHTML) {
- setElement(DOM.createTD());
- setSelectionStyle(false);
-
- if (asHTML) {
- setHTML(text);
- } else {
- setText(text);
- }
- setStyleName("gwt-MenuItem");
- }
-
- /**
- * Gets the command associated with this item.
- *
- * @return this item's command, or <code>null</code> if none exists
- */
- public Command getCommand() {
- return command;
- }
-
- public String getHTML() {
- return DOM.getInnerHTML(getElement());
- }
-
- /**
- * Gets the menu that contains this item.
- *
- * @return the parent menu, or <code>null</code> if none exists.
- */
- public MenuBar getParentMenu() {
- return parentMenu;
- }
-
- /**
- * Gets the sub-menu associated with this item.
- *
- * @return this item's sub-menu, or <code>null</code> if none exists
- */
- public MenuBar getSubMenu() {
- return subMenu;
- }
-
- public String getText() {
- return DOM.getInnerText(getElement());
- }
-
- /**
- * Sets the command associated with this item.
- *
- * @param cmd
- * the command to be associated with this item
- */
- public void setCommand(Command cmd) {
- command = cmd;
- }
-
- public void setHTML(String html) {
- DOM.setInnerHTML(getElement(), html);
- }
-
- /**
- * Sets the sub-menu associated with this item.
- *
- * @param subMenu
- * this item's new sub-menu
- */
- public void setSubMenu(MenuBar subMenu) {
- this.subMenu = subMenu;
- }
-
- public void setText(String text) {
- DOM.setInnerText(getElement(), text);
- }
-
- void setParentMenu(MenuBar parentMenu) {
- this.parentMenu = parentMenu;
- }
-
- void setSelectionStyle(boolean selected) {
- if (selected) {
- addStyleDependentName(DEPENDENT_STYLENAME_SELECTED_ITEM);
- } else {
- removeStyleDependentName(DEPENDENT_STYLENAME_SELECTED_ITEM);
- }
- }
- }
|