comparison visualizer/Bytecodes/src/com/sun/hotspot/igv/bytecodes/BytecodeViewTopComponent.java @ 4512:015fb895586b

Moved visualizer to new directory.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Tue, 07 Feb 2012 22:41:09 +0100
parents
children be428fe2d86c
comparison
equal deleted inserted replaced
4511:6cb549627941 4512:015fb895586b
1 /*
2 * Copyright (c) 2008, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * 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 javax.swing.SwingUtilities;
32 import org.openide.ErrorManager;
33 import org.openide.explorer.ExplorerManager;
34 import org.openide.explorer.ExplorerUtils;
35 import org.openide.explorer.view.BeanTreeView;
36 import org.openide.util.*;
37 import org.openide.windows.TopComponent;
38 import org.openide.windows.WindowManager;
39
40 /**
41 * @author Thomas Wuerthinger
42 */
43 final class BytecodeViewTopComponent extends TopComponent implements ExplorerManager.Provider, LookupListener {
44
45 private static BytecodeViewTopComponent instance;
46 private static final String PREFERRED_ID = "BytecodeViewTopComponent";
47 private ExplorerManager manager;
48 private BeanTreeView treeView;
49 private Lookup.Result result = null;
50 private MethodNode rootNode;
51
52 private BytecodeViewTopComponent() {
53 initComponents();
54 setName(NbBundle.getMessage(BytecodeViewTopComponent.class, "CTL_BytecodeViewTopComponent"));
55 setToolTipText(NbBundle.getMessage(BytecodeViewTopComponent.class, "HINT_BytecodeViewTopComponent"));
56
57 manager = new ExplorerManager();
58 rootNode = new MethodNode(null, null, "");
59 manager.setRootContext(rootNode);
60
61 setLayout(new BorderLayout());
62
63 treeView = new BeanTreeView();
64 treeView.setRootVisible(false);
65 this.add(BorderLayout.CENTER, treeView);
66 associateLookup(ExplorerUtils.createLookup(manager, getActionMap()));
67 }
68
69 /** This method is called from within the constructor to
70 * initialize the form.
71 * WARNING: Do NOT modify this code. The content of this method is
72 * always regenerated by the Form Editor.
73 */
74 // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75 private void initComponents() {
76
77 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
78 this.setLayout(layout);
79 layout.setHorizontalGroup(
80 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
81 .add(0, 400, Short.MAX_VALUE)
82 );
83 layout.setVerticalGroup(
84 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
85 .add(0, 300, Short.MAX_VALUE)
86 );
87 }// </editor-fold>//GEN-END:initComponents
88 // Variables declaration - do not modify//GEN-BEGIN:variables
89 // End of variables declaration//GEN-END:variables
90
91 /**
92 * Gets default instance. Do not use directly: reserved for *.settings files only,
93 * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
94 * To obtain the singleton instance, use {@link findInstance}.
95 */
96 public static synchronized BytecodeViewTopComponent getDefault() {
97 if (instance == null) {
98 instance = new BytecodeViewTopComponent();
99 }
100 return instance;
101 }
102
103 /**
104 * Obtain the BytecodeViewTopComponent instance. Never call {@link #getDefault} directly!
105 */
106 public static synchronized BytecodeViewTopComponent findInstance() {
107 TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
108 if (win == null) {
109 ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find BytecodeView component. It will not be located properly in the window system.");
110 return getDefault();
111 }
112 if (win instanceof BytecodeViewTopComponent) {
113 return (BytecodeViewTopComponent) win;
114 }
115 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.");
116 return getDefault();
117 }
118
119 @Override
120 public int getPersistenceType() {
121 return TopComponent.PERSISTENCE_ALWAYS;
122 }
123
124 @Override
125 public void componentOpened() {
126 Lookup.Template<InputGraphProvider> tpl = new Lookup.Template<>(InputGraphProvider.class);
127 result = Utilities.actionsGlobalContext().lookup(tpl);
128 result.addLookupListener(this);
129 }
130
131 @Override
132 public void componentClosed() {
133 result.removeLookupListener(this);
134 result = null;
135 }
136
137 @Override
138 public Object writeReplace() {
139 return new ResolvableHelper();
140 }
141
142 @Override
143 protected String preferredID() {
144 return PREFERRED_ID;
145 }
146
147 @Override
148 public ExplorerManager getExplorerManager() {
149 return manager;
150 }
151
152 @Override
153 public void requestActive() {
154 super.requestActive();
155 this.treeView.requestFocus();
156 }
157
158 @Override
159 public boolean requestFocus(boolean temporary) {
160 this.treeView.requestFocus();
161 return super.requestFocus(temporary);
162 }
163
164 @Override
165 protected boolean requestFocusInWindow(boolean temporary) {
166 this.treeView.requestFocus();
167 return super.requestFocusInWindow(temporary);
168 }
169
170 @Override
171 public void resultChanged(LookupEvent lookupEvent) {
172 final InputGraphProvider p = null; // TODO(tw): FIXME //.getLast(InputGraphProvider.class);//)Utilities.actionsGlobalContext().lookup(InputGraphProvider.class);
173 if (p != null) {
174 SwingUtilities.invokeLater(new Runnable() {
175 @Override
176 public void run() {
177 InputGraph graph = p.getGraph();
178 if (graph != null) {
179 Group g = graph.getGroup();
180 rootNode.update(graph, g.getMethod());
181 }
182 }
183 });
184 }
185 }
186
187 final static class ResolvableHelper implements Serializable {
188
189 private static final long serialVersionUID = 1L;
190
191 public Object readResolve() {
192 return BytecodeViewTopComponent.getDefault();
193 }
194 }
195 }