01: /*
02: * MyGWT Widget Library
03: * Copyright(c) 2007, MyGWT.
04: * licensing@mygwt.net
05: *
06: * http://mygwt.net/license
07: */
08: package net.mygwt.samples.explorer.client;
09:
10: import net.mygwt.samples.resources.client.TestData;
11: import net.mygwt.ui.client.Events;
12: import net.mygwt.ui.client.Style;
13: import net.mygwt.ui.client.event.BaseEvent;
14: import net.mygwt.ui.client.event.Listener;
15: import net.mygwt.ui.client.event.SelectionListener;
16: import net.mygwt.ui.client.widget.Button;
17: import net.mygwt.ui.client.widget.ButtonBar;
18: import net.mygwt.ui.client.widget.Info;
19: import net.mygwt.ui.client.widget.TabFolder;
20: import net.mygwt.ui.client.widget.TabItem;
21: import net.mygwt.ui.client.widget.WidgetContainer;
22: import net.mygwt.ui.client.widget.layout.FlowLayout;
23: import net.mygwt.ui.client.widget.layout.RowData;
24: import net.mygwt.ui.client.widget.layout.RowLayout;
25:
26: public class TabFolderPage extends Page {
27:
28: private int count = 1;
29:
30: protected void createWidget(WidgetContainer container) {
31: final TabFolder tabFolder = new TabFolder(Style.TOP);
32: tabFolder.setTabWidth(85);
33: tabFolder.addListener(Events.SelectionChange, new Listener() {
34: public void handleEvent(BaseEvent be) {
35: TabItem item = (TabItem) be.item;
36: Info.show("Selection Changed",
37: "The '{0}' item was selected", item.getText());
38: }
39: });
40:
41: TabItem item = new TabItem(Style.NONE);
42: item.setText("GWT");
43: item.setIconStyle("icon-tabs");
44: item.setURL("http://code.google.com/webtoolkit");
45: tabFolder.add(item);
46: tabFolder.setSelection(item);
47:
48: item = new TabItem(Style.CLOSE);
49: item.setText("Close");
50: item.setIconStyle("icon-tabs");
51: item.addListener(Events.Close, new Listener() {
52: public void handleEvent(BaseEvent be) {
53: TabItem item = (TabItem) be.widget;
54: Info.show("Close", "Closing {0}", item.getText());
55: }
56: });
57: WidgetContainer c = item.getContainer();
58: c.setScrollEnabled(true);
59: c.setLayout(new FlowLayout(0));
60: c.addText(TestData.DUMMY_TEXT_LONG);
61: tabFolder.add(item);
62:
63: item = new TabItem(Style.CLOSE);
64: item.setText("Tab 3");
65: item.setIconStyle("icon-tabs");
66: item.addListener(Events.Close, new Listener() {
67: public void handleEvent(BaseEvent be) {
68: TabItem item = (TabItem) be.widget;
69: Info.show("Close", "Closing {0}", item.getText());
70: }
71: });
72:
73: tabFolder.add(item);
74:
75: ButtonBar buttonBar = new ButtonBar(Style.LEFT);
76: buttonBar.add(new Button("Add TabItem",
77: new SelectionListener() {
78:
79: public void widgetSelected(BaseEvent be) {
80: TabItem item = new TabItem(Style.CLOSE);
81: item.setText("New Item " + count++);
82: tabFolder.add(item);
83: }
84:
85: }));
86:
87: container.setScrollEnabled(false);
88: RowLayout layout = new RowLayout(Style.VERTICAL);
89: layout.setMargin(6);
90: container.setLayout(layout);
91:
92: container.add(tabFolder, new RowData(RowData.FILL_BOTH));
93: container.add(buttonBar);
94:
95: }
96:
97: }
|