diff options
Diffstat (limited to 'src/cppcheckplus/control/MyList.java')
-rw-r--r-- | src/cppcheckplus/control/MyList.java | 104 |
1 files changed, 47 insertions, 57 deletions
diff --git a/src/cppcheckplus/control/MyList.java b/src/cppcheckplus/control/MyList.java index 2a577ff..084ee74 100644 --- a/src/cppcheckplus/control/MyList.java +++ b/src/cppcheckplus/control/MyList.java | |||
@@ -1,68 +1,58 @@ | |||
1 | |||
2 | package cppcheckplus.control; | 1 | package cppcheckplus.control; |
3 | 2 | ||
3 | import cppcheckplus.shortcut.MyShortcutItem; | ||
4 | import cppcheckplus.shortcut.MyShortcutItemClickListenter; | ||
4 | import java.awt.event.MouseEvent; | 5 | import java.awt.event.MouseEvent; |
5 | |||
6 | import javax.swing.JList; | 6 | import javax.swing.JList; |
7 | import javax.swing.event.MouseInputAdapter; | 7 | import javax.swing.event.MouseInputAdapter; |
8 | import javax.swing.event.MouseInputListener; | 8 | import javax.swing.event.MouseInputListener; |
9 | 9 | ||
10 | import cppcheckplus.shortcut.MyShortcutItem; | ||
11 | import cppcheckplus.shortcut.MyShortcutItemClickListenter; | ||
12 | 10 | ||
11 | public class MyList extends JList { | ||
12 | private MyShortcutItemClickListenter clickListenter; | ||
13 | |||
14 | public MyList() { | ||
15 | init(); | ||
16 | } | ||
17 | |||
18 | public void setListenter(MyShortcutItemClickListenter itemClickListenter) { | ||
19 | this.clickListenter = itemClickListenter; | ||
20 | MouseInputListener listener = new MouseInputAdapter() { | ||
21 | //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 | ||
22 | @Override | ||
23 | public void mouseMoved(MouseEvent e) { | ||
24 | int moveIndex = locationToIndex(e.getPoint()); | ||
25 | setSelectedIndex(moveIndex); | ||
26 | } | ||
27 | |||
28 | //移动出去之后,清除选中,从而触发渲染器 | ||
29 | @Override | ||
30 | public void mouseExited(MouseEvent e) { | ||
31 | getSelectionModel().clearSelection(); | ||
32 | } | ||
13 | 33 | ||
14 | public class MyList extends JList | 34 | @Override |
15 | { | 35 | public void mouseClicked(MouseEvent e) { |
16 | private MyShortcutItemClickListenter clickListenter; | 36 | //因为该JList是单选模式,所以取第一个选择的就可以了 |
17 | 37 | Object selObj = getSelectedValue(); | |
18 | public MyList() | 38 | if (selObj != null) { |
19 | { | 39 | MyShortcutItem item = (MyShortcutItem) selObj; |
20 | init(); | 40 | if (!item.isGroup()) { |
21 | } | 41 | clickListenter.ItemClick(item.getActionCommand()); |
22 | public void setListenter(MyShortcutItemClickListenter itemClickListenter) | 42 | } |
23 | { | 43 | } |
24 | this.clickListenter = itemClickListenter; | 44 | //itemClick.ItemClick(actionCommand) |
25 | MouseInputListener listener = new MouseInputAdapter() | 45 | } |
26 | { | 46 | }; |
27 | //通过Move设置Item为selected,从而触发渲染器处理,实现高亮 | 47 | addMouseMotionListener(listener); |
28 | @Override | 48 | addMouseListener(listener); |
29 | public void mouseMoved(MouseEvent e) | 49 | } |
30 | { | ||
31 | int moveIndex = locationToIndex(e.getPoint()); | ||
32 | setSelectedIndex(moveIndex); | ||
33 | } | ||
34 | //移动出去之后,清除选中,从而触发渲染器 | ||
35 | @Override | ||
36 | public void mouseExited(MouseEvent e) | ||
37 | { | ||
38 | getSelectionModel().clearSelection(); | ||
39 | } | ||
40 | 50 | ||
41 | @Override | 51 | private void init() { |
42 | public void mouseClicked(MouseEvent e) | 52 | setFont(MyContorlUtil.FONT_12_BOLD); |
43 | { | 53 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); |
44 | //因为该JList是单选模式,所以取第一个选择的就可以了 | 54 | setBackground(MyContorlUtil.LIST_BACKGROUND); |
45 | Object selObj = getSelectedValue(); | 55 | setCellRenderer(new MyListRenderer(this)); |
46 | if(selObj != null) | 56 | setSelectionMode(0); |
47 | { | 57 | } |
48 | MyShortcutItem item = (MyShortcutItem)selObj; | ||
49 | if(!item.isGroup()) | ||
50 | { | ||
51 | clickListenter.ItemClick(item.getActionCommand()); | ||
52 | } | ||
53 | } | ||
54 | //itemClick.ItemClick(actionCommand) | ||
55 | } | ||
56 | }; | ||
57 | addMouseMotionListener(listener); | ||
58 | addMouseListener(listener); | ||
59 | } | ||
60 | private void init() | ||
61 | { | ||
62 | setFont(MyContorlUtil.FONT_12_BOLD); | ||
63 | setForeground(MyContorlUtil.DEFAULT_TEXT_COLOR); | ||
64 | setBackground(MyContorlUtil.LIST_BACKGROUND); | ||
65 | setCellRenderer(new MyListRenderer(this)); | ||
66 | setSelectionMode(0); | ||
67 | } | ||
68 | } | 58 | } |