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