Context Menu Sample (Smart GWT) : Context Menu « GWT « Java






Context Menu Sample (Smart GWT)

Context Menu Sample (Smart GWT)
  
/*
 * SmartGWT (GWT for SmartClient)
 * Copyright 2008 and beyond, Isomorphic Software, Inc.
 *
 * SmartGWT 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.  SmartGWT 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.
 */

package com.smartgwt.sample.showcase.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.smartgwt.client.types.AnimationEffect;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.Img;
import com.smartgwt.client.widgets.menu.Menu;
import com.smartgwt.client.widgets.menu.MenuButton;
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;

public class Showcase implements EntryPoint{

    public void onModuleLoad() {
       RootPanel.get().add(getViewPanel());
    }
    public Canvas getViewPanel() {
      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);

      MenuButton mainMenuButton = new MenuButton("Widget", mainMenu);
      mainMenuButton.setWidth(150);

      canvas.addChild(mainMenuButton);

      return canvas;
    }

}

   
    
  








SmartGWT.zip( 9,880 k)

Related examples in the same category