1// BEGIN LICENSE BLOCK
2// Version: CMPL 1.1
3//
4// The contents of this file are subject to the Cisco-style Mozilla Public
5// License Version 1.1 (the "License"); you may not use this file except
6// in compliance with the License.  You may obtain a copy of the License
7// at www.eclipse-clp.org/license.
8//
9// Software distributed under the License is distributed on an "AS IS"
10// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See
11// the License for the specific language governing rights and limitations
12// under the License.
13//
14// The Original Code is  The ECLiPSe Constraint Logic Programming System.
15// The Initial Developer of the Original Code is  Cisco Systems, Inc.
16// Portions created by the Initial Developer are
17// Copyright (C) 2006 Cisco Systems, Inc.  All Rights Reserved.
18//
19// Contributor(s):
20//
21// END LICENSE BLOCK
22
23package com.parctechnologies.eclipse.visualisation;
24
25import java.awt.event.*;
26import java.awt.*;
27import java.util.*;
28import javax.swing.JPopupMenu;
29
30/**
31 * MouseListener to create and display a viewletPopupMenu based on the current
32 * selection when the right button is clicked on a Viewlet's component
33 * (the invoker).
34 */
35public class MouseViewletMenuUpPopper extends MouseAdapter
36{
37  private ContainerViewer containerViewer;
38  private Component invoker;
39  private static final int RIGHT_BUTTON_MASK = InputEvent.BUTTON3_MASK;
40
41
42  public MouseViewletMenuUpPopper(ContainerViewer containerViewer,
43                                  Component invoker)
44  {
45    this.containerViewer = containerViewer;
46    this.invoker = invoker;
47    invoker.addMouseListener(this);
48  }
49
50  public void mouseReleased(MouseEvent e)
51  {
52    if((e.getModifiers() & RIGHT_BUTTON_MASK) == RIGHT_BUTTON_MASK) {
53      JPopupMenu menu = containerViewer.getPopupMenu();
54      if (menu.getComponentCount() > 0) {
55        menu.show((Component) e.getSource(), e.getX(), e.getY());
56      }
57    }
58  }
59
60}
61