001/* A mouse filter class for dealing with popups on different platforms. 002 003 Copyright (c) 1998-2016 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028package ptolemy.vergil.basic; 029 030import java.awt.event.MouseEvent; 031 032import diva.canvas.event.ExtendedMouseFilter; 033import ptolemy.gui.PtGUIUtilities; 034 035////////////////////////////////////////////////////////////////////////// 036//// PopupMouseFilter 037 038/** 039 This class is a mouseFilter that recognizes popup events. 040 Unfortunately, on because of the Diva event dispatch architecture, 041 it is difficult to have interactors receive mouseReleased events, 042 without possibly hiding mousePressed events from other interactors. 043 This class is a workaround for popup menus which uses 044 MouseEvent.isPopupTrigger() for macs, but uses a hardcoded right 045 mouse button for PC's. 046 047 @author Steve Neuendorffer 048 @version $Id$ 049 @since Ptolemy II 2.0 050 @Pt.ProposedRating Red (eal) 051 @Pt.AcceptedRating Red (johnr) 052 */ 053public class PopupMouseFilter extends ExtendedMouseFilter { 054 /** Create an attribute controller associated with the specified graph 055 * controller. 056 */ 057 public PopupMouseFilter() { 058 super(3, 0, 0); 059 } 060 061 /** 062 * Test whether the given MouseEvent passes the filter. 063 */ 064 @Override 065 public boolean accept(MouseEvent event) { 066 if (PtGUIUtilities.macOSLookAndFeel()) { 067 return event.isPopupTrigger(); 068 } else { 069 return super.accept(event); 070 } 071 } 072}