001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.design.actions;
020:
021: import java.awt.Point;
022: import java.awt.Rectangle;
023: import java.awt.event.ActionEvent;
024: import javax.swing.JPopupMenu;
025: import org.netbeans.modules.bpel.design.DesignView;
026: import org.netbeans.modules.bpel.design.DiagramView;
027: import org.netbeans.modules.bpel.design.geometry.FBounds;
028: import org.netbeans.modules.bpel.design.model.patterns.Pattern;
029: import org.netbeans.modules.bpel.design.model.patterns.ProcessPattern;
030:
031: /**
032: *
033: * @author Vitaly Bychkov
034: * @version 1.0
035: */
036: public class ShowContextMenuAction extends DesignModeAction {
037:
038: private static final long serialVersionUID = 1L;
039:
040: public ShowContextMenuAction(DesignView view) {
041: super (view);
042: }
043:
044: public void actionPerformed(ActionEvent e) {
045: Pattern p = getDesignView().getSelectionModel()
046: .getSelectedPattern();
047:
048: if (p == null) {
049: return;
050: }
051:
052: JPopupMenu menu = p.createPopupMenu();
053:
054: FBounds r;
055:
056: if (p instanceof ProcessPattern) {
057: r = ((ProcessPattern) p).getBorder().getBounds();
058: } else {
059: r = p.getBounds();
060: }
061:
062: DiagramView dView = p.getView();
063:
064: Point topLeft = dView.convertPointToParent(r.getTopLeft());
065: Point bottomRight = dView.convertPointToParent(r
066: .getBottomRight());
067:
068: // Point topLeft = getDesignView().convertDiagramToScreen(r.getTopLeft());
069: // Point bottomRight = getDesignView().convertDiagramToScreen(r.getBottomRight());
070:
071: Rectangle vr = getDesignView().getVisibleRect();
072:
073: int x1 = Math.max(topLeft.x, vr.x);
074: int y1 = Math.max(topLeft.y, vr.y);
075:
076: int x2 = Math.min(bottomRight.x, vr.x + vr.width);
077: int y2 = Math.min(bottomRight.y, vr.y + vr.height);
078:
079: int px = topLeft.x;
080: int py = topLeft.y;
081:
082: if (x1 <= x2) {
083: px = x1;
084: } else if (px <= vr.x) {
085: px = vr.x;
086: } else if (px >= vr.x + vr.width) {
087: px = vr.x + vr.width;
088: }
089:
090: if (y1 <= y2) {
091: py = y1;
092: } else if (py <= vr.y) {
093: py = vr.y;
094: } else if (py >= vr.y + vr.height) {
095: py = vr.y + vr.height;
096: }
097:
098: menu.show(getDesignView(), px, py);
099: }
100: }
|