/* * Smart GWT (GWT for SmartClient) * Copyright 2008 and beyond, Isomorphic Software, Inc. * * Smart GWT is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License version 3 * as published by the Free Software Foundation. Smart GWT is also * available under typical commercial license terms - see * http://smartclient.com/license * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import com.smartgwt.client.types.AnimationEffect; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.menu.IMenuButton; import com.smartgwt.client.widgets.menu.Menu; import com.smartgwt.client.widgets.menu.MenuItem; import com.smartgwt.client.widgets.menu.MenuItemIfFunction; import com.smartgwt.client.widgets.menu.MenuItemSeparator; import com.smartgwt.client.widgets.menu.events.MenuItemClickEvent; import com.google.gwt.core.client.EntryPoint; public class ContextMenuSample implements EntryPoint { public void onModuleLoad() { Canvas canvas = new Canvas(); final Img widget = new Img("crystal/128/apps/xmms.png", 100, 100); widget.setLeft(200); widget.setTop(75); canvas.addChild(widget); Menu sizeMenu = new Menu(); sizeMenu.setWidth(150); MenuItem smallItem = new MenuItem("Small"); smallItem.setCheckIfCondition(new MenuItemIfFunction() { public boolean execute(Canvas target, Menu menu, MenuItem item) { return widget.getWidth() == 50; } }); smallItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateResize(50, 50); } }); MenuItem mediumItem = new MenuItem("Medium"); mediumItem.setCheckIfCondition(new MenuItemIfFunction() { public boolean execute(Canvas target, Menu menu, MenuItem item) { return widget.getWidth() == 100; } }); mediumItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateResize(100, 100); } }); MenuItem largeItem = new MenuItem("Large"); largeItem.setCheckIfCondition(new MenuItemIfFunction() { public boolean execute(Canvas target, Menu menu, MenuItem item) { return widget.getWidth() == 200; } }); largeItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateResize(200, 200); } }); sizeMenu.setItems(smallItem, mediumItem, largeItem); Menu moveMenu = new Menu(); moveMenu.setWidth(150); MenuItem upItem = new MenuItem("Up"); upItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateMove(widget.getOffsetX(), widget.getOffsetY() - 20); } }); MenuItem rightItem = new MenuItem("Right"); rightItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateMove(widget.getOffsetX() + 20, widget.getOffsetY()); } }); MenuItem downItem = new MenuItem("Down"); downItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateMove(widget.getOffsetX(), widget.getOffsetY() + 20); } }); MenuItem leftItem = new MenuItem("Left"); leftItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateMove(widget.getOffsetX() - 20, widget.getOffsetY()); } }); moveMenu.setData(upItem, rightItem, downItem, leftItem); Menu mainMenu = new Menu(); mainMenu.setWidth(150); widget.setContextMenu(mainMenu); MenuItem visibleItem = new MenuItem(); visibleItem.setTitle("Visible"); visibleItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { if (widget.isVisible()) { widget.animateHide(AnimationEffect.FADE); } else { widget.animateShow(AnimationEffect.FADE); } } }); MenuItemSeparator separator = new MenuItemSeparator(); MenuItem sizeItem = new MenuItem("Size"); sizeItem.setSubmenu(sizeMenu); MenuItem moveItem = new MenuItem("Move"); moveItem.setSubmenu(moveMenu); MenuItem resetItem = new MenuItem("Reset"); resetItem.addClickHandler(new com.smartgwt.client.widgets.menu.events.ClickHandler() { public void onClick(MenuItemClickEvent event) { widget.animateRect(200, 75, 100, 100); widget.animateShow(AnimationEffect.FADE); } }); resetItem.setIcon("crystal/128/apps/xmms.png"); resetItem.setIconWidth(20); resetItem.setIconHeight(20); mainMenu.setItems(visibleItem, separator, sizeItem, moveItem, separator, resetItem); IMenuButton mainMenuButton = new IMenuButton("Widget", mainMenu); mainMenuButton.setWidth(150); canvas.addChild(mainMenuButton); canvas.draw(); } }