1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 package uk.ac.rdg.resc.jstyx.interloper;
30
31 import javax.swing.JPopupMenu;
32 import javax.swing.JMenuItem;
33 import java.awt.event.ActionListener;
34 import java.awt.event.ActionEvent;
35 import java.awt.Component;
36
37 /***
38 * Pop-up menu that is shown when a user right-clicks on the table in
39 * the StyxMon.
40 *
41 * @author Jon Blower
42 * $Revision: 50 $
43 * $Date: 2005-02-28 13:46:46 +0000 (Mon, 28 Feb 2005) $
44 * $Log$
45 * Revision 1.4 2005/02/28 13:46:46 jonblower
46 * Combined the two ActionListeners into a single one
47 *
48 * Revision 1.3 2005/02/28 12:53:47 jonblower
49 * Improved message filtering
50 *
51 * Revision 1.2 2005/02/24 11:23:40 jonblower
52 * Handles filtering by filename correctly
53 *
54 * Revision 1.1 2005/02/24 09:06:26 jonblower
55 * Initial import
56 *
57 */
58 public class StyxMonPopupMenu extends JPopupMenu
59 {
60
61 private StyxMonTableModel theModel;
62 private JMenuItem menuShowAll;
63 private static final String prefix = "Filter by filename ";
64
65 /*** Creates a new instance of StyxMonPopUpMenu */
66 public StyxMonPopupMenu(StyxMonTableModel model)
67 {
68 this.theModel = model;
69 menuShowAll = new JMenuItem("Show all messages");
70 menuShowAll.addActionListener(al);
71 }
72
73 /***
74 * Shows a popup menu that gives the user the option to filter by a
75 * given filename
76 */
77 public void showContext(String filename, Component invoker, int x, int y)
78 {
79 this.removeAll();
80 if (this.theModel.isFiltered())
81 {
82 this.add(menuShowAll);
83 }
84 else
85 {
86
87 JMenuItem root = new JMenuItem(prefix + filename);
88 root.addActionListener(al);
89 this.add(root);
90 }
91 super.show(invoker, x, y);
92 }
93
94 /***
95 * Action listener for JMenuItems
96 */
97 ActionListener al = new ActionListener()
98 {
99 public void actionPerformed(ActionEvent e)
100 {
101 JMenuItem menuItem = (JMenuItem)e.getSource();
102 if (menuItem == menuShowAll)
103 {
104 theModel.showAllData();
105 }
106 else
107 {
108 String filename = menuItem.getText().substring(prefix.length());
109 theModel.filterByFilename(filename);
110 }
111 }
112 };
113
114 }