1 7 8 package org.gjt.jclasslib.browser.detail.constants; 9 10 import org.gjt.jclasslib.browser.BrowserTreeNode; 11 import org.gjt.jclasslib.browser.config.window.*; 12 import org.gjt.jclasslib.structures.CPInfo; 13 import org.gjt.jclasslib.structures.InvalidByteCodeException; 14 import org.gjt.jclasslib.structures.constants.*; 15 16 import javax.swing.*; 17 import java.awt.*; 18 import java.awt.event.ActionEvent ; 19 import java.awt.event.ActionListener ; 20 21 27 public class ClassElementOpener implements ActionListener { 28 29 private JButton btnShow; 30 private CPInfo cpInfo; 31 private AbstractConstantInfoDetailPane detailPane; 32 33 37 public ClassElementOpener(AbstractConstantInfoDetailPane detailPane) { 38 this.detailPane = detailPane; 39 40 btnShow = new JButton("Show"); 41 btnShow.addActionListener(this); 42 } 43 44 public void actionPerformed(ActionEvent event) { 45 46 try { 47 ConstantClassInfo classInfo = null; 48 BrowserPath browserPath = null; 49 if (cpInfo instanceof ConstantClassInfo) { 50 classInfo = (ConstantClassInfo)cpInfo; 51 } else if (cpInfo instanceof ConstantReference) { 52 ConstantReference reference = (ConstantReference)cpInfo; 53 ConstantNameAndTypeInfo nameAndType = reference.getNameAndTypeInfo(); 54 classInfo = reference.getClassInfo(); 55 String category = null; 56 if (cpInfo instanceof ConstantFieldrefInfo) { 57 category = BrowserTreeNode.NODE_FIELD; 58 } else if (cpInfo instanceof ConstantMethodrefInfo || cpInfo instanceof ConstantInterfaceMethodrefInfo){ 59 category = BrowserTreeNode.NODE_METHOD; 60 } 61 if (category != null) { 62 browserPath = new BrowserPath(); 63 browserPath.addPathComponent(new CategoryHolder(category)); 64 browserPath.addPathComponent(new ReferenceHolder(nameAndType.getName(), nameAndType.getDescriptor())); 65 } 66 } 67 if (classInfo == null) { 68 return; 69 } 70 String className = classInfo.getName().replace('/', '.'); 71 detailPane.getBrowserServices().openClassFile(className, browserPath); 72 } catch (InvalidByteCodeException ex) { 73 ex.printStackTrace(); 74 } 75 } 76 77 83 public int addSpecial(AbstractConstantInfoDetailPane detailPane, int gridy) { 84 85 GridBagConstraints gc = new GridBagConstraints(); 86 gc.weightx = 1; 87 gc.anchor = GridBagConstraints.WEST; 88 gc.insets = new Insets(5, 10, 0, 10); 89 gc.gridy = gridy; 90 gc.gridx = 0; 91 gc.gridwidth = 3; 92 93 detailPane.add(btnShow, gc); 94 95 return 1; 96 } 97 98 102 public void setCPInfo(CPInfo cpInfo) { 103 104 this.cpInfo = cpInfo; 105 106 String buttonText = null; 107 if (cpInfo instanceof ConstantClassInfo) { 108 buttonText = "Show class"; 109 try { 110 if (((ConstantClassInfo)cpInfo).getName().equals(detailPane.getBrowserServices().getClassFile().getThisClassName())) { 111 buttonText = null; 112 } 113 } catch (InvalidByteCodeException e) { 114 } 115 } else if (cpInfo instanceof ConstantFieldrefInfo) { 116 buttonText = "Show field"; 117 } else if (cpInfo instanceof ConstantMethodrefInfo) { 118 buttonText = "Show method"; 119 } else if (cpInfo instanceof ConstantInterfaceMethodrefInfo) { 120 buttonText = "Show interface method"; 121 } 122 123 if (buttonText != null) { 124 btnShow.setVisible(true); 125 btnShow.setText(buttonText); 126 } else { 127 btnShow.setVisible(false); 128 } 129 } 130 131 } 132 | Popular Tags |