001: /*
002: * ====================================================================
003: * The JRefactory License, Version 1.0
004: *
005: * Copyright (c) 2001 JRefactory. All rights reserved.
006: *
007: * Redistribution and use in source and binary forms, with or without
008: * modification, are permitted provided that the following conditions
009: * are met:
010: *
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The end-user documentation included with the redistribution,
020: * if any, must include the following acknowledgment:
021: * "This product includes software developed by the
022: * JRefactory (http://www.sourceforge.org/projects/jrefactory)."
023: * Alternately, this acknowledgment may appear in the software itself,
024: * if and wherever such third-party acknowledgments normally appear.
025: *
026: * 4. The names "JRefactory" must not be used to endorse or promote
027: * products derived from this software without prior written
028: * permission. For written permission, please contact seguin@acm.org.
029: *
030: * 5. Products derived from this software may not be called "JRefactory",
031: * nor may "JRefactory" appear in their name, without prior written
032: * permission of Chris Seguin.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL THE CHRIS SEGUIN OR
038: * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
039: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
040: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
041: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
042: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
043: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
044: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
045: * SUCH DAMAGE.
046: * ====================================================================
047: *
048: * This software consists of voluntary contributions made by many
049: * individuals on behalf of JRefactory. For more information on
050: * JRefactory, please see
051: * <http://www.sourceforge.org/projects/jrefactory>.
052: */
053: package org.acm.seguin.uml;
054:
055: import java.awt.Point;
056: import java.awt.event.MouseAdapter;
057: import java.awt.event.MouseEvent;
058: import javax.swing.JPanel;
059: import javax.swing.JPopupMenu;
060:
061: /**
062: * Create a mouse listener for a method or a field or a title
063: *
064: *@author Chris Seguin
065: *@created July 7, 1999
066: */
067: public class UMLMouseAdapter extends MouseAdapter {
068: private JPanel child;
069: // Instance Variables
070: private UMLPackage current;
071: private UMLType type;
072:
073: /**
074: * Constructor for the UMLMouseAdapter object
075: *
076: *@param initType Type object
077: *@param initChild Single line
078: *@param currentPackage Description of Parameter
079: */
080: public UMLMouseAdapter(UMLPackage currentPackage, UMLType initType,
081: JPanel initChild) {
082: current = currentPackage;
083: type = initType;
084: child = initChild;
085: }
086:
087: /**
088: * User has pressed a mouse button
089: *
090: *@param mevt the mouse event
091: */
092: public void mousePressed(MouseEvent mevt) {
093: if (mevt.isPopupTrigger()) {
094: showMenu(mevt);
095: }
096: }
097:
098: /**
099: * User has released a mouse button
100: *
101: *@param mevt the mouse event
102: */
103: public void mouseReleased(MouseEvent mevt) {
104: if (mevt.isPopupTrigger()) {
105: showMenu(mevt);
106: }
107: }
108:
109: /**
110: * Shows the popup menu
111: *
112: *@param mevt the mouse event
113: */
114: private void showMenu(MouseEvent mevt) {
115: Point pt;
116: UMLPopupMenu upm;
117: if (child == null) {
118: upm = new UMLPopupMenu(current, type);
119: pt = type.getLocationOnScreen();
120: } else {
121: upm = new UMLPopupMenu(current, child);
122: pt = child.getLocationOnScreen();
123: }
124: JPopupMenu menu = upm.getMenu();
125: menu.setLocation(mevt.getX() + pt.x, mevt.getY() + pt.y);
126: menu.setVisible(true);
127: }
128: }
|