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