comparison src/samer/core_/util/swing/PopupHandler.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * PopupHandler.java
3 *
4 * Copyright (c) 2000, Samer Abdallah, King's College London.
5 * All rights reserved.
6 *
7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
8 * without even the implied warranty of MERCHANTABILITY or
9 * FITNESS FOR A PARTICULAR PURPOSE.
10 */
11
12 package samer.core.util.swing;
13 import java.awt.event.*;
14 import javax.swing.*;
15
16 public class PopupHandler extends MouseAdapter
17 {
18 private JPopupMenu popup;
19 private boolean backstop;
20
21 public PopupHandler(JPopupMenu p) { this(p,false); }
22 public PopupHandler(JPopupMenu p, boolean bs) { popup=p; backstop=bs; }
23
24 public void setBackstop(boolean f) { backstop=f; }
25 public void mousePressed( MouseEvent e) { maybeShowMenu(e); }
26 public void mouseReleased( MouseEvent e) { maybeShowMenu(e); }
27
28 void maybeShowMenu(MouseEvent e)
29 {
30 if (!e.isPopupTrigger()) return;
31 if (!backstop) {
32 // if not backstop, must NOT have Alt or Ctl down
33 // modified for Macs: need modifiers to get right mouse click!
34 if (e.isShiftDown()) return;
35 }
36 popup.show( e.getComponent(), e.getX(), e.getY());
37 e.consume();
38 }
39 }