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