diff options
Diffstat (limited to 'src/cppcheckplus/outlookpanel/MyOutlookBar.java')
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookBar.java | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookBar.java b/src/cppcheckplus/outlookpanel/MyOutlookBar.java new file mode 100644 index 0000000..d74345d --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookBar.java | |||
@@ -0,0 +1,223 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.BorderLayout; | ||
5 | import java.awt.Color; | ||
6 | import java.awt.Component; | ||
7 | import java.awt.Dimension; | ||
8 | import java.awt.Graphics; | ||
9 | import java.awt.Graphics2D; | ||
10 | import java.awt.Image; | ||
11 | import java.awt.Insets; | ||
12 | import java.awt.TexturePaint; | ||
13 | import java.awt.event.MouseAdapter; | ||
14 | import java.awt.event.MouseEvent; | ||
15 | import java.awt.event.MouseListener; | ||
16 | import javax.swing.BorderFactory; | ||
17 | import javax.swing.Icon; | ||
18 | import javax.swing.ImageIcon; | ||
19 | import javax.swing.JComponent; | ||
20 | import javax.swing.JLabel; | ||
21 | import javax.swing.JPanel; | ||
22 | import javax.swing.JScrollPane; | ||
23 | import javax.swing.border.Border; | ||
24 | |||
25 | import cppcheckplus.control.MyContorlUtil; | ||
26 | |||
27 | |||
28 | public class MyOutlookBar extends JPanel | ||
29 | { | ||
30 | private Image backgroundSelectedLeft; | ||
31 | private Image backgroundSelectedRight; | ||
32 | private Image backgroundImage; | ||
33 | private ImageIcon handlerIcon; | ||
34 | private ImageIcon handlerSelectedIcon; | ||
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 | |||
223 | } | ||