diff options
Diffstat (limited to 'src/cppcheckplus/outlookpanel/MyOutlookBar.java')
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookBar.java | 393 |
1 files changed, 194 insertions, 199 deletions
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookBar.java b/src/cppcheckplus/outlookpanel/MyOutlookBar.java index d74345d..ce61489 100644 --- a/src/cppcheckplus/outlookpanel/MyOutlookBar.java +++ b/src/cppcheckplus/outlookpanel/MyOutlookBar.java | |||
@@ -1,14 +1,12 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | 1 | package cppcheckplus.outlookpanel; |
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.Component; | ||
7 | import java.awt.Dimension; | 6 | import java.awt.Dimension; |
8 | import java.awt.Graphics; | 7 | import java.awt.Graphics; |
9 | import java.awt.Graphics2D; | 8 | import java.awt.Graphics2D; |
10 | import java.awt.Image; | 9 | import java.awt.Image; |
11 | import java.awt.Insets; | ||
12 | import java.awt.TexturePaint; | 10 | import java.awt.TexturePaint; |
13 | import java.awt.event.MouseAdapter; | 11 | import java.awt.event.MouseAdapter; |
14 | import java.awt.event.MouseEvent; | 12 | import java.awt.event.MouseEvent; |
@@ -19,205 +17,202 @@ import javax.swing.ImageIcon; | |||
19 | import javax.swing.JComponent; | 17 | import javax.swing.JComponent; |
20 | import javax.swing.JLabel; | 18 | import javax.swing.JLabel; |
21 | import javax.swing.JPanel; | 19 | import javax.swing.JPanel; |
22 | import javax.swing.JScrollPane; | ||
23 | import javax.swing.border.Border; | 20 | import javax.swing.border.Border; |
24 | 21 | ||
25 | import cppcheckplus.control.MyContorlUtil; | ||
26 | 22 | ||
23 | public class MyOutlookBar extends JPanel { | ||
24 | private Image backgroundSelectedLeft; | ||
25 | private Image backgroundSelectedRight; | ||
26 | private Image backgroundImage; | ||
27 | private ImageIcon handlerIcon; | ||
28 | private ImageIcon handlerSelectedIcon; | ||
29 | private TexturePaint paint; | ||
30 | private TexturePaint selectedPaint; | ||
31 | private JLabel lbHandler; | ||
32 | private Border handlerBorder; | ||
33 | private Border handlerShrinkedBorder; | ||
34 | private JLabel lbIcon; | ||
35 | private JLabel lbTitle; | ||
36 | private boolean selected; | ||
37 | private Color titleColor; | ||
38 | private Color selectedTitleColor; | ||
39 | private MouseListener mouseListener; | ||
40 | |||
41 | private Icon icon = null; | ||
42 | private Icon selectedIcon = null; | ||
43 | private MyOutlookPanel outlookPanel; | ||
44 | private MyOutlookListPanel outlookListPanel; | ||
45 | |||
46 | public MyOutlookBar(MyOutlookPanel panel) { | ||
47 | super(); | ||
48 | backgroundSelectedLeft = MyContorlUtil.getImage( | ||
49 | "control/images/outlook_bar_background_selected_left.png"); | ||
50 | backgroundSelectedRight = MyContorlUtil.getImage( | ||
51 | "control/images/outlook_bar_background_selected_right.png"); | ||
52 | backgroundImage = | ||
53 | MyContorlUtil.getImage("control/images/outlook_bar_background.png"); | ||
54 | handlerIcon = MyContorlUtil.getImageIcon( | ||
55 | "control/images/outlook_bar_handler.png"); | ||
56 | handlerSelectedIcon = MyContorlUtil.getImageIcon( | ||
57 | "control/images/outlook_bar_handler_selected.png"); | ||
58 | paint = MyContorlUtil.createTexturePaint( | ||
59 | "control/images/outlook_bar_background.png"); | ||
60 | selectedPaint = MyContorlUtil.createTexturePaint( | ||
61 | "control/images/outlook_bar_background_selected.png"); | ||
62 | lbHandler = new JLabel(); | ||
63 | handlerBorder = BorderFactory.createEmptyBorder(0, 0, 0, 16); | ||
64 | handlerShrinkedBorder = BorderFactory.createEmptyBorder(0, 0, 0, 22); | ||
65 | lbIcon = new JLabel(); | ||
66 | lbTitle = new JLabel(); | ||
67 | selected = false; | ||
68 | titleColor = MyContorlUtil.OUTLOOK_TEXT_COLOR; | ||
69 | selectedTitleColor = Color.white; | ||
70 | mouseListener = new MouseAdapter() { | ||
71 | public void mouseReleased(MouseEvent e) { | ||
72 | if (((JComponent) e.getSource()).contains(e.getPoint())) { | ||
73 | changeStatus(); | ||
74 | } | ||
75 | } | ||
76 | }; | ||
77 | this.outlookPanel = panel; | ||
78 | |||
79 | init(); | ||
80 | } | ||
81 | |||
82 | public void setOutlookListPanel(MyOutlookListPanel listPanel) { | ||
83 | this.outlookListPanel = listPanel; | ||
84 | } | ||
85 | |||
86 | private void init() { | ||
87 | setLayout(new BorderLayout()); | ||
88 | lbHandler.setVerticalAlignment(0); | ||
89 | lbHandler.setIcon(handlerIcon); | ||
90 | lbHandler.setBorder(handlerBorder); | ||
91 | add(lbHandler, "East"); | ||
92 | lbIcon.setVerticalAlignment(0); | ||
93 | lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); | ||
94 | add(lbIcon, "West"); | ||
95 | lbTitle.setVerticalAlignment(0); | ||
96 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); | ||
97 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | ||
98 | lbTitle.setForeground(titleColor); | ||
99 | add(lbTitle, "Center"); | ||
100 | lbHandler.addMouseListener(mouseListener); | ||
101 | lbTitle.addMouseListener(mouseListener); | ||
102 | lbIcon.addMouseListener(mouseListener); | ||
103 | } | ||
104 | |||
105 | protected void paintComponent(Graphics g) { | ||
106 | super.paintComponent(g); | ||
107 | Graphics2D g2d = (Graphics2D) g; | ||
108 | if (isSelected()) { | ||
109 | g2d.setPaint(selectedPaint); | ||
110 | if (getSelectedIcon() != null) { | ||
111 | lbIcon.setIcon(getSelectedIcon()); | ||
112 | } else { | ||
113 | lbIcon.setIcon(getIcon()); | ||
114 | } | ||
115 | } else { | ||
116 | g2d.setPaint(paint); | ||
117 | lbIcon.setIcon(getIcon()); | ||
118 | } | ||
119 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
120 | if (isSelected()) { | ||
121 | g2d.drawImage(backgroundSelectedLeft, 0, 0, null); | ||
122 | g2d.drawImage(backgroundSelectedRight, getWidth() | ||
123 | - backgroundSelectedRight.getWidth(null), 0, null); | ||
124 | } | ||
125 | } | ||
126 | |||
127 | public Dimension getPreferredSize() { | ||
128 | return new Dimension(super.getPreferredSize().width, backgroundImage | ||
129 | .getHeight(null)); | ||
130 | } | ||
131 | |||
132 | public void changeStatus() { | ||
133 | setSelected(!isSelected()); | ||
134 | } | ||
135 | |||
136 | public boolean isSelected() { | ||
137 | return selected; | ||
138 | } | ||
139 | |||
140 | public void setSelected(boolean selected) { | ||
141 | if (selected != this.selected) { | ||
142 | if (!isSelected()) { | ||
143 | outlookPanel.closeAllBars(); | ||
144 | } | ||
145 | this.selected = selected; | ||
146 | if (selected) { | ||
147 | lbHandler.setIcon(handlerSelectedIcon); | ||
148 | lbTitle.setForeground(selectedTitleColor); | ||
149 | } else { | ||
150 | lbHandler.setIcon(handlerIcon); | ||
151 | lbTitle.setForeground(titleColor); | ||
152 | } | ||
153 | |||
154 | outlookPanel.updateLayoutConstraint(getContentComponent(), | ||
155 | selected); | ||
156 | outlookPanel.setAdditionalPaneVisible(!selected); | ||
157 | outlookPanel.revalidate(); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public Icon getIcon() { | ||
162 | return icon; | ||
163 | } | ||
164 | |||
165 | public void setIcon(Icon icon) { | ||
166 | this.icon = icon; | ||
167 | updateIcon(); | ||
168 | } | ||
169 | |||
170 | public Icon getSelectedIcon() { | ||
171 | return selectedIcon; | ||
172 | } | ||
173 | |||
174 | public void setSelectedIcon(Icon selectedIcon) { | ||
175 | this.selectedIcon = selectedIcon; | ||
176 | updateIcon(); | ||
177 | } | ||
178 | |||
179 | private void updateIcon() { | ||
180 | if (selected) { | ||
181 | lbIcon.setIcon(selectedIcon); | ||
182 | } else { | ||
183 | lbIcon.setIcon(icon); | ||
184 | } | ||
185 | } | ||
186 | |||
187 | public String getTitle() { | ||
188 | return lbTitle.getText(); | ||
189 | } | ||
190 | |||
191 | public void setTitle(String title) { | ||
192 | lbTitle.setText(title); | ||
193 | lbTitle.setToolTipText(title); | ||
194 | lbHandler.setToolTipText(title); | ||
195 | lbIcon.setToolTipText(title); | ||
196 | } | ||
197 | |||
198 | public MyOutlookListPanel getContentComponent() { | ||
199 | return outlookListPanel; | ||
200 | } | ||
201 | |||
202 | public MyOutlookList getList() { | ||
203 | return this.outlookListPanel.getOutlookList(); | ||
204 | } | ||
205 | |||
206 | public MyOutlookPanel getOutlookPanel() { | ||
207 | return this.outlookPanel; | ||
208 | } | ||
27 | 209 | ||
28 | public class MyOutlookBar extends JPanel | 210 | public void headerShrinkChanged(boolean headShrinked) { |
29 | { | 211 | if (headShrinked) { |
30 | private Image backgroundSelectedLeft; | 212 | lbHandler.setBorder(handlerShrinkedBorder); |
31 | private Image backgroundSelectedRight; | 213 | } else { |
32 | private Image backgroundImage; | 214 | lbHandler.setBorder(handlerBorder); |
33 | private ImageIcon handlerIcon; | 215 | } |
34 | private ImageIcon handlerSelectedIcon; | 216 | } |
35 | private TexturePaint paint; | ||
36 | private TexturePaint selectedPaint; | ||
37 | private JLabel lbHandler; | ||
38 | private Border handlerBorder; | ||
39 | private Border handlerShrinkedBorder; | ||
40 | private JLabel lbIcon; | ||
41 | private JLabel lbTitle; | ||
42 | private boolean selected; | ||
43 | private Color titleColor; | ||
44 | private Color selectedTitleColor; | ||
45 | private MouseListener mouseListener; | ||
46 | |||
47 | private Icon icon = null; | ||
48 | private Icon selectedIcon = null; | ||
49 | private MyOutlookPanel outlookPanel; | ||
50 | private MyOutlookListPanel outlookListPanel; | ||
51 | |||
52 | public MyOutlookBar(MyOutlookPanel panel) | ||
53 | { | ||
54 | super(); | ||
55 | backgroundSelectedLeft = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_left.png"); | ||
56 | backgroundSelectedRight = MyContorlUtil.getImage("control/images/outlook_bar_background_selected_right.png"); | ||
57 | backgroundImage = MyContorlUtil.getImage("control/images/outlook_bar_background.png"); | ||
58 | handlerIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler.png"); | ||
59 | handlerSelectedIcon = MyContorlUtil.getImageIcon("control/images/outlook_bar_handler_selected.png"); | ||
60 | paint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background.png"); | ||
61 | selectedPaint = MyContorlUtil.createTexturePaint("control/images/outlook_bar_background_selected.png"); | ||
62 | lbHandler = new JLabel(); | ||
63 | handlerBorder = BorderFactory.createEmptyBorder(0, 0, 0, 16); | ||
64 | handlerShrinkedBorder = BorderFactory.createEmptyBorder(0, 0, 0, 22); | ||
65 | lbIcon = new JLabel(); | ||
66 | lbTitle = new JLabel(); | ||
67 | selected = false; | ||
68 | titleColor = MyContorlUtil.OUTLOOK_TEXT_COLOR; | ||
69 | selectedTitleColor = Color.white; | ||
70 | mouseListener = new MouseAdapter() | ||
71 | { | ||
72 | public void mouseReleased(MouseEvent e) | ||
73 | { | ||
74 | if (((JComponent) e.getSource()).contains(e.getPoint())) | ||
75 | changeStatus(); | ||
76 | } | ||
77 | }; | ||
78 | this.outlookPanel = panel; | ||
79 | |||
80 | init(); | ||
81 | } | ||
82 | public void setOutlookListPanel(MyOutlookListPanel listPanel) | ||
83 | { | ||
84 | this.outlookListPanel=listPanel; | ||
85 | } | ||
86 | private void init() | ||
87 | { | ||
88 | setLayout(new BorderLayout()); | ||
89 | lbHandler.setVerticalAlignment(0); | ||
90 | lbHandler.setIcon(handlerIcon); | ||
91 | lbHandler.setBorder(handlerBorder); | ||
92 | add(lbHandler, "East"); | ||
93 | lbIcon.setVerticalAlignment(0); | ||
94 | lbIcon.setBorder(BorderFactory.createEmptyBorder(0, 16, 0, 0)); | ||
95 | add(lbIcon, "West"); | ||
96 | lbTitle.setVerticalAlignment(0); | ||
97 | lbTitle.setBorder(BorderFactory.createEmptyBorder(0, 8, 0, 0)); | ||
98 | lbTitle.setFont(MyContorlUtil.FONT_14_BOLD); | ||
99 | lbTitle.setForeground(titleColor); | ||
100 | add(lbTitle, "Center"); | ||
101 | lbHandler.addMouseListener(mouseListener); | ||
102 | lbTitle.addMouseListener(mouseListener); | ||
103 | lbIcon.addMouseListener(mouseListener); | ||
104 | } | ||
105 | protected void paintComponent(Graphics g) | ||
106 | { | ||
107 | super.paintComponent(g); | ||
108 | Graphics2D g2d = (Graphics2D) g; | ||
109 | if (isSelected()) | ||
110 | { | ||
111 | g2d.setPaint(selectedPaint); | ||
112 | if (getSelectedIcon() != null) | ||
113 | lbIcon.setIcon(getSelectedIcon()); | ||
114 | else | ||
115 | lbIcon.setIcon(getIcon()); | ||
116 | } | ||
117 | else | ||
118 | { | ||
119 | g2d.setPaint(paint); | ||
120 | lbIcon.setIcon(getIcon()); | ||
121 | } | ||
122 | g2d.fillRect(0, 0, getWidth(), getHeight()); | ||
123 | if (isSelected()) | ||
124 | { | ||
125 | g2d.drawImage(backgroundSelectedLeft, 0, 0, null); | ||
126 | g2d.drawImage(backgroundSelectedRight, getWidth() | ||
127 | - backgroundSelectedRight.getWidth(null), 0, null); | ||
128 | } | ||
129 | } | ||
130 | public Dimension getPreferredSize() | ||
131 | { | ||
132 | return new Dimension(super.getPreferredSize().width, backgroundImage | ||
133 | .getHeight(null)); | ||
134 | } | ||
135 | public void setSelected(boolean selected) | ||
136 | { | ||
137 | if (selected != this.selected) | ||
138 | { | ||
139 | if (!isSelected()) | ||
140 | outlookPanel.closeAllBars(); | ||
141 | this.selected = selected; | ||
142 | if (selected) | ||
143 | { | ||
144 | lbHandler.setIcon(handlerSelectedIcon); | ||
145 | lbTitle.setForeground(selectedTitleColor); | ||
146 | } | ||
147 | else | ||
148 | { | ||
149 | lbHandler.setIcon(handlerIcon); | ||
150 | lbTitle.setForeground(titleColor); | ||
151 | } | ||
152 | |||
153 | outlookPanel.updateLayoutConstraint(getContentComponent(), selected); | ||
154 | outlookPanel.setAdditionalPaneVisible(!selected); | ||
155 | outlookPanel.revalidate(); | ||
156 | } | ||
157 | } | ||
158 | public void changeStatus() | ||
159 | { | ||
160 | setSelected(!isSelected()); | ||
161 | } | ||
162 | public boolean isSelected() | ||
163 | { | ||
164 | return selected; | ||
165 | } | ||
166 | public Icon getIcon() | ||
167 | { | ||
168 | return icon; | ||
169 | } | ||
170 | public void setIcon(Icon icon) | ||
171 | { | ||
172 | this.icon = icon; | ||
173 | updateIcon(); | ||
174 | } | ||
175 | public Icon getSelectedIcon() | ||
176 | { | ||
177 | return selectedIcon; | ||
178 | } | ||
179 | public void setSelectedIcon(Icon selectedIcon) | ||
180 | { | ||
181 | this.selectedIcon = selectedIcon; | ||
182 | updateIcon(); | ||
183 | } | ||
184 | private void updateIcon() | ||
185 | { | ||
186 | if (selected) | ||
187 | lbIcon.setIcon(selectedIcon); | ||
188 | else | ||
189 | lbIcon.setIcon(icon); | ||
190 | } | ||
191 | public void setTitle(String title) | ||
192 | { | ||
193 | lbTitle.setText(title); | ||
194 | lbTitle.setToolTipText(title); | ||
195 | lbHandler.setToolTipText(title); | ||
196 | lbIcon.setToolTipText(title); | ||
197 | } | ||
198 | public String getTitle() | ||
199 | { | ||
200 | return lbTitle.getText(); | ||
201 | } | ||
202 | |||
203 | public MyOutlookListPanel getContentComponent() | ||
204 | { | ||
205 | return outlookListPanel; | ||
206 | } | ||
207 | public MyOutlookList getList() | ||
208 | { | ||
209 | return this.outlookListPanel.getOutlookList(); | ||
210 | } | ||
211 | public MyOutlookPanel getOutlookPanel() | ||
212 | { | ||
213 | return this.outlookPanel; | ||
214 | } | ||
215 | public void headerShrinkChanged(boolean headShrinked) | ||
216 | { | ||
217 | if (headShrinked) | ||
218 | lbHandler.setBorder(handlerShrinkedBorder); | ||
219 | else | ||
220 | lbHandler.setBorder(handlerBorder); | ||
221 | } | ||
222 | 217 | ||
223 | } | 218 | } |