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