KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > xml > nbprefuse > PopupMouseControl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.xml.nbprefuse;
21
22
23 import java.awt.event.MouseEvent JavaDoc;
24 import javax.swing.Action JavaDoc;
25 import javax.swing.JPopupMenu JavaDoc;
26 import prefuse.controls.ControlAdapter;
27 import prefuse.visual.NodeItem;
28 import prefuse.visual.VisualItem;
29
30 /**
31  * In the prefuse NodeItem is stored a UIHelper org.openide.nodes.Node
32  * The actions from Node.getActions() are used to populate a NodeItem
33  * popup menu.
34  *
35  *
36  * @author Jeri Lockhart
37  */

38 public final class PopupMouseControl extends ControlAdapter {
39         
40         private VisualItem vItem;
41
42         public void itemReleased(VisualItem gi, MouseEvent JavaDoc e) {
43
44             super.itemReleased(gi, e);
45             vItem = gi;
46             maybeShowPopup(e);
47         }
48
49         public void itemPressed(VisualItem gi, MouseEvent JavaDoc e) {
50
51             super.itemPressed(gi, e);
52             vItem = gi;
53             maybeShowPopup(e);
54         }
55         
56         private void maybeShowPopup(MouseEvent JavaDoc e) {
57             if (e.isPopupTrigger()) {
58                 if (vItem instanceof NodeItem){
59                     if ((vItem.canGetBoolean(AnalysisConstants.IS_PRIMITIVE) &&
60                             vItem.getBoolean(AnalysisConstants.IS_PRIMITIVE) == false)
61                             &&
62                             (hasActions())
63                             ){
64                         
65                         createPopup().show(e.getComponent(),
66                                    e.getX(), e.getY());
67                         
68                     }
69                 }
70             }
71         }
72         
73         private boolean hasActions(){
74         /* org.openide.nodes.Node displayNode = null;
75             if (vItem.canGet(AnalysisConstants.OPENIDE_NODE,
76                     org.openide.nodes.Node.class)) {
77                 displayNode = (org.openide.nodes.Node)
78                     vItem.get(AnalysisConstants.OPENIDE_NODE);
79                 if (displayNode == null){
80                     return false;
81                 }
82                 Action[] actions = displayNode.getActions(false);
83                 return (actions != null && actions.length > 0);
84             }*/

85             return false;
86         }
87         
88     private JPopupMenu JavaDoc createPopup() {
89         JPopupMenu JavaDoc menu = null;
90         /*if (vItem.canGet(AnalysisConstants.OPENIDE_NODE,
91                     org.openide.nodes.Node.class)) {
92         org.openide.nodes.Node displayNode = null;
93                 displayNode = (org.openide.nodes.Node)
94                     vItem.get(AnalysisConstants.OPENIDE_NODE);
95         if (displayNode != null) {
96             menu = displayNode.getContextMenu();
97         }
98         }*/

99         return menu == null ? new JPopupMenu JavaDoc() : menu;
100     }
101
102     }
103
Popular Tags