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