1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.widget.client;
26
27 import java.util.ArrayList;
28
29 import com.google.gwt.event.dom.client.MouseDownEvent;
30 import com.google.gwt.event.dom.client.MouseDownHandler;
31 import com.google.gwt.user.client.ui.AbsolutePanel;
32 import com.google.gwt.user.client.ui.Composite;
33 import com.google.gwt.user.client.ui.Panel;
34 import com.google.gwt.user.client.ui.TabPanel;
35 import com.google.gwt.user.client.ui.Widget;
36
37
38
39
40
41
42
43 public class TabbedTrackFrame extends Composite {
44
45 private AbsolutePanel boundaryPanel = new AbsolutePanel();
46 private TabPanel tabPanel = new TabPanel();
47
48
49 private ArrayList<Tab> tabList = new ArrayList<Tab>();
50
51 public TabbedTrackFrame() {
52 Style.fullSize(boundaryPanel);
53 Style.fullSize(tabPanel);
54 boundaryPanel.add(tabPanel);
55
56
57 initWidget(boundaryPanel);
58 }
59
60 public Panel getTabContent(int index) {
61 return (Panel) tabPanel.getWidget(index);
62 }
63
64 private class TabClickListener implements MouseDownHandler {
65 private final int tabIndex;
66
67 public TabClickListener(int tabIndex) {
68 this.tabIndex = tabIndex;
69 }
70
71 public void onMouseDown(MouseDownEvent arg0) {
72 selectTab(tabIndex);
73 }
74 }
75
76 public void addTab(TrackPanel panel, Tab tabWidget) {
77
78 tabPanel.add((Widget) panel, tabWidget);
79 int tabIndex = tabPanel.getTabBar().getTabCount() - 1;
80 tabList.add(tabWidget);
81
82 tabWidget.setParenTabPanel(tabPanel, (Widget) panel);
83 tabWidget.addMouseDownHandler(new TabClickListener(tabIndex));
84
85
86
87
88 }
89
90
91
92
93
94
95 public void enableClose(int tabIndex, boolean enableClose) {
96 if (tabIndex > tabList.size())
97 throw new IndexOutOfBoundsException("out of bound tab index: " + tabIndex);
98
99 tabList.get(tabIndex).enableCloseButton(enableClose);
100 }
101
102 public void selectTab(int index) {
103 tabPanel.selectTab(index);
104
105 for (int i = 0; i < tabList.size(); i++) {
106 Tab tab = tabList.get(i);
107 tabList.get(i).setSelect(i == index);
108 }
109 }
110
111 }