001: /*
002: * MyGWT Widget Library
003: * Copyright(c) 2007, MyGWT.
004: * licensing@mygwt.net
005: *
006: * http://mygwt.net/license
007: */
008: package net.mygwt.samples.explorer.client;
009:
010: import net.mygwt.ui.client.Events;
011: import net.mygwt.ui.client.Style;
012: import net.mygwt.ui.client.event.BaseEvent;
013: import net.mygwt.ui.client.event.Listener;
014: import net.mygwt.ui.client.event.SelectionListener;
015: import net.mygwt.ui.client.widget.Info;
016: import net.mygwt.ui.client.widget.Item;
017: import net.mygwt.ui.client.widget.ThemeSelector;
018: import net.mygwt.ui.client.widget.ToolBar;
019: import net.mygwt.ui.client.widget.ToolItem;
020: import net.mygwt.ui.client.widget.ToolItemAdapter;
021: import net.mygwt.ui.client.widget.WidgetContainer;
022: import net.mygwt.ui.client.widget.layout.FillLayout;
023: import net.mygwt.ui.client.widget.menu.Menu;
024: import net.mygwt.ui.client.widget.menu.MenuItem;
025:
026: public class ToolBarPage extends Page {
027:
028: protected void createWidget(WidgetContainer container) {
029: SelectionListener listener = new SelectionListener() {
030: public void widgetSelected(BaseEvent be) {
031: Item item = (Item) be.widget;
032: String txt = item.getText() != null ? item.getText()
033: : item.getIconStyle();
034: Info.show("Item Selection", "Item '{0}' was selected.",
035: txt);
036: }
037: };
038: Listener checkListener = new Listener() {
039: public void handleEvent(BaseEvent be) {
040: MenuItem item = (MenuItem) be.widget;
041: String s = item.isSelected() ? "checked" : "unchecked";
042: String[] values = new String[] { s, item.getText() };
043: Info.show("Item Check", "You {0} the '{1}' menu item.",
044: values);
045: }
046: };
047:
048: ToolBar toolbar = new ToolBar();
049:
050: Menu newMenu = new Menu();
051: MenuItem menuItem = new MenuItem(Style.PUSH);
052: menuItem.setText("Email");
053: menuItem.setIconStyle("icon-email-add");
054: menuItem.addSelectionListener(listener);
055: newMenu.add(menuItem);
056:
057: menuItem = new MenuItem(Style.PUSH);
058: menuItem.setText("Appointment");
059: menuItem.setIconStyle("icon-date-add");
060: menuItem.addSelectionListener(listener);
061: newMenu.add(menuItem);
062:
063: menuItem = new MenuItem(Style.PUSH);
064: menuItem.setText("Contact");
065: menuItem.setIconStyle("icon-contact-add");
066: menuItem.addSelectionListener(listener);
067: newMenu.add(menuItem);
068:
069: ToolItem item = new ToolItem(Style.MENU);
070: item.setText("New");
071: item.setIconStyle("icon-email-add");
072: item.setMenu(newMenu);
073: item.addSelectionListener(listener);
074: toolbar.add(item);
075:
076: toolbar.add(new ToolItem(Style.SEPARATOR));
077:
078: item = new ToolItem(Style.PUSH);
079: item.setText("Disabled");
080: item.disable();
081: toolbar.add(item);
082:
083: toolbar.add(new ToolItem(Style.SEPARATOR));
084:
085: item = new ToolItem(Style.PUSH);
086: item.setIconStyle("icon-printer");
087: item.addSelectionListener(listener);
088:
089: item.setToolTip("Prints the document");
090: toolbar.add(item);
091:
092: toolbar.add(new ToolItem(Style.SEPARATOR));
093:
094: item = new ToolItem(Style.TOGGLE);
095: item.setText("Toggle");
096: item.setSelected(true);
097: item.addSelectionListener(listener);
098: toolbar.add(item);
099:
100: toolbar.add(new ToolItem(Style.SEPARATOR));
101:
102: Menu subMenu = new Menu();
103: MenuItem subItem = new MenuItem(Style.CHECK);
104: subItem.setText("Check Item 1");
105: subItem.setSelected(true);
106: subItem.addListener(Events.CheckChange, checkListener);
107: subMenu.add(subItem);
108:
109: subItem = new MenuItem(Style.CHECK);
110: subItem.setText("Check Item 2");
111: subItem.addListener(Events.CheckChange, checkListener);
112: subMenu.add(subItem);
113:
114: Menu radioSubMenu = new Menu();
115: MenuItem radioItem = new MenuItem(Style.RADIO);
116: radioItem.setText("Radio Item 1");
117: radioItem.setSelected(true);
118: radioItem.addListener(Events.CheckChange, checkListener);
119: radioSubMenu.add(radioItem);
120:
121: radioItem = new MenuItem(Style.RADIO);
122: radioItem.setText("Radio Item 2");
123: radioItem.addListener(Events.CheckChange, checkListener);
124: radioSubMenu.add(radioItem);
125:
126: Menu menu = new Menu();
127: MenuItem item1 = new MenuItem(Style.PUSH);
128: item1.setText("Menu Item 1");
129: item1.addSelectionListener(listener);
130: menu.add(item1);
131: item1 = new MenuItem(Style.PUSH);
132: item1.setText("Menu Item 2");
133: item1.addSelectionListener(listener);
134: menu.add(item1);
135:
136: menu.add(new MenuItem(Style.SEPARATOR));
137:
138: item1 = new MenuItem(Style.MENU);
139: item1.setText("Menu Item 3");
140: item1.setSubMenu(subMenu);
141: item1.addSelectionListener(listener);
142: menu.add(item1);
143:
144: item1 = new MenuItem(Style.MENU);
145: item1.setText("Menu Item 4");
146: item1.setSubMenu(radioSubMenu);
147: item1.addSelectionListener(listener);
148: menu.add(item1);
149:
150: item = new ToolItem(Style.SPLIT_MENU);
151: item.setText("Split Menu");
152: item.setMenu(menu);
153: item.addSelectionListener(listener);
154: toolbar.add(item);
155:
156: toolbar.add(new ToolItem(Style.SEPARATOR));
157:
158: // put a arbitrary widget in the tool bar using the adapter
159: ToolItemAdapter adapter = new ToolItemAdapter(
160: new ThemeSelector());
161: adapter.setStyleAttribute("paddingLeft", "5px");
162: toolbar.add(adapter);
163:
164: WidgetContainer c = new WidgetContainer();
165: c.add(toolbar);
166:
167: container.setLayout(new FillLayout(0));
168: container.add(c);
169: }
170:
171: }
|