BytecodeNode.java revision 1472:c18cbe5936b8
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 */ 24package com.sun.hotspot.igv.bytecodes; 25 26import com.sun.hotspot.igv.data.InputBytecode; 27import com.sun.hotspot.igv.data.InputGraph; 28import com.sun.hotspot.igv.data.InputNode; 29import com.sun.hotspot.igv.data.Properties; 30import com.sun.hotspot.igv.data.Properties.StringPropertyMatcher; 31import java.awt.Image; 32import java.util.HashSet; 33import java.util.List; 34import java.util.Set; 35import javax.swing.Action; 36import org.openide.nodes.AbstractNode; 37import org.openide.nodes.Children; 38import org.openide.nodes.Node; 39import org.openide.util.Utilities; 40 41/** 42 * 43 * @author Thomas Wuerthinger 44 */ 45public 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} 101