blob: 3dff0f4fef66351a74811e5ae062cd930f13038b (
plain) (
blame)
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
|
package cppcheckplus.tab;
import cppcheckplus.control.MyContorlUtil;
import java.awt.Component;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class MyTabPanel extends JTabbedPane {
private int preferredUnselectedTabWidth;
private int preferredTabHeight;
public MyTabPanel() {
preferredUnselectedTabWidth = 80;
preferredTabHeight = MyContorlUtil.getImageIcon(
"control/images/tab_header_background.png").getIconHeight();
init();
}
private void init() {
setFont(MyContorlUtil.FONT_12_BOLD);
setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR);
setBorder(null);
setFocusable(false);
setTabLayoutPolicy(1);
setOpaque(false);
setUI(new MyTabPanelUI(this));
addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
updateTabComponents();
}
});
}
@Override
public void addTab(String title, Component component) {
super.addTab(title, component);
int index = getTabCount() - 1;
MyTabComponent tabComponent = new MyTabComponent(title, this);
tabComponent.setTitle(title);
setTabComponentAt(index, tabComponent);
setToolTipTextAt(index, title);
updateTabComponents();
}
public boolean isSelectTabComponents(String oId) {
for (int i = 0; i < getTabCount(); i++) {
Component c = getTabComponentAt(i);
if (c instanceof MyTabComponent) {
if (((MyTabComponent) c).getOId().equals(oId)) {
setSelectedIndex(i);
updateTabComponents();
return true;
}
}
}
return false;
}
public int getPreferredTabHeight() {
return preferredTabHeight;
}
private void updateTabComponents() {
int selectedIndex = getSelectedIndex();
for (int i = 0; i < getTabCount(); i++) {
Component c = getTabComponentAt(i);
if (c instanceof MyTabComponent) {
MyTabComponent component = (MyTabComponent) c;
boolean selected = selectedIndex == i;
component.updateSelection(selected);
}
}
}
public int getPreferredUnselectedTabWidth() {
return preferredUnselectedTabWidth;
}
}
|