diff options
Diffstat (limited to 'src/cppcheckplus/tab/MyTabComponent1.java')
-rw-r--r-- | src/cppcheckplus/tab/MyTabComponent1.java | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/src/cppcheckplus/tab/MyTabComponent1.java b/src/cppcheckplus/tab/MyTabComponent1.java new file mode 100644 index 0000000..9901441 --- /dev/null +++ b/src/cppcheckplus/tab/MyTabComponent1.java | |||
@@ -0,0 +1,136 @@ | |||
1 | package cppcheckplus.tab; | ||
2 | |||
3 | import java.awt.BorderLayout; | ||
4 | import java.awt.Color; | ||
5 | import java.awt.Dimension; | ||
6 | import java.awt.Graphics; | ||
7 | import java.awt.Graphics2D; | ||
8 | import java.awt.Image; | ||
9 | import java.awt.TexturePaint; | ||
10 | |||
11 | import javax.swing.BorderFactory; | ||
12 | import javax.swing.ImageIcon; | ||
13 | import javax.swing.JLabel; | ||
14 | import javax.swing.JPanel; | ||
15 | import javax.swing.border.Border; | ||
16 | |||
17 | import cppcheckplus.control.MyContorlUtil; | ||
18 | |||
19 | public class MyTabComponent1 extends JPanel{ | ||
20 | |||
21 | private String backgroundUnselectedImageURL; | ||
22 | private TexturePaint selectedPaint; | ||
23 | private TexturePaint unselectedPaint; | ||
24 | private ImageIcon pressedIcon; | ||
25 | private Image unselectedLeftImage; | ||
26 | private Image unselectedRightImage; | ||
27 | private Image selectedLeftImage; | ||
28 | private Image selectedRightImage; | ||
29 | private JLabel lbTitle; | ||
30 | private MyTabPanel1 tab; | ||
31 | private Color selectedTitleColor; | ||
32 | private Color unselectedTitleColor; | ||
33 | private Border border; | ||
34 | private String oId; | ||
35 | |||
36 | public MyTabComponent1(String oId,MyTabPanel1 tab) | ||
37 | { | ||
38 | super(); | ||
39 | this.oId = oId; | ||
40 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_background.png"); | ||
41 | unselectedPaint = MyContorlUtil.createTexturePaint("control/images/tab_header_unselected_background.png"); | ||
42 | unselectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_left.png"); | ||
43 | unselectedRightImage = MyContorlUtil.getImage("control/images/tab_header_unselected_background_right.png"); | ||
44 | selectedLeftImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_left.png"); | ||
45 | selectedRightImage = MyContorlUtil.getImage("control/images/tab_header_selected_background_right.png"); | ||
46 | lbTitle = new JLabel(); | ||
47 | this.tab = null; | ||
48 | selectedTitleColor = new Color(120, 120, 125); | ||
49 | unselectedTitleColor = Color.white; | ||
50 | border = BorderFactory.createEmptyBorder(0, 5, 0, 5); | ||
51 | this.tab = tab; | ||
52 | init(); | ||
53 | } | ||
54 | |||
55 | private void init() | ||
56 | { | ||
57 | lbTitle.setOpaque(false); | ||
58 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 3)); | ||
59 | lbTitle.setVerticalAlignment(0); | ||
60 | lbTitle.setFont(MyContorlUtil.FONT_12_BOLD); | ||
61 | setLayout(new BorderLayout()); | ||
62 | add(lbTitle, "Center"); | ||
63 | setBorder(border); | ||
64 | setOpaque(false); | ||
65 | } | ||
66 | |||
67 | public void paintComponent(Graphics g) | ||
68 | { | ||
69 | Graphics2D g2d = (Graphics2D)g; | ||
70 | if (isTabSelected()) | ||
71 | { | ||
72 | g2d.drawImage(selectedLeftImage, 0, 0, null); | ||
73 | g2d.setPaint(selectedPaint); | ||
74 | int x = selectedLeftImage.getWidth(null); | ||
75 | int y = 0; | ||
76 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
77 | int height = getHeight(); | ||
78 | g2d.fillRect(x, y, width, height); | ||
79 | g2d.drawImage(selectedRightImage, x + width, 0, null); | ||
80 | } else | ||
81 | { | ||
82 | g2d.drawImage(unselectedLeftImage, 0, 0, null); | ||
83 | g2d.setPaint(unselectedPaint); | ||
84 | int x = unselectedLeftImage.getWidth(null); | ||
85 | int y = 0; | ||
86 | int width = getWidth() - x - selectedRightImage.getWidth(null); | ||
87 | int height = getHeight(); | ||
88 | g2d.fillRect(x, y, width, height); | ||
89 | g2d.drawImage(unselectedRightImage, x + width, 0, null); | ||
90 | g2d.setColor(MyContorlUtil.TAB_BOTTOM_LINE_COLOR); | ||
91 | int lineY = getHeight() - 1; | ||
92 | g2d.drawLine(0, lineY, getWidth(), lineY); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | public Dimension getPreferredSize() | ||
97 | { | ||
98 | int width = super.getPreferredSize().width; | ||
99 | if (!isTabSelected()) | ||
100 | width = Math.min(width, tab.getPreferredUnselectedTabWidth()); | ||
101 | int height = tab.getPreferredTabHeight(); | ||
102 | return new Dimension(width, height); | ||
103 | } | ||
104 | |||
105 | public boolean isTabSelected() | ||
106 | { | ||
107 | int index = tab.indexOfTabComponent(this); | ||
108 | int selectedIndex = tab.getSelectedIndex(); | ||
109 | return selectedIndex == index; | ||
110 | } | ||
111 | |||
112 | public void setTitle(String title) | ||
113 | { | ||
114 | lbTitle.setText(title); | ||
115 | } | ||
116 | |||
117 | public void updateSelection(boolean selected) | ||
118 | { | ||
119 | if (selected) | ||
120 | lbTitle.setForeground(selectedTitleColor); | ||
121 | else | ||
122 | lbTitle.setForeground(unselectedTitleColor); | ||
123 | } | ||
124 | |||
125 | |||
126 | |||
127 | public void setOId(String oId) | ||
128 | { | ||
129 | this.oId = oId; | ||
130 | } | ||
131 | |||
132 | public String getOId() | ||
133 | { | ||
134 | return oId; | ||
135 | } | ||
136 | } | ||