1 package com.explosion.expf.menusandtools.menu.popup;
2
3 import java.awt.AWTEvent;
4 import java.awt.ActiveEvent;
5 import java.awt.Component;
6 import java.awt.event.MouseEvent;
7 import java.awt.event.MouseListener;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 /***
30 * @author Stephen Cowx
31 * Created on 04-Mar-2005
32 */
33 public class ExpPopupMouseListener implements MouseListener
34 {
35
36 public void mouseClicked(MouseEvent event) {
37 mouseEvent(event);
38 }
39
40 public void mouseEntered(MouseEvent event) {
41 mouseEvent(event);
42 }
43
44 public void mouseExited(MouseEvent event) {
45 mouseEvent(event);
46 }
47
48 public void mousePressed(MouseEvent event) {
49 mouseEvent(event);
50 }
51
52 public void mouseReleased(MouseEvent event) {
53 mouseEvent(event);
54 }
55
56 private void mouseEvent(MouseEvent event) {
57 dispatchPopup(event);
58 }
59
60 /*** Dispatches popup events to ancestor implementing ExpPopupIntercepter. */
61 public static boolean dispatchPopup(AWTEvent event) {
62 if (!(event instanceof MouseEvent) || event instanceof ActiveEvent) { return false; }
63 MouseEvent mouseEvent = (MouseEvent) event;
64 if (!mouseEvent.isPopupTrigger()) { return false; }
65 Object src = event.getSource();
66 if (!(src instanceof Component)) { return false; }
67 Component component = (Component) src;
68 while (component != null) {
69 if (component.isFocusOwner() && component instanceof ExpPopupIntercepter) {
70 ExpPopupIntercepter intercepter = (ExpPopupIntercepter) component;
71 intercepter.popupEvent(mouseEvent);
72 mouseEvent.consume();
73 return true;
74 }
75 component = component.getParent();
76 }
77 return false;
78 }
79
80 }