diff options
Diffstat (limited to 'src/cppcheckplus/outlookpanel')
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookBar.java | 223 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookHeader.java | 109 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookList.java | 31 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookListPanel.java | 61 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java | 54 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookPanel.java | 222 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java | 51 | ||||
-rw-r--r-- | src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java | 33 |
8 files changed, 784 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 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookHeader.java b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java new file mode 100644 index 0000000..c7ba589 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookHeader.java | |||
@@ -0,0 +1,109 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.FlowLayout; | ||
5 | import java.awt.LayoutManager; | ||
6 | import java.awt.event.ActionEvent; | ||
7 | import java.awt.event.ActionListener; | ||
8 | import javax.swing.BorderFactory; | ||
9 | import javax.swing.Icon; | ||
10 | import javax.swing.ImageIcon; | ||
11 | import javax.swing.JComponent; | ||
12 | import javax.swing.JLabel; | ||
13 | import javax.swing.JPanel; | ||
14 | import javax.swing.border.Border; | ||
15 | |||
16 | import cppcheckplus.control.MyContorlUtil; | ||
17 | import cppcheckplus.control.MyHeader; | ||
18 | import cppcheckplus.control.MyListSplitListener; | ||
19 | import cppcheckplus.toolbar.MyToolBarButton; | ||
20 | |||
21 | public class MyOutlookHeader extends MyHeader | ||
22 | { | ||
23 | private LayoutManager toolbarLayout; | ||
24 | private JPanel toolbar; | ||
25 | private ImageIcon separatorIcon; | ||
26 | |||
27 | public MyOutlookHeader(ActionListener listener) | ||
28 | { | ||
29 | toolbarLayout = new FlowLayout(FlowLayout.LEFT,2,1); | ||
30 | toolbar = new JPanel(toolbarLayout); | ||
31 | separatorIcon = MyContorlUtil.getImageIcon("control/images/toolbar_separator.png"); | ||
32 | init(); | ||
33 | //加载工具栏 | ||
34 | MyContorlUtil.loadOutlookToolBar("cppcheckplus/control/toolbar.xml", this,listener); | ||
35 | } | ||
36 | |||
37 | private void init() | ||
38 | { | ||
39 | toolbar.setOpaque(false); | ||
40 | toolbar.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); | ||
41 | add(toolbar, "Center"); | ||
42 | } | ||
43 | //在Header上添加工具按钮 | ||
44 | public MyToolBarButton addButton(Icon icon, String tooltip, ActionListener action, String command) | ||
45 | { | ||
46 | MyToolBarButton button = new MyToolBarButton(); | ||
47 | button.setIcon(icon); | ||
48 | button.setToolTipText(tooltip); | ||
49 | if (action != null) | ||
50 | button.addActionListener(action); | ||
51 | button.setActionCommand(command); | ||
52 | toolbar.add(button); | ||
53 | return button; | ||
54 | } | ||
55 | |||
56 | public void addSeparator() | ||
57 | { | ||
58 | toolbar.add(new JLabel(separatorIcon)); | ||
59 | } | ||
60 | |||
61 | protected Object getResizeHandlerLayoutConstraint() | ||
62 | { | ||
63 | return "East"; | ||
64 | } | ||
65 | |||
66 | protected Object getShrinkHandlerLayoutConstraint() | ||
67 | { | ||
68 | return "West"; | ||
69 | } | ||
70 | |||
71 | protected MyListSplitListener createSplitListener() | ||
72 | { | ||
73 | return new MyOutlookSplitListener(this); | ||
74 | } | ||
75 | |||
76 | protected Border createBorder() | ||
77 | { | ||
78 | return BorderFactory.createEmptyBorder(4, 0, 0, 7); | ||
79 | } | ||
80 | |||
81 | protected ImageIcon getShrinkIcon(boolean shrinked) | ||
82 | { | ||
83 | if (shrinked) | ||
84 | return RIGHT_ARROW_ICON; | ||
85 | else | ||
86 | return LEFT_ARROW_ICON; | ||
87 | } | ||
88 | |||
89 | protected JComponent getCenterComponent() | ||
90 | { | ||
91 | return null; | ||
92 | } | ||
93 | |||
94 | public void setShrink(boolean shrinked) | ||
95 | { | ||
96 | super.setShrink(shrinked); | ||
97 | toolbar.setVisible(!shrinked); | ||
98 | } | ||
99 | |||
100 | protected int getShrinkedWidth() | ||
101 | { | ||
102 | return 37; | ||
103 | } | ||
104 | |||
105 | public JPanel getToolBar() | ||
106 | { | ||
107 | return toolbar; | ||
108 | } | ||
109 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookList.java b/src/cppcheckplus/outlookpanel/MyOutlookList.java new file mode 100644 index 0000000..d5c04d5 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookList.java | |||
@@ -0,0 +1,31 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import javax.swing.JList; | ||
5 | |||
6 | import cppcheckplus.control.MyContorlUtil; | ||
7 | |||
8 | public class MyOutlookList extends JList | ||
9 | { | ||
10 | //通过MyOutlookBar获得MyOutlookPanel是否sh | ||
11 | private MyOutlookBar bar; | ||
12 | public MyOutlookList(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | ||
13 | { | ||
14 | this.bar = bar; | ||
15 | setListData(listItems); | ||
16 | init(); | ||
17 | } | ||
18 | |||
19 | private void init() | ||
20 | { | ||
21 | setCellRenderer(new MyOutlookListRenderer()); | ||
22 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
23 | setForeground(MyContorlUtil.OUTLOOK_TEXT_COLOR); | ||
24 | setSelectionMode(0); | ||
25 | } | ||
26 | |||
27 | public MyOutlookBar getOutlookBar() | ||
28 | { | ||
29 | return this.bar; | ||
30 | } | ||
31 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java new file mode 100644 index 0000000..2b43866 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookListPanel.java | |||
@@ -0,0 +1,61 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | |||
5 | import java.awt.BorderLayout; | ||
6 | import java.awt.Color; | ||
7 | import java.awt.Component; | ||
8 | import java.awt.Dimension; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Insets; | ||
11 | import javax.swing.JPanel; | ||
12 | import javax.swing.JScrollPane; | ||
13 | import javax.swing.ScrollPaneConstants; | ||
14 | import javax.swing.border.Border; | ||
15 | |||
16 | |||
17 | public class MyOutlookListPanel extends JPanel | ||
18 | { | ||
19 | private MyOutlookList list; | ||
20 | |||
21 | //MyOutlookBar对应的MyOutlookList封装的Panel | ||
22 | private JScrollPane listScrollPane; | ||
23 | private Border scrollBorder; | ||
24 | |||
25 | public MyOutlookListPanel(MyOutlookList list) | ||
26 | { | ||
27 | this.list = list; | ||
28 | listScrollPane = new JScrollPane(list); | ||
29 | // listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); | ||
30 | listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); | ||
31 | scrollBorder = new Border() | ||
32 | { | ||
33 | public void paintBorder(Component c, Graphics g, int x, int y, | ||
34 | int width, int height) | ||
35 | { | ||
36 | g.setColor(new Color(233, 223, 207)); | ||
37 | g.drawLine(0, height, x, height); | ||
38 | } | ||
39 | public Insets getBorderInsets(Component c) | ||
40 | { | ||
41 | return new Insets(0, 0, 1, 0); | ||
42 | } | ||
43 | public boolean isBorderOpaque() | ||
44 | { | ||
45 | return true; | ||
46 | } | ||
47 | }; | ||
48 | init(); | ||
49 | } | ||
50 | private void init() | ||
51 | { | ||
52 | listScrollPane.setMinimumSize(new Dimension(0, 0)); | ||
53 | listScrollPane.setBorder(scrollBorder); | ||
54 | this.setLayout(new BorderLayout()); | ||
55 | add(listScrollPane,BorderLayout.CENTER); | ||
56 | } | ||
57 | public MyOutlookList getOutlookList() | ||
58 | { | ||
59 | return list; | ||
60 | } | ||
61 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java new file mode 100644 index 0000000..9c71301 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookListRenderer.java | |||
@@ -0,0 +1,54 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.Color; | ||
5 | import java.awt.Component; | ||
6 | import javax.swing.BorderFactory; | ||
7 | import javax.swing.DefaultListCellRenderer; | ||
8 | import javax.swing.JList; | ||
9 | import javax.swing.SwingConstants; | ||
10 | import javax.swing.border.Border; | ||
11 | |||
12 | import cppcheckplus.control.MyContorlUtil; | ||
13 | |||
14 | public class MyOutlookListRenderer extends DefaultListCellRenderer | ||
15 | { | ||
16 | private Color selectedColor; | ||
17 | private Border normalBorder; | ||
18 | private Border shrinkedBorder; | ||
19 | |||
20 | public MyOutlookListRenderer() | ||
21 | { | ||
22 | super(); | ||
23 | selectedColor = new Color(253, 192, 47); | ||
24 | normalBorder = BorderFactory.createEmptyBorder(3, 19, 3, 2); | ||
25 | shrinkedBorder = BorderFactory.createEmptyBorder(2, 7, 1, 2); | ||
26 | } | ||
27 | @Override | ||
28 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) | ||
29 | { | ||
30 | super.getListCellRendererComponent(list, value, index, isSelected,cellHasFocus); | ||
31 | |||
32 | MyOutlookPanelListItem listItem = (MyOutlookPanelListItem)value; | ||
33 | MyOutlookList outlookList = (MyOutlookList)list; | ||
34 | setToolTipText(listItem.getToolTip()); | ||
35 | setIcon(listItem.getIcon()); | ||
36 | //收缩样式 | ||
37 | if (outlookList.getOutlookBar().getOutlookPanel().isShrinked()) | ||
38 | { | ||
39 | setBorder(shrinkedBorder); | ||
40 | setText(null); | ||
41 | } | ||
42 | //普通样式 | ||
43 | else | ||
44 | { | ||
45 | setBorder(normalBorder); | ||
46 | setText(listItem.getText()); | ||
47 | setHorizontalAlignment(SwingConstants.LEADING); | ||
48 | setIconTextGap(5); | ||
49 | } | ||
50 | if (isSelected) | ||
51 | setBackground(selectedColor); | ||
52 | return this; | ||
53 | } | ||
54 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanel.java b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java new file mode 100644 index 0000000..139f62a --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanel.java | |||
@@ -0,0 +1,222 @@ | |||
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.Cursor; | ||
8 | import java.awt.Dimension; | ||
9 | import java.awt.Graphics; | ||
10 | import java.awt.Insets; | ||
11 | import java.awt.event.ActionListener; | ||
12 | import java.util.ArrayList; | ||
13 | import java.util.Hashtable; | ||
14 | import java.util.List; | ||
15 | import javax.swing.Icon; | ||
16 | import javax.swing.JButton; | ||
17 | import javax.swing.JComponent; | ||
18 | import javax.swing.JPanel; | ||
19 | import javax.swing.border.Border; | ||
20 | import javax.swing.event.ListSelectionListener; | ||
21 | |||
22 | import cppcheckplus.control.MyContorlUtil; | ||
23 | import layout.TableLayout; | ||
24 | |||
25 | public class MyOutlookPanel extends JPanel | ||
26 | { | ||
27 | //Header | ||
28 | private MyOutlookHeader header; | ||
29 | //容器Panel | ||
30 | private JPanel barPane;; | ||
31 | //右边的分割滑动线条 | ||
32 | private JPanel split; | ||
33 | private int splitWidth; | ||
34 | private Color splitColor; | ||
35 | private JPanel additionalPane; | ||
36 | private Hashtable componentLayoutRows; | ||
37 | private JPanel centerPane; | ||
38 | private TableLayout barPaneLayout; | ||
39 | private MyOutlookSplitListener splitListener; | ||
40 | private ListSelectionListener listSelectionListener; | ||
41 | |||
42 | /** | ||
43 | * 构造MyOutlookPanel | ||
44 | * @param headerListener Header的监听器 | ||
45 | * @param listSelectionListener ListItemSelection的监听器 | ||
46 | */ | ||
47 | public MyOutlookPanel(ActionListener headerListener,ListSelectionListener listSelectionListener) | ||
48 | { | ||
49 | super(); | ||
50 | //注册Header事件 | ||
51 | this.header = new MyOutlookHeader(headerListener){ | ||
52 | public void setShrink(boolean shrinked) | ||
53 | { | ||
54 | super.setShrink(shrinked); | ||
55 | shrinkChanged(shrinked); | ||
56 | } | ||
57 | |||
58 | }; | ||
59 | this.listSelectionListener = listSelectionListener; | ||
60 | barPaneLayout = new TableLayout(); | ||
61 | barPane = new JPanel(barPaneLayout); | ||
62 | |||
63 | additionalPane = new JPanel(new BorderLayout()); | ||
64 | componentLayoutRows = new Hashtable(); | ||
65 | centerPane = new JPanel(new BorderLayout()); | ||
66 | |||
67 | //分割条 | ||
68 | split = new JPanel(); | ||
69 | splitWidth = 1; | ||
70 | splitColor = new Color(166, 172, 174); | ||
71 | splitListener = new MyOutlookSplitListener(header); | ||
72 | |||
73 | init(); | ||
74 | } | ||
75 | private void init() | ||
76 | { | ||
77 | split.setPreferredSize(new Dimension(splitWidth, 0)); | ||
78 | split.setOpaque(true); | ||
79 | split.setBackground(splitColor); | ||
80 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
81 | split.addMouseListener(splitListener); | ||
82 | split.addMouseMotionListener(splitListener); | ||
83 | additionalPane.setBackground(MyContorlUtil.OUTLOOK_CONTAINER_COLOR); | ||
84 | additionalPane.setPreferredSize(new Dimension(0, 0)); | ||
85 | additionalPane.setBorder(new Border() { | ||
86 | |||
87 | public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) | ||
88 | { | ||
89 | g.setColor(MyContorlUtil.OUTLOOK_SPLIT_COLOR); | ||
90 | g.drawLine(0, 0, width, 0); | ||
91 | } | ||
92 | |||
93 | public Insets getBorderInsets(Component c) | ||
94 | { | ||
95 | return new Insets(1, 0, 0, 0); | ||
96 | } | ||
97 | |||
98 | public boolean isBorderOpaque() | ||
99 | { | ||
100 | return true; | ||
101 | } | ||
102 | |||
103 | }); | ||
104 | |||
105 | centerPane.add(barPane, "North"); | ||
106 | centerPane.add(additionalPane, "Center"); | ||
107 | barPaneLayout.insertColumn(0, -1D); | ||
108 | setLayout(new BorderLayout()); | ||
109 | add(header, "North"); | ||
110 | add(centerPane, "Center"); | ||
111 | add(split, "East"); | ||
112 | } | ||
113 | public MyOutlookBar addBar(String title, Icon icon, Icon selectedIcon,MyOutlookPanelListItem[] listItems) | ||
114 | { | ||
115 | MyOutlookBar bar = new MyOutlookBar(this); | ||
116 | MyOutlookListPanel listPanel = getListPanel(listItems, bar); | ||
117 | //注册JList事件 | ||
118 | listPanel.getOutlookList().addListSelectionListener(listSelectionListener); | ||
119 | bar.setOutlookListPanel(listPanel); | ||
120 | bar.setSelected(false); | ||
121 | bar.setTitle(title); | ||
122 | bar.setIcon(icon); | ||
123 | bar.setSelectedIcon(selectedIcon); | ||
124 | int rowCount = barPaneLayout.getRow().length; | ||
125 | barPaneLayout.insertRow(rowCount, -2D); | ||
126 | barPane.add(bar, (new StringBuilder()).append("0,").append(rowCount).toString()); | ||
127 | componentLayoutRows.put(bar, Integer.valueOf(rowCount)); | ||
128 | rowCount++; | ||
129 | barPaneLayout.insertRow(rowCount, -3D); | ||
130 | //加载列表 | ||
131 | barPane.add(listPanel,(new StringBuilder()).append("0,").append(rowCount).toString()); | ||
132 | componentLayoutRows.put(bar.getContentComponent(), Integer.valueOf(rowCount)); | ||
133 | return bar; | ||
134 | } | ||
135 | private MyOutlookListPanel getListPanel(MyOutlookPanelListItem[] listItems,MyOutlookBar bar) | ||
136 | { | ||
137 | MyOutlookList list = new MyOutlookList(listItems,bar); | ||
138 | MyOutlookListPanel listPanel = new MyOutlookListPanel(list); | ||
139 | return listPanel; | ||
140 | } | ||
141 | public void updateLayoutConstraint(Component component, boolean selected) | ||
142 | { | ||
143 | int rowIndex = ((Integer)componentLayoutRows.get(component)).intValue(); | ||
144 | double constraint = -1D; | ||
145 | if (!selected) | ||
146 | constraint = -3D; | ||
147 | barPaneLayout.setRow(rowIndex, constraint); | ||
148 | } | ||
149 | public JComponent getAdditionalPane() | ||
150 | { | ||
151 | return additionalPane; | ||
152 | } | ||
153 | public void setAdditionalPaneVisible(boolean visible) | ||
154 | { | ||
155 | centerPane.remove(barPane); | ||
156 | centerPane.remove(additionalPane); | ||
157 | if (visible) | ||
158 | { | ||
159 | centerPane.add(barPane, "North"); | ||
160 | centerPane.add(additionalPane, "Center"); | ||
161 | } else | ||
162 | { | ||
163 | centerPane.add(barPane, "Center"); | ||
164 | } | ||
165 | } | ||
166 | public void closeAllBars() | ||
167 | { | ||
168 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
169 | { | ||
170 | Component c = barPane.getComponent(i); | ||
171 | if (!(c instanceof MyOutlookBar)) | ||
172 | continue; | ||
173 | MyOutlookBar bar = (MyOutlookBar)c; | ||
174 | if (bar.isSelected()) | ||
175 | bar.setSelected(false); | ||
176 | } | ||
177 | } | ||
178 | public MyOutlookBar getSelectedBar() | ||
179 | { | ||
180 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
181 | { | ||
182 | Component c = barPane.getComponent(i); | ||
183 | if (!(c instanceof MyOutlookBar)) | ||
184 | continue; | ||
185 | MyOutlookBar bar = (MyOutlookBar)c; | ||
186 | if (bar.isSelected()) | ||
187 | return bar; | ||
188 | } | ||
189 | |||
190 | return null; | ||
191 | } | ||
192 | public void setShrink(boolean shrinked) | ||
193 | { | ||
194 | header.setShrink(shrinked); | ||
195 | } | ||
196 | |||
197 | public boolean isShrinked() | ||
198 | { | ||
199 | return header.isShrinked(); | ||
200 | } | ||
201 | private void shrinkChanged(boolean shrinked) | ||
202 | { | ||
203 | if (shrinked) | ||
204 | split.setCursor(Cursor.getDefaultCursor()); | ||
205 | else | ||
206 | split.setCursor(Cursor.getPredefinedCursor(10)); | ||
207 | for (int i = 0; i < barPane.getComponentCount(); i++) | ||
208 | { | ||
209 | Component c = barPane.getComponent(i); | ||
210 | if (c instanceof MyOutlookBar) | ||
211 | { | ||
212 | MyOutlookBar bar = (MyOutlookBar)c; | ||
213 | bar.headerShrinkChanged(shrinked); | ||
214 | |||
215 | |||
216 | //XOutlookList list = bar.getList(); | ||
217 | |||
218 | //list.firePropertyChange("layoutOrientation", true, false); | ||
219 | } | ||
220 | } | ||
221 | } | ||
222 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java new file mode 100644 index 0000000..92fd09e --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookPanelListItem.java | |||
@@ -0,0 +1,51 @@ | |||
1 | package cppcheckplus.outlookpanel; | ||
2 | |||
3 | import javax.swing.Icon; | ||
4 | |||
5 | public class MyOutlookPanelListItem | ||
6 | { | ||
7 | private Icon icon; | ||
8 | private String text; | ||
9 | private String toolTip; | ||
10 | private String actionCommand; | ||
11 | |||
12 | public void setIcon(Icon icon) | ||
13 | { | ||
14 | this.icon = icon; | ||
15 | } | ||
16 | |||
17 | public Icon getIcon() | ||
18 | { | ||
19 | return icon; | ||
20 | } | ||
21 | |||
22 | public void setText(String value) | ||
23 | { | ||
24 | this.text = value; | ||
25 | } | ||
26 | |||
27 | public String getText() | ||
28 | { | ||
29 | return text; | ||
30 | } | ||
31 | |||
32 | public void setToolTip(String toolTip) | ||
33 | { | ||
34 | this.toolTip = toolTip; | ||
35 | } | ||
36 | |||
37 | public String getToolTip() | ||
38 | { | ||
39 | return toolTip; | ||
40 | } | ||
41 | |||
42 | public void setActionCommand(String actionCommand) | ||
43 | { | ||
44 | this.actionCommand = actionCommand; | ||
45 | } | ||
46 | |||
47 | public String getActionCommand() | ||
48 | { | ||
49 | return actionCommand; | ||
50 | } | ||
51 | } | ||
diff --git a/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java new file mode 100644 index 0000000..b65e706 --- /dev/null +++ b/src/cppcheckplus/outlookpanel/MyOutlookSplitListener.java | |||
@@ -0,0 +1,33 @@ | |||
1 | |||
2 | package cppcheckplus.outlookpanel; | ||
3 | |||
4 | import java.awt.Dimension; | ||
5 | import java.awt.Point; | ||
6 | import java.awt.event.MouseEvent; | ||
7 | import javax.swing.JComponent; | ||
8 | |||
9 | import cppcheckplus.control.MyHeader; | ||
10 | import cppcheckplus.control.MyListSplitListener; | ||
11 | |||
12 | public class MyOutlookSplitListener extends MyListSplitListener | ||
13 | { | ||
14 | public MyOutlookSplitListener(MyHeader header) | ||
15 | { | ||
16 | super(header); | ||
17 | } | ||
18 | |||
19 | public void mouseDragged(MouseEvent e) | ||
20 | { | ||
21 | if (!header.isShrinked() && lastPoint != null) | ||
22 | { | ||
23 | JComponent parent = (JComponent)header.getParent(); | ||
24 | Dimension size = parent.getPreferredSize(); | ||
25 | Point thisPoint = e.getPoint(); | ||
26 | int xMovement = thisPoint.x - lastPoint.x; | ||
27 | size.width += xMovement; | ||
28 | size.width = Math.max(size.width, 37); | ||
29 | parent.setPreferredSize(size); | ||
30 | header.revalidateParent(); | ||
31 | } | ||
32 | } | ||
33 | } | ||