samer@0
|
1 /*
|
samer@0
|
2 * PopupHandler.java
|
samer@0
|
3 *
|
samer@0
|
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
|
samer@0
|
5 * All rights reserved.
|
samer@0
|
6 *
|
samer@0
|
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
|
samer@0
|
8 * without even the implied warranty of MERCHANTABILITY or
|
samer@0
|
9 * FITNESS FOR A PARTICULAR PURPOSE.
|
samer@0
|
10 */
|
samer@0
|
11
|
samer@0
|
12 package samer.core.util.heavy;
|
samer@0
|
13 import java.awt.*;
|
samer@0
|
14 import java.awt.event.*;
|
samer@0
|
15
|
samer@0
|
16 public class PopupHandler extends MouseAdapter
|
samer@0
|
17 {
|
samer@0
|
18 private PopupMenu popup;
|
samer@0
|
19 private boolean backstop;
|
samer@0
|
20
|
samer@0
|
21 public PopupHandler(PopupMenu p) { this(p,false); }
|
samer@0
|
22 public PopupHandler(PopupMenu p, boolean bs) { popup=p; backstop=bs; }
|
samer@0
|
23
|
samer@0
|
24 public void mousePressed( MouseEvent e)
|
samer@0
|
25 {
|
samer@0
|
26 if (isTrigger(e)) {
|
samer@0
|
27 popup.show( e.getComponent(), e.getX(), e.getY());
|
samer@0
|
28 e.consume();
|
samer@0
|
29 }
|
samer@0
|
30 // could pass directly on to dispatcher here
|
samer@0
|
31 }
|
samer@0
|
32 public void mouseReleased( MouseEvent e)
|
samer@0
|
33 {
|
samer@0
|
34 if (isTrigger(e)) {
|
samer@0
|
35 popup.show( e.getComponent(), e.getX(), e.getY());
|
samer@0
|
36 e.consume();
|
samer@0
|
37 }
|
samer@0
|
38 // could pass directly on to dispatcher here
|
samer@0
|
39 }
|
samer@0
|
40
|
samer@0
|
41 boolean isTrigger(MouseEvent e)
|
samer@0
|
42 {
|
samer@0
|
43 if (!e.isPopupTrigger()) return false;
|
samer@0
|
44
|
samer@0
|
45 // firstly, must have button 2 or 3 down
|
samer@0
|
46 // if ( (f & (InputEvent.BUTTON3_MASK|InputEvent.BUTTON2_MASK))==0 ) return false;
|
samer@0
|
47
|
samer@0
|
48 // next, if Popup is backstop menu, definitely show it
|
samer@0
|
49 if (backstop) return true;
|
samer@0
|
50
|
samer@0
|
51 // otherwise, must NOT have Alt or Ctl down
|
samer@0
|
52 if (e.isShiftDown() || e.isControlDown()) return false;
|
samer@0
|
53 return true;
|
samer@0
|
54 }
|
samer@0
|
55 }
|