Coverage Report - org.dishevelled.identify.ContextMenuListener
 
Classes in this File Line Coverage Branch Coverage Complexity
ContextMenuListener
0%
0/13
0%
0/6
2
 
 1  
 /*
 2  
 
 3  
     dsh-identify  Lightweight components for identifiable beans.
 4  
     Copyright (c) 2003-2019 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.identify;
 25  
 
 26  
 import java.awt.event.MouseAdapter;
 27  
 import java.awt.event.MouseEvent;
 28  
 
 29  
 import javax.swing.JPopupMenu;
 30  
 
 31  
 /**
 32  
  * Context menu listener.
 33  
  *
 34  
  * @author  Michael Heuer
 35  
  */
 36  
 public final class ContextMenuListener
 37  
     extends MouseAdapter
 38  
 {
 39  
     /** Context menu. */
 40  
     private final JPopupMenu contextMenu;
 41  
 
 42  
 
 43  
     /**
 44  
      * Create a new context menu listener for the specified context menu.
 45  
      *
 46  
      * @param contextMenu context menu, must not be null
 47  
      */
 48  
     public ContextMenuListener(final JPopupMenu contextMenu)
 49  0
     {
 50  0
         if (contextMenu == null)
 51  
         {
 52  0
             throw new IllegalArgumentException("contextMenu must not be null");
 53  
         }
 54  0
         this.contextMenu = contextMenu;
 55  0
     }
 56  
 
 57  
 
 58  
     @Override
 59  
     public void mousePressed(final MouseEvent event)
 60  
     {
 61  0
         if (event.isPopupTrigger())
 62  
         {
 63  0
             showContextMenu(event);
 64  
         }
 65  0
     }
 66  
 
 67  
     @Override
 68  
     public void mouseReleased(final MouseEvent event)
 69  
     {
 70  0
         if (event.isPopupTrigger())
 71  
         {
 72  0
             showContextMenu(event);
 73  
         }
 74  0
     }
 75  
 
 76  
     /**
 77  
      * Show context menu.
 78  
      *
 79  
      * @param event mouse event
 80  
      */
 81  
     private void showContextMenu(final MouseEvent event)
 82  
     {
 83  0
         contextMenu.show(event.getComponent(), event.getX(), event.getY());
 84  0
     }
 85  
 }