001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008: package com.gwtext.sample.showcase2.client.button;
009:
010: import com.gwtext.client.widgets.Button;
011: import com.gwtext.client.widgets.Panel;
012: import com.gwtext.client.widgets.form.Checkbox;
013: import com.gwtext.client.widgets.form.FormPanel;
014: import com.gwtext.client.widgets.form.event.CheckboxListenerAdapter;
015: import com.gwtext.client.widgets.layout.HorizontalLayout;
016: import com.gwtext.client.widgets.menu.Item;
017: import com.gwtext.client.widgets.menu.Menu;
018: import com.gwtext.client.widgets.menu.MenuItem;
019: import com.gwtext.sample.showcase2.client.ShowcasePanel;
020:
021: /**
022: * Menu Button sample.
023: */
024: public class MenuButtonSample extends ShowcasePanel {
025:
026: public String getSourceUrl() {
027: return "source/button/MenuButtonSample.java.html";
028: }
029:
030: public String getCssUrl() {
031: return "source/button/MenuButtonSample.css.html";
032: }
033:
034: public Panel getViewPanel() {
035: if (panel == null) {
036: panel = new Panel();
037: //add some extra space on to for the menu to be displayed
038: panel.setPaddings(100, 0, 0, 0);
039:
040: //create the button
041: final Button button = new Button();
042: button.setText("Start");
043: button.setIconCls("office-icon");
044:
045: //create the menu we want to assign to the button
046: Menu menu = new Menu();
047:
048: Item wordItem = new Item("Word");
049: wordItem.setIconCls("word-icon");
050: menu.addItem(wordItem);
051:
052: Item excelItem = new Item("Excel");
053: excelItem.setIconCls("excel-icon");
054: menu.addItem(excelItem);
055:
056: //create a sub menu
057: Menu subMenu = new Menu();
058: Item cItem = new Item("C");
059: cItem.setIconCls("c-icon");
060:
061: Item cppItem = new Item("C++");
062: cppItem.setIconCls("cpp-icon");
063:
064: Item csharpItem = new Item("CSharp");
065: csharpItem.setIconCls("csharp-icon");
066:
067: subMenu.addItem(cItem);
068: subMenu.addItem(cppItem);
069: subMenu.addItem(csharpItem);
070:
071: //add menu item that has sub menu
072: MenuItem vsItem = new MenuItem("Visual Studio", subMenu);
073: vsItem.setIconCls("visualstudio-icon");
074: menu.addItem(vsItem);
075:
076: Item powerPointItem = new Item("PowerPoint");
077: powerPointItem.setIconCls("powerpoint-icon");
078: menu.addItem(powerPointItem);
079:
080: //assign the menu to to the button
081: button.setMenu(menu);
082:
083: FormPanel form = new FormPanel();
084: form.setBorder(false);
085: Checkbox cb = new Checkbox("Menu on top?");
086:
087: //dynamically change the poistion of the menu in relation to the button
088: cb.addListener(new CheckboxListenerAdapter() {
089: public void onCheck(Checkbox field, boolean checked) {
090: log(EVENT, "Checkbox "
091: + (checked ? " checked." : " unchecked."));
092: if (checked) {
093: //set position to top
094: button.setMenuAlign("bl-tl");
095: } else {
096: //set position to bottom
097: button.setMenuAlign("tl-bl?");
098: }
099: }
100: });
101: form.add(cb);
102:
103: Panel horizontalPanel = new Panel();
104: horizontalPanel.setLayout(new HorizontalLayout(15));
105:
106: horizontalPanel.add(button);
107: horizontalPanel.add(form);
108:
109: panel.add(horizontalPanel);
110: }
111: return panel;
112: }
113:
114: protected boolean showEvents() {
115: return true;
116: }
117:
118: public String getIntro() {
119: return "<p>This example demonstrates a Menu associated with a Button. When the Button is clicked,"
120: + " the Button's Menu is displayed. You can attach event listeners for various actions.</p>"
121: + "<p>The position on the Menu (and SubMenu's) is configurable. Try toggling the checkbox "
122: + " and then click the Button for an example of this.</p>";
123: }
124: }
|