diff options
Diffstat (limited to 'src/cppcheckplus/tab/MyTabPanel1.java')
-rw-r--r-- | src/cppcheckplus/tab/MyTabPanel1.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/cppcheckplus/tab/MyTabPanel1.java b/src/cppcheckplus/tab/MyTabPanel1.java new file mode 100644 index 0000000..ace4d72 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabPanel1.java | |||
@@ -0,0 +1,96 @@ | |||
1 | package cppcheckplus.tab; | ||
2 | |||
3 | import java.awt.Component; | ||
4 | import javax.swing.JTabbedPane; | ||
5 | import javax.swing.event.ChangeEvent; | ||
6 | import javax.swing.event.ChangeListener; | ||
7 | |||
8 | import cppcheckplus.control.MyContorlUtil; | ||
9 | |||
10 | public class MyTabPanel1 extends JTabbedPane | ||
11 | { | ||
12 | private int preferredUnselectedTabWidth; | ||
13 | private int preferredTabHeight; | ||
14 | |||
15 | public MyTabPanel1() | ||
16 | { | ||
17 | preferredUnselectedTabWidth = 80; | ||
18 | preferredTabHeight = MyContorlUtil.getImageIcon("control/images/tab_header_background.png").getIconHeight(); | ||
19 | init(); | ||
20 | } | ||
21 | |||
22 | private void init() | ||
23 | { | ||
24 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
25 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | ||
26 | setBorder(null); | ||
27 | setFocusable(false); | ||
28 | setTabLayoutPolicy(1); | ||
29 | setOpaque(false); | ||
30 | setUI(new MyTabPanelUI1(this)); | ||
31 | addChangeListener(new ChangeListener() { | ||
32 | public void stateChanged(ChangeEvent e) | ||
33 | { | ||
34 | updateTabComponents(); | ||
35 | } | ||
36 | }); | ||
37 | } | ||
38 | |||
39 | |||
40 | @Override | ||
41 | public void addTab(String title, Component component) | ||
42 | { | ||
43 | super.addTab(title, component); | ||
44 | int index = getTabCount() - 1; | ||
45 | MyTabComponent1 tabComponent = new MyTabComponent1(title, this); | ||
46 | tabComponent.setTitle(title); | ||
47 | setTabComponentAt(index, tabComponent); | ||
48 | setToolTipTextAt(index, title); | ||
49 | updateTabComponents(); | ||
50 | } | ||
51 | |||
52 | public boolean isSelectTabComponents(String oId) | ||
53 | { | ||
54 | for(int i=0;i<getTabCount();i++) | ||
55 | { | ||
56 | Component c = getTabComponentAt(i); | ||
57 | if (c instanceof MyTabComponent) | ||
58 | { | ||
59 | if(((MyTabComponent) c).getOId().equals(oId)) | ||
60 | { | ||
61 | setSelectedIndex(i); | ||
62 | updateTabComponents(); | ||
63 | return true; | ||
64 | } | ||
65 | } | ||
66 | } | ||
67 | return false; | ||
68 | } | ||
69 | |||
70 | public int getPreferredTabHeight() | ||
71 | { | ||
72 | return preferredTabHeight; | ||
73 | } | ||
74 | |||
75 | private void updateTabComponents() | ||
76 | { | ||
77 | int selectedIndex = getSelectedIndex(); | ||
78 | for (int i = 0; i < getTabCount(); i++) | ||
79 | { | ||
80 | Component c = getTabComponentAt(i); | ||
81 | if (c instanceof MyTabComponent) | ||
82 | { | ||
83 | MyTabComponent component = (MyTabComponent)c; | ||
84 | boolean selected = selectedIndex == i; | ||
85 | component.updateSelection(selected); | ||
86 | } | ||
87 | } | ||
88 | |||
89 | } | ||
90 | |||
91 | public int getPreferredUnselectedTabWidth() | ||
92 | { | ||
93 | return preferredUnselectedTabWidth; | ||
94 | } | ||
95 | |||
96 | } | ||