|
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.InputBytecode; |
|
27 import com.sun.hotspot.igv.data.InputGraph; |
|
28 import com.sun.hotspot.igv.data.InputNode; |
|
29 import com.sun.hotspot.igv.data.Properties; |
|
30 import com.sun.hotspot.igv.data.Properties.StringPropertyMatcher; |
|
31 import java.awt.Image; |
|
32 import java.util.HashSet; |
|
33 import java.util.List; |
|
34 import java.util.Set; |
|
35 import javax.swing.Action; |
|
36 import org.openide.nodes.AbstractNode; |
|
37 import org.openide.nodes.Children; |
|
38 import org.openide.nodes.Node; |
|
39 import org.openide.util.Utilities; |
|
40 |
|
41 /** |
|
42 * |
|
43 * @author Thomas Wuerthinger |
|
44 */ |
|
45 public class BytecodeNode extends AbstractNode { |
|
46 |
|
47 private Set<InputNode> nodes; |
|
48 |
|
49 public BytecodeNode(InputBytecode bytecode, InputGraph graph, String bciValue) { |
|
50 |
|
51 super(Children.LEAF); |
|
52 this.setDisplayName(bytecode.getBci() + " " + bytecode.getName()); |
|
53 |
|
54 bciValue = bytecode.getBci() + " " + bciValue; |
|
55 bciValue = bciValue.trim(); |
|
56 |
|
57 Properties.PropertySelector<InputNode> selector = new Properties.PropertySelector<InputNode>(graph.getNodes()); |
|
58 StringPropertyMatcher matcher = new StringPropertyMatcher("bci", bciValue); |
|
59 List<InputNode> nodeList = selector.selectMultiple(matcher); |
|
60 if (nodeList.size() > 0) { |
|
61 nodes = new HashSet<InputNode>(); |
|
62 for (InputNode n : nodeList) { |
|
63 nodes.add(n); |
|
64 } |
|
65 this.setDisplayName(this.getDisplayName() + " (" + nodes.size() + " nodes)"); |
|
66 } |
|
67 } |
|
68 |
|
69 @Override |
|
70 public Image getIcon(int i) { |
|
71 if (nodes != null) { |
|
72 return Utilities.loadImage("com/sun/hotspot/igv/bytecodes/images/link.gif"); |
|
73 } else { |
|
74 return Utilities.loadImage("com/sun/hotspot/igv/bytecodes/images/bytecode.gif"); |
|
75 } |
|
76 } |
|
77 |
|
78 @Override |
|
79 public Image getOpenedIcon(int i) { |
|
80 return getIcon(i); |
|
81 } |
|
82 |
|
83 @Override |
|
84 public Action[] getActions(boolean b) { |
|
85 return new Action[]{(Action) SelectBytecodesAction.findObject(SelectBytecodesAction.class, true)}; |
|
86 } |
|
87 |
|
88 @Override |
|
89 public Action getPreferredAction() { |
|
90 return (Action) SelectBytecodesAction.findObject(SelectBytecodesAction.class, true); |
|
91 } |
|
92 |
|
93 @Override |
|
94 public <T extends Node.Cookie> T getCookie(Class<T> aClass) { |
|
95 if (aClass == SelectBytecodesCookie.class && nodes != null) { |
|
96 return (T) (new SelectBytecodesCookie(nodes)); |
|
97 } |
|
98 return super.getCookie(aClass); |
|
99 } |
|
100 } |