diff options
Diffstat (limited to 'src/cppcheckplus/tab/MyTabComponent.java')
-rw-r--r-- | src/cppcheckplus/tab/MyTabComponent.java | 299 |
1 files changed, 146 insertions, 153 deletions
diff --git a/src/cppcheckplus/tab/MyTabComponent.java b/src/cppcheckplus/tab/MyTabComponent.java index 5a1d2a6..4ed4b1d 100644 --- a/src/cppcheckplus/tab/MyTabComponent.java +++ b/src/cppcheckplus/tab/MyTabComponent.java | |||
@@ -1,6 +1,6 @@ | |||
1 | |||
2 | package cppcheckplus.tab; | 1 | package cppcheckplus.tab; |
3 | 2 | ||
3 | import cppcheckplus.control.MyContorlUtil; | ||
4 | import java.awt.BorderLayout; | 4 | import java.awt.BorderLayout; |
5 | import java.awt.Color; | 5 | import java.awt.Color; |
6 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
@@ -17,157 +17,150 @@ import javax.swing.JLabel; | |||
17 | import javax.swing.JPanel; | 17 | import javax.swing.JPanel; |
18 | import javax.swing.border.Border; | 18 | import javax.swing.border.Border; |
19 | 19 | ||
20 | import cppcheckplus.control.MyContorlUtil; | ||
21 | |||
22 | 20 | ||
23 | public class MyTabComponent extends JPanel | 21 | public class MyTabComponent extends JPanel { |
24 | { | 22 | |
25 | 23 | private String backgroundUnselectedImageURL; | |
26 | private String backgroundUnselectedImageURL; | 24 | private TexturePaint selectedPaint; |
27 | private TexturePaint selectedPaint; | 25 | private TexturePaint unselectedPaint; |
28 | private TexturePaint unselectedPaint; | 26 | private ImageIcon icon; |
29 | private ImageIcon icon; | 27 | private ImageIcon pressedIcon; |
30 | private ImageIcon pressedIcon; | 28 | private Image unselectedLeftImage; |
31 | private Image unselectedLeftImage; | 29 | private Image unselectedRightImage; |
32 | private Image unselectedRightImage; | 30 | private Image selectedLeftImage; |
33 | private Image selectedLeftImage; | 31 | private Image selectedRightImage; |
34 | private Image selectedRightImage; | 32 | private JButton btnClose; |
35 | private JButton btnClose; | 33 | private JLabel lbTitle; |
36 | private JLabel lbTitle; | 34 | private MyTabPanel tab; |
37 | private MyTabPanel tab; | 35 | private Color selectedTitleColor; |
38 | private Color selectedTitleColor; | 36 | private Color unselectedTitleColor; |
39 | private Color unselectedTitleColor; | 37 | private Border border; |
40 | private Border border; | 38 | private String oId; |
41 | private String oId; | 39 | |
42 | 40 | public MyTabComponent(String oId, MyTabPanel tab) { | |
43 | public MyTabComponent(String oId,MyTabPanel tab) | 41 | super(); |
44 | { | 42 | this.oId = oId; |
45 | super(); | 43 | selectedPaint = MyContorlUtil.createTexturePaint( |
46 | this.oId = oId; | 44 | "control/images/tab_header_background.png"); |
47 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); | 45 | unselectedPaint = MyContorlUtil.createTexturePaint( |
48 | unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); | 46 | "control/images/tab_header_unselected_background.png"); |
49 | icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); | 47 | icon = MyContorlUtil.getImageIcon("control/images/tab_close.png"); |
50 | pressedIcon = MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); | 48 | pressedIcon = |
51 | unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); | 49 | MyContorlUtil.getImageIcon("control/images/tab_close_pressed.png"); |
52 | unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); | 50 | unselectedLeftImage = MyContorlUtil.getImage( |
53 | selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); | 51 | "control/images/tab_header_unselected_background_left.png"); |
54 | selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); | 52 | unselectedRightImage = MyContorlUtil.getImage( |
55 | btnClose = new JButton(); | 53 | "control/images/tab_header_unselected_background_right.png"); |
56 | lbTitle = new JLabel(); | 54 | selectedLeftImage = MyContorlUtil.getImage( |
57 | this.tab = null; | 55 | "control/images/tab_header_selected_background_left.png"); |
58 | selectedTitleColor = new Color(120, 120, 125); | 56 | selectedRightImage = MyContorlUtil.getImage( |
59 | unselectedTitleColor = Color.white; | 57 | "control/images/tab_header_selected_background_right.png"); |
60 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); | 58 | btnClose = new JButton(); |
61 | this.tab = tab; | 59 | lbTitle = new JLabel(); |
62 | init(); | 60 | this.tab = null; |
63 | } | 61 | selectedTitleColor = new Color(120, 120, 125); |
64 | 62 | unselectedTitleColor = Color.white; | |
65 | private void init() | 63 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); |
66 | { | 64 | this.tab = tab; |
67 | btnClose.setIcon(icon); | 65 | init(); |
68 | btnClose.setPressedIcon(pressedIcon); | 66 | } |
69 | btnClose.setToolTipText("Close this tab"); | 67 | |
70 | btnClose.setMargin(MyContorlUtil.ZERO_INSETS); | 68 | private void init() { |
71 | btnClose.setFocusPainted(false); | 69 | btnClose.setIcon(icon); |
72 | btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); | 70 | btnClose.setPressedIcon(pressedIcon); |
73 | btnClose.setContentAreaFilled(false); | 71 | btnClose.setToolTipText("Close this tab"); |
74 | btnClose.addActionListener(new ActionListener() { | 72 | btnClose.setMargin(MyContorlUtil.ZERO_INSETS); |
75 | 73 | btnClose.setFocusPainted(false); | |
76 | public void actionPerformed(ActionEvent e) | 74 | btnClose.setBorder(BorderFactory.createEmptyBorder(0, 3, 1, 3)); |
77 | { | 75 | btnClose.setContentAreaFilled(false); |
78 | closeTab(); | 76 | btnClose.addActionListener(new ActionListener() { |
79 | } | 77 | |
80 | 78 | public void actionPerformed(ActionEvent e) { | |
81 | }); | 79 | closeTab(); |
82 | lbTitle.setOpaque(false); | 80 | } |
83 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | 81 | |
84 | lbTitle.setVerticalAlignment(0); | 82 | }); |
85 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | 83 | lbTitle.setOpaque(false); |
86 | setLayout(new BorderLayout()); | 84 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); |
87 | add(btnClose, "East"); | 85 | lbTitle.setVerticalAlignment(0); |
88 | add(lbTitle, "Center"); | 86 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); |
89 | setBorder(border); | 87 | setLayout(new BorderLayout()); |
90 | setOpaque(false); | 88 | add(btnClose, "East"); |
91 | } | 89 | add(lbTitle, "Center"); |
92 | 90 | setBorder(border); | |
93 | public void paintComponent(Graphics g) | 91 | setOpaque(false); |
94 | { | 92 | } |
95 | Graphics2D g2d = (Graphics2D)g; | 93 | |
96 | if (isTabSelected()) | 94 | public void paintComponent(Graphics g) { |
97 | { | 95 | Graphics2D g2d = (Graphics2D) g; |
98 | g2d.drawImage(selectedLeftImage, 0, 0, null); | 96 | if (isTabSelected()) { |
99 | g2d.setPaint(selectedPaint); | 97 | g2d.drawImage(selectedLeftImage, 0, 0, null); |
100 | int x = selectedLeftImage.getWidth(null); | 98 | g2d.setPaint(selectedPaint); |
101 | int y = 0; | 99 | int x = selectedLeftImage.getWidth(null); |
102 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 100 | int y = 0; |
103 | int height = getHeight(); | 101 | int width = getWidth() - x - selectedRightImage.getWidth(null); |
104 | g2d.fillRect(x, y, width, height); | 102 | int height = getHeight(); |
105 | g2d.drawImage(selectedRightImage, x + width, 0, null); | 103 | g2d.fillRect(x, y, width, height); |
106 | } else | 104 | g2d.drawImage(selectedRightImage, x + width, 0, null); |
107 | { | 105 | } else { |
108 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | 106 | g2d.drawImage(unselectedLeftImage, 0, 0, null); |
109 | g2d.setPaint(unselectedPaint); | 107 | g2d.setPaint(unselectedPaint); |
110 | int x = unselectedLeftImage.getWidth(null); | 108 | int x = unselectedLeftImage.getWidth(null); |
111 | int y = 0; | 109 | int y = 0; |
112 | int width = getWidth() - x - selectedRightImage.getWidth(null); | 110 | int width = getWidth() - x - selectedRightImage.getWidth(null); |
113 | int height = getHeight(); | 111 | int height = getHeight(); |
114 | g2d.fillRect(x, y, width, height); | 112 | g2d.fillRect(x, y, width, height); |
115 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | 113 | g2d.drawImage(unselectedRightImage, x + width, 0, null); |
116 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | 114 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); |
117 | int lineY = getHeight() - 1; | 115 | int lineY = getHeight() - 1; |
118 | g2d.drawLine(0, lineY, getWidth(), lineY); | 116 | g2d.drawLine(0, lineY, getWidth(), lineY); |
119 | } | 117 | } |
120 | } | 118 | } |
121 | 119 | ||
122 | public Dimension getPreferredSize() | 120 | public Dimension getPreferredSize() { |
123 | { | 121 | int width = super.getPreferredSize().width; |
124 | int width = super.getPreferredSize().width; | 122 | if (!isTabSelected()) { |
125 | if (!isTabSelected()) | 123 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); |
126 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | 124 | } |
127 | int height = tab.getPreferredTabHeight(); | 125 | int height = tab.getPreferredTabHeight(); |
128 | return new Dimension(width, height); | 126 | return new Dimension(width, height); |
129 | } | 127 | } |
130 | 128 | ||
131 | public boolean isTabSelected() | 129 | public boolean isTabSelected() { |
132 | { | 130 | int index = tab.indexOfTabComponent(this); |
133 | int index = tab.indexOfTabComponent(this); | 131 | int selectedIndex = tab.getSelectedIndex(); |
134 | int selectedIndex = tab.getSelectedIndex(); | 132 | return selectedIndex == index; |
135 | return selectedIndex == index; | 133 | } |
136 | } | 134 | |
137 | 135 | public void setTitle(String title) { | |
138 | public void setTitle(String title) | 136 | lbTitle.setText(title); |
139 | { | 137 | } |
140 | lbTitle.setText(title); | 138 | |
141 | } | 139 | public void updateSelection(boolean selected) { |
142 | 140 | if (selected) { | |
143 | public void updateSelection(boolean selected) | 141 | lbTitle.setForeground(selectedTitleColor); |
144 | { | 142 | } else { |
145 | if (selected) | 143 | lbTitle.setForeground(unselectedTitleColor); |
146 | lbTitle.setForeground(selectedTitleColor); | 144 | } |
147 | else | 145 | btnClose.setVisible(selected); |
148 | lbTitle.setForeground(unselectedTitleColor); | 146 | } |
149 | btnClose.setVisible(selected); | 147 | |
150 | } | 148 | private void closeTab() { |
151 | 149 | int index = tab.indexOfTabComponent(this); | |
152 | private void closeTab() | 150 | tab.removeTabAt(index); |
153 | { | 151 | } |
154 | int index = tab.indexOfTabComponent(this); | 152 | |
155 | tab.removeTabAt(index); | 153 | /** |
156 | } | 154 | * @return the oId |
157 | 155 | */ | |
158 | /** | 156 | public String getOId() { |
159 | * @param oId the oId to set | 157 | return oId; |
160 | */ | 158 | } |
161 | public void setOId(String oId) | 159 | |
162 | { | 160 | /** |
163 | this.oId = oId; | 161 | * @param oId the oId to set |
164 | } | 162 | */ |
165 | 163 | public void setOId(String oId) { | |
166 | /** | 164 | this.oId = oId; |
167 | * @return the oId | 165 | } |
168 | */ | ||
169 | public String getOId() | ||
170 | { | ||
171 | return oId; | ||
172 | } | ||
173 | } | 166 | } |