2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
43
* NodeExpansionMouseControl.java
45
* Created on January 17, 2006, 12:50 PM
47
* To change this template, choose Tools | Template Manager
48
* and open the template in the editor.
51
package org.netbeans.modules.xml.nbprefuse;
54
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56
import java.awt.event.MouseEvent;
57
import java.util.Iterator;
58
import javax.swing.JMenuItem;
59
import javax.swing.JPopupMenu;
60
import org.netbeans.modules.xml.nbprefuse.util.GraphUtilities;
61
import org.openide.util.NbBundle;
62
import prefuse.Visualization;
63
import prefuse.controls.ControlAdapter;
64
import prefuse.visual.AggregateItem;
65
import prefuse.visual.NodeItem;
66
import prefuse.visual.VisualItem;
70
* @author Jeri Lockhart
72
public final class NodeExpansionMouseControl extends ControlAdapter {
74
private JPopupMenu popup;
75
private VisualItem vItem;
76
private JMenuItem menuItem;
78
public NodeExpansionMouseControl(final Visualization viz, final String activity) {
79
popup = new JPopupMenu();
80
menuItem = new JMenuItem();
81
menuItem.addActionListener(new ActionListener() {
82
public void actionPerformed(ActionEvent e){
83
if (vItem != null && vItem instanceof VisualItem){
84
NodeItem fileNode = null;
85
if (vItem.canGetBoolean(AnalysisConstants.IS_FILE_GROUP_AGGREGATE) &&
86
vItem.getBoolean(AnalysisConstants.IS_FILE_GROUP_AGGREGATE)){
88
fileNode = findFileNode(vItem.getInt(AnalysisConstants.ID),
89
AggregateItem.class.cast(vItem));
91
fileNode = NodeItem.class.cast(vItem);
93
if (fileNode.canGetBoolean(AnalysisConstants.IS_FILE_NODE) &&
94
fileNode.getBoolean(AnalysisConstants.IS_FILE_NODE)){
95
GraphUtilities.expandCollapseFileNode(fileNode);
96
if (activity != null){
107
public void itemReleased(VisualItem gi, MouseEvent e) {
109
super.itemReleased(gi, e);
114
public void itemPressed(VisualItem gi, MouseEvent e) {
116
super.itemPressed(gi, e);
123
private void maybeShowPopup(MouseEvent e) {
124
if (e.isPopupTrigger()) {
125
NodeItem fileNode = null;
126
if (vItem.canGetBoolean(AnalysisConstants.IS_FILE_GROUP_AGGREGATE) &&
127
vItem.getBoolean(AnalysisConstants.IS_FILE_GROUP_AGGREGATE)){
128
fileNode = findFileNode(vItem.getInt(AnalysisConstants.ID),
129
AggregateItem.class.cast(vItem));
131
if (vItem.canGetBoolean(AnalysisConstants.IS_FILE_NODE) &&
132
vItem.getBoolean(AnalysisConstants.IS_FILE_NODE)){
133
fileNode = NodeItem.class.cast(vItem);
135
if (fileNode == null){
138
boolean isExpanded = fileNode.getBoolean(AnalysisConstants.IS_EXPANDED);
139
menuItem.setText(NbBundle.getMessage(NodeExpansionMouseControl.class,(isExpanded?"LBL_collapse":"LBL_expand")));
140
popup.show(e.getComponent(),
146
* Finds the schema File Node in the AggregateItem
147
* The AggregateItem contains the schema file node and
148
* the SchemaComponent nodes for the file
151
private NodeItem findFileNode(final int aggregateItemFileGroup, final VisualItem item ) {
152
NodeItem fileNode = null;
153
AggregateItem agIt = AggregateItem.class.cast(item);
154
Iterator agItems = agIt.items();
155
while(agItems.hasNext()){
156
VisualItem agItem = (VisualItem)agItems.next();
158
if (agItem.canGetInt(AnalysisConstants.FILE_NODE_FILE_GROUP)) {
159
fileGroup = agItem.getInt(AnalysisConstants.FILE_NODE_FILE_GROUP);
160
if (fileGroup == aggregateItemFileGroup &&
161
agItem.canGetBoolean(AnalysisConstants.IS_EXPANDED)){
162
fileNode = NodeItem.class.cast(agItem);