768
|
1 |
/*
|
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*
|
|
23 |
*/
|
|
24 |
package com.sun.hotspot.igv.coordinator;
|
|
25 |
|
|
26 |
import com.sun.hotspot.igv.coordinator.actions.DiffGraphAction;
|
|
27 |
import com.sun.hotspot.igv.coordinator.actions.DiffGraphCookie;
|
|
28 |
import com.sun.hotspot.igv.coordinator.actions.RemoveCookie;
|
|
29 |
import com.sun.hotspot.igv.data.InputGraph;
|
|
30 |
import com.sun.hotspot.igv.data.services.GraphViewer;
|
|
31 |
import com.sun.hotspot.igv.data.services.InputGraphProvider;
|
|
32 |
import com.sun.hotspot.igv.util.PropertiesSheet;
|
|
33 |
import java.awt.Image;
|
|
34 |
import javax.swing.Action;
|
|
35 |
import org.openide.actions.OpenAction;
|
|
36 |
import org.openide.cookies.OpenCookie;
|
|
37 |
import org.openide.nodes.AbstractNode;
|
|
38 |
import org.openide.nodes.Children;
|
|
39 |
import org.openide.nodes.Node;
|
|
40 |
import org.openide.nodes.Sheet;
|
|
41 |
import org.openide.util.Lookup;
|
|
42 |
import org.openide.util.Utilities;
|
|
43 |
import org.openide.util.lookup.AbstractLookup;
|
|
44 |
import org.openide.util.lookup.InstanceContent;
|
|
45 |
|
|
46 |
/**
|
|
47 |
*
|
|
48 |
* @author Thomas Wuerthinger
|
|
49 |
*/
|
|
50 |
public class GraphNode extends AbstractNode {
|
|
51 |
|
|
52 |
private InputGraph graph;
|
|
53 |
|
|
54 |
/** Creates a new instance of GraphNode */
|
|
55 |
public GraphNode(InputGraph graph) {
|
|
56 |
this(graph, new InstanceContent());
|
|
57 |
}
|
|
58 |
|
|
59 |
private GraphNode(final InputGraph graph, InstanceContent content) {
|
|
60 |
super(Children.LEAF, new AbstractLookup(content));
|
|
61 |
this.graph = graph;
|
|
62 |
this.setDisplayName(graph.getName());
|
|
63 |
content.add(graph);
|
|
64 |
|
|
65 |
final GraphViewer viewer = Lookup.getDefault().lookup(GraphViewer.class);
|
|
66 |
|
|
67 |
if (viewer != null) {
|
|
68 |
// Action for opening the graph
|
|
69 |
content.add(new OpenCookie() {
|
|
70 |
|
|
71 |
public void open() {
|
|
72 |
viewer.view(graph);
|
|
73 |
}
|
|
74 |
});
|
|
75 |
}
|
|
76 |
|
|
77 |
// Action for removing a graph
|
|
78 |
content.add(new RemoveCookie() {
|
|
79 |
|
|
80 |
public void remove() {
|
|
81 |
graph.getGroup().removeGraph(graph);
|
|
82 |
}
|
|
83 |
});
|
|
84 |
}
|
|
85 |
|
|
86 |
@Override
|
|
87 |
protected Sheet createSheet() {
|
|
88 |
Sheet s = super.createSheet();
|
|
89 |
PropertiesSheet.initializeSheet(graph.getProperties(), s);
|
|
90 |
return s;
|
|
91 |
}
|
|
92 |
|
|
93 |
@Override
|
|
94 |
public Image getIcon(int i) {
|
|
95 |
return Utilities.loadImage("com/sun/hotspot/igv/coordinator/images/graph.gif");
|
|
96 |
}
|
|
97 |
|
|
98 |
@Override
|
|
99 |
public Image getOpenedIcon(int i) {
|
|
100 |
return getIcon(i);
|
|
101 |
}
|
|
102 |
|
|
103 |
@Override
|
|
104 |
public <T extends Node.Cookie> T getCookie(Class<T> aClass) {
|
|
105 |
if (aClass == DiffGraphCookie.class) {
|
|
106 |
InputGraphProvider graphProvider = Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
|
|
107 |
|
|
108 |
InputGraph graphA = null;
|
|
109 |
if (graphProvider != null) {
|
|
110 |
graphA = graphProvider.getGraph();
|
|
111 |
}
|
|
112 |
|
|
113 |
if (graphA != null && !graphA.isDifferenceGraph()) {
|
|
114 |
return (T) new DiffGraphCookie(graphA, graph);
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
return super.getCookie(aClass);
|
|
119 |
}
|
|
120 |
|
|
121 |
@Override
|
|
122 |
public Action[] getActions(boolean b) {
|
|
123 |
return new Action[]{(Action) DiffGraphAction.findObject(DiffGraphAction.class, true), (Action) OpenAction.findObject(OpenAction.class, true)};
|
|
124 |
}
|
|
125 |
|
|
126 |
@Override
|
|
127 |
public Action getPreferredAction() {
|
|
128 |
return (Action) OpenAction.findObject(OpenAction.class, true);
|
|
129 |
}
|
|
130 |
}
|