-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathTabPanel.java
More file actions
executable file
·94 lines (88 loc) · 2.48 KB
/
Copy pathTabPanel.java
File metadata and controls
executable file
·94 lines (88 loc) · 2.48 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package javaforce.webui;
/** Tabbed Panel
*
* @author pquiring
*/
public class TabPanel extends Panel {
private Column tabs;
private Row row;
private int idx;
private boolean borders = true;
private boolean tabsVisible = true;
public TabPanel() {
addClass("tab");
setBorderGray(true);
row = new Row();
add(row);
tabs = new Column();
tabs.setMaxWidth();
tabs.setMaxHeight();
add(tabs);
setAlign(Component.LEFT);
}
/** Creates borders on added tabs. */
public void setBorders(boolean state) {
borders = state;
setBorderGray(state);
}
public void addTab(Panel panel, String text) {
int cnt = row.count();
Label label = new Label(text);
label.setClass("tab" + (cnt == 0 ? "active" : "inactive"));
if (borders) label.setBorderGray(true);
row.add(label);
tabs.add(panel);
panel.setClass("tabcontent" + (cnt == 0 ? "shown" : "hidden"));
if (borders) panel.setBorderGray(true);
}
/** Shows or hides the tabs so only the panels are visible.
* If the tabs are not visible the user can not change tabs.
*/
public void setTabsVisible(boolean state) {
if (tabsVisible == state) return;
tabsVisible = state;
if (state) {
add(0, row);
} else {
remove(row);
}
}
public void init() {
super.init();
int cnt = row.count();
for(int a=0;a<cnt;a++) {
Component c = row.get(a);
c.addEvent("onclick", "openTab(event," + a + ",\"" + id + "\",\"" + row.id + "\",\"" + tabs.id + "\");");
}
}
public void onLoaded(String[] args) {
super.onLoaded(args);
sendOnResize();
}
public void setTabIndex(int idx) {
if (idx == this.idx) return;
Label currentLbl = (Label)row.get(this.idx);
currentLbl.removeClass("tabactive");
currentLbl.addClass("tabinactive");
Label newLbl = (Label)row.get(idx);
newLbl.removeClass("tabinactive");
newLbl.addClass("tabactive");
Panel currentPanel = (Panel)tabs.get(this.idx);
currentPanel.removeClass("tabcontentshown");
currentPanel.addClass("tabcontenthidden");
Panel newPanel = (Panel)tabs.get(idx);
newPanel.removeClass("tabcontenthidden");
newPanel.addClass("tabcontentshown");
this.idx = idx;
}
public int getTabIndex() {
return idx;
}
public int getTabsCount() {
return tabs.count();
}
public void removeTab(int idx) {
row.remove(idx);
tabs.remove(idx);
}
}