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.bytecodes;
|
|
25 |
|
|
26 |
import com.sun.hotspot.igv.data.Group;
|
|
27 |
import com.sun.hotspot.igv.data.InputGraph;
|
|
28 |
import com.sun.hotspot.igv.data.services.InputGraphProvider;
|
|
29 |
import java.awt.BorderLayout;
|
|
30 |
import java.io.Serializable;
|
|
31 |
import org.openide.ErrorManager;
|
|
32 |
import org.openide.explorer.ExplorerManager;
|
|
33 |
import org.openide.explorer.ExplorerUtils;
|
|
34 |
import org.openide.explorer.view.BeanTreeView;
|
|
35 |
import org.openide.util.Lookup;
|
|
36 |
import org.openide.util.LookupEvent;
|
|
37 |
import org.openide.util.LookupListener;
|
|
38 |
import org.openide.util.NbBundle;
|
|
39 |
import org.openide.util.Utilities;
|
|
40 |
import org.openide.windows.TopComponent;
|
|
41 |
import org.openide.windows.WindowManager;
|
|
42 |
|
|
43 |
/**
|
|
44 |
* @author Thomas Wuerthinger
|
|
45 |
*/
|
|
46 |
final class BytecodeViewTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener {
|
|
47 |
|
|
48 |
private static BytecodeViewTopComponent instance;
|
|
49 |
private static final String PREFERRED_ID = "BytecodeViewTopComponent";
|
|
50 |
private ExplorerManager manager;
|
|
51 |
private BeanTreeView treeView;
|
|
52 |
private Lookup.Result result = null;
|
|
53 |
private MethodNode rootNode;
|
|
54 |
|
|
55 |
private BytecodeViewTopComponent() {
|
|
56 |
initComponents();
|
|
57 |
setName(NbBundle.getMessage(BytecodeViewTopComponent.class, "CTL_BytecodeViewTopComponent"));
|
|
58 |
setToolTipText(NbBundle.getMessage(BytecodeViewTopComponent.class, "HINT_BytecodeViewTopComponent"));
|
|
59 |
|
|
60 |
manager = new ExplorerManager();
|
|
61 |
rootNode = new MethodNode(null, null, "");
|
|
62 |
manager.setRootContext(rootNode);
|
|
63 |
|
|
64 |
setLayout(new BorderLayout());
|
|
65 |
|
|
66 |
treeView = new BeanTreeView();
|
|
67 |
treeView.setRootVisible(false);
|
|
68 |
this.add(BorderLayout.CENTER, treeView);
|
|
69 |
associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
|
|
70 |
}
|
|
71 |
|
|
72 |
/** This method is called from within the constructor to
|
|
73 |
* initialize the form.
|
|
74 |
* WARNING: Do NOT modify this code. The content of this method is
|
|
75 |
* always regenerated by the Form Editor.
|
|
76 |
*/
|
|
77 |
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
|
|
78 |
private void initComponents() {
|
|
79 |
|
|
80 |
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
|
|
81 |
this.setLayout(layout);
|
|
82 |
layout.setHorizontalGroup(
|
|
83 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
|
84 |
.add(0, 400, Short.MAX_VALUE)
|
|
85 |
);
|
|
86 |
layout.setVerticalGroup(
|
|
87 |
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
|
88 |
.add(0, 300, Short.MAX_VALUE)
|
|
89 |
);
|
|
90 |
}// </editor-fold>//GEN-END:initComponents
|
|
91 |
// Variables declaration - do not modify//GEN-BEGIN:variables
|
|
92 |
// End of variables declaration//GEN-END:variables
|
|
93 |
/**
|
|
94 |
* Gets default instance. Do not use directly: reserved for *.settings files only,
|
|
95 |
* i.e. deserialization routines; otherwise you could get a non-deserialized instance.
|
|
96 |
* To obtain the singleton instance, use {@link findInstance}.
|
|
97 |
*/
|
|
98 |
public static synchronized BytecodeViewTopComponent getDefault() {
|
|
99 |
if (instance == null) {
|
|
100 |
instance = new BytecodeViewTopComponent();
|
|
101 |
}
|
|
102 |
return instance;
|
|
103 |
}
|
|
104 |
|
|
105 |
/**
|
|
106 |
* Obtain the BytecodeViewTopComponent instance. Never call {@link #getDefault} directly!
|
|
107 |
*/
|
|
108 |
public static synchronized BytecodeViewTopComponent findInstance() {
|
|
109 |
TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
|
|
110 |
if (win == null) {
|
|
111 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find BytecodeView component. It will not be located properly in the window system.");
|
|
112 |
return getDefault();
|
|
113 |
}
|
|
114 |
if (win instanceof BytecodeViewTopComponent) {
|
|
115 |
return (BytecodeViewTopComponent) win;
|
|
116 |
}
|
|
117 |
ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior.");
|
|
118 |
return getDefault();
|
|
119 |
}
|
|
120 |
|
|
121 |
@Override
|
|
122 |
public int getPersistenceType() {
|
|
123 |
return TopComponent.PERSISTENCE_ALWAYS;
|
|
124 |
}
|
|
125 |
|
|
126 |
@Override
|
|
127 |
public void componentOpened() {
|
|
128 |
Lookup.Template tpl = new Lookup.Template(Object.class);
|
|
129 |
result = Utilities.actionsGlobalContext().lookup(tpl);
|
|
130 |
result.addLookupListener(this);
|
|
131 |
}
|
|
132 |
|
|
133 |
@Override
|
|
134 |
public void componentClosed() {
|
|
135 |
result.removeLookupListener(this);
|
|
136 |
result = null;
|
|
137 |
}
|
|
138 |
|
|
139 |
@Override
|
|
140 |
public Object writeReplace() {
|
|
141 |
return new ResolvableHelper();
|
|
142 |
}
|
|
143 |
|
|
144 |
@Override
|
|
145 |
protected String preferredID() {
|
|
146 |
return PREFERRED_ID;
|
|
147 |
}
|
|
148 |
|
|
149 |
public ExplorerManager getExplorerManager() {
|
|
150 |
return manager;
|
|
151 |
}
|
|
152 |
|
|
153 |
public void resultChanged(LookupEvent lookupEvent) {
|
|
154 |
InputGraphProvider p = Lookup.getDefault().lookup(InputGraphProvider.class);
|
|
155 |
if (p != null) {
|
|
156 |
InputGraph graph = p.getGraph();
|
|
157 |
if (graph != null) {
|
|
158 |
Group g = graph.getGroup();
|
|
159 |
rootNode.update(graph, g.getMethod());
|
|
160 |
}
|
|
161 |
}
|
|
162 |
}
|
|
163 |
|
|
164 |
final static class ResolvableHelper implements Serializable {
|
|
165 |
|
|
166 |
private static final long serialVersionUID = 1L;
|
|
167 |
|
|
168 |
public Object readResolve() {
|
|
169 |
return BytecodeViewTopComponent.getDefault();
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|