view src/samer/core_/util/heavy/PopupHandler.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	PopupHandler.java	
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package samer.core.util.heavy;
import  java.awt.*;
import  java.awt.event.*;

public class PopupHandler extends MouseAdapter
{
	private PopupMenu	popup;
	private boolean	backstop;

	public PopupHandler(PopupMenu p) { this(p,false); }	
	public PopupHandler(PopupMenu p, boolean bs) { popup=p; backstop=bs; }	

	public void mousePressed( MouseEvent e)
	{
		if (isTrigger(e)) { 
			popup.show( e.getComponent(), e.getX(), e.getY());
			e.consume();
		}
		// could pass directly on to dispatcher here
	}
	public void mouseReleased( MouseEvent e)
	{
		if (isTrigger(e)) { 
			popup.show( e.getComponent(), e.getX(), e.getY());
			e.consume();
		}
		// could pass directly on to dispatcher here
	}

	boolean isTrigger(MouseEvent e)
	{
		if (!e.isPopupTrigger()) return false;		

		// firstly, must have button 2 or 3 down
		// if ( (f & (InputEvent.BUTTON3_MASK|InputEvent.BUTTON2_MASK))==0 ) return false; 

		// next, if Popup is backstop menu, definitely show it
		if (backstop) return true; 

		// otherwise, must NOT have Alt or Ctl down
		if (e.isShiftDown() || e.isControlDown()) return false; 
		return true;
	}
}