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 com.google.gwt.event.dom.client.ClickEvent;
28 import com.google.gwt.event.dom.client.ClickHandler;
29 import com.google.gwt.event.dom.client.MouseDownHandler;
30 import com.google.gwt.event.dom.client.MouseOutEvent;
31 import com.google.gwt.event.dom.client.MouseOutHandler;
32 import com.google.gwt.event.dom.client.MouseOverEvent;
33 import com.google.gwt.event.dom.client.MouseOverHandler;
34 import com.google.gwt.user.client.ui.Composite;
35 import com.google.gwt.user.client.ui.FlexTable;
36 import com.google.gwt.user.client.ui.FocusPanel;
37 import com.google.gwt.user.client.ui.HorizontalPanel;
38 import com.google.gwt.user.client.ui.Label;
39 import com.google.gwt.user.client.ui.TabPanel;
40 import com.google.gwt.user.client.ui.VerticalPanel;
41 import com.google.gwt.user.client.ui.Widget;
42
43
44
45
46
47
48
49 public class Tab extends Composite implements MouseOutHandler, MouseOverHandler {
50
51 private FocusPanel focusPanel = new FocusPanel();
52 private FlexTable layoutFrame = new FlexTable();
53 private Label left = new Label();
54 private HorizontalPanel center = new HorizontalPanel();
55 private Label right = new Label();
56 private Label centerLabel = new Label();
57
58 UTGBDesignFactory designFactory = new UTGBDesignFactory();
59 private boolean enableClose = true;
60 private Icon closeButton;
61
62 private TabPanel parentTabPanel = null;
63 private Widget tabWidget = null;
64
65 public Tab(String label) {
66 drawWidget(label);
67
68 centerLabel.addMouseOutHandler(this);
69 centerLabel.addMouseOverHandler(this);
70
71 initWidget(focusPanel);
72 }
73
74 public void addMouseDownHandler(MouseDownHandler handler) {
75 centerLabel.addMouseDownHandler(handler);
76 }
77
78 private void drawWidget(String label) {
79
80 layoutFrame.setCellPadding(0);
81 layoutFrame.setCellSpacing(0);
82
83 Style.backgroundNoRepeat(left);
84 Style.fontSize(left, 0);
85
86 left.setPixelSize(9, 21);
87
88 centerLabel.setText(label);
89 center.setVerticalAlignment(VerticalPanel.ALIGN_MIDDLE);
90 center.add(centerLabel);
91
92 Style.fullWidth(center);
93 Style.textAlign(center, "center");
94
95 Style.backgroundRepeatX(center);
96 Style.fontSize(centerLabel, 13);
97 Style.fontFamily(centerLabel, "Arial, Helvetica, Tahoma");
98 Style.bold(centerLabel);
99 Style.fontColor(centerLabel, "#666666");
100 Style.nowrap(centerLabel);
101 Style.fullWidth(centerLabel);
102 center.setHeight("21px");
103
104 Style.backgroundNoRepeat(right);
105 Style.backgroundPosition(right, "top right");
106 Style.fontSize(right, 0);
107
108 center.setHorizontalAlignment(HorizontalPanel.ALIGN_RIGHT);
109 closeButton = designFactory.getTabCloseButton();
110 Style.padding(closeButton, Style.LEFT, 3);
111 Style.padding(closeButton, Style.TOP, 2);
112 center.add(closeButton);
113
114 closeButton.addClickHandler(new ClickHandler() {
115
116 public void onClick(ClickEvent arg0) {
117 if (!enableClose)
118 return;
119 if (parentTabPanel != null) {
120 if (tabWidget != null)
121 parentTabPanel.remove(tabWidget);
122 }
123 }
124
125 });
126
127 right.setPixelSize(9, 21);
128
129 layoutFrame.setHeight("21px");
130 layoutFrame.setWidth("100px");
131 layoutFrame.setWidget(0, 0, left);
132 layoutFrame.setWidget(0, 1, center);
133 layoutFrame.setWidget(0, 2, right);
134 layoutFrame.getRowFormatter().setVerticalAlign(0, VerticalPanel.ALIGN_MIDDLE);
135 layoutFrame.getCellFormatter().setWidth(0, 1, "100%");
136
137 setBackground(false);
138
139 focusPanel.setWidget(layoutFrame);
140 }
141
142 public void enableCloseButton(boolean enableClose) {
143 this.enableClose = enableClose;
144
145
146
147
148
149
150 closeButton.setVisible(enableClose);
151
152 }
153
154 public void setParenTabPanel(TabPanel tabPanel, Widget tabWidet) {
155 this.parentTabPanel = tabPanel;
156 this.tabWidget = tabWidet;
157 }
158
159 private void setBackground(boolean onMouse) {
160 if (onMouse) {
161 Style.backgroundImage(left, "theme/default/wframe_lw.gif");
162 Style.backgroundImage(center, "theme/default/wframe_cw.gif");
163 Style.backgroundImage(right, "theme/default/wframe_rw.gif");
164 }
165 else {
166 Style.backgroundImage(left, "theme/default/wframe_l.gif");
167 Style.backgroundImage(center, "theme/default/wframe_c.gif");
168 Style.backgroundImage(right, "theme/default/wframe_r.gif");
169 }
170 }
171
172 private boolean isSelected = false;
173
174 public void setSelect(boolean selected) {
175 isSelected = selected;
176 setBackground(selected);
177 }
178
179 public void onMouseOver(MouseOverEvent arg0) {
180 setBackground(true);
181 }
182
183 public void onMouseOut(MouseOutEvent arg0) {
184 setBackground(isSelected | false);
185 }
186
187 }