1 7 8 package org.gjt.jclasslib.browser; 9 10 import javax.swing.*; 11 import javax.swing.tree.TreeNode ; 12 import javax.swing.tree.TreePath ; 13 import java.awt.event.MouseAdapter ; 14 import java.awt.event.MouseEvent ; 15 16 22 public class ConstantPoolHyperlinkListener extends MouseAdapter { 23 24 private BrowserServices services; 25 private int constantPoolIndex; 26 27 32 public ConstantPoolHyperlinkListener(BrowserServices services, int constantPoolIndex) { 33 34 this.services = services; 35 this.constantPoolIndex = constantPoolIndex; 36 } 37 38 public void mouseClicked(MouseEvent event) { 39 link(services, constantPoolIndex); 40 } 41 42 47 public static void link(BrowserServices services, int constantPoolIndex) { 48 49 if (constantPoolIndex <= 0) { 50 return; 51 } 52 53 JTree tree = services.getBrowserComponent().getTreePane().getTree(); 54 TreePath newPath = linkPath(services, constantPoolIndex); 55 tree.setSelectionPath(newPath); 56 tree.scrollPathToVisible(newPath); 57 } 58 59 private static TreePath linkPath(BrowserServices services, int constantPoolIndex) { 60 61 TreePath constantPoolPath = services.getBrowserComponent().getTreePane().getPathForCategory(BrowserTreeNode.NODE_CONSTANT_POOL); 62 63 BrowserTreeNode constantPoolNode = (BrowserTreeNode)constantPoolPath.getLastPathComponent(); 64 TreeNode targetNode = constantPoolNode.getChildAt(constantPoolIndex - 1); 65 TreePath linkPath = constantPoolPath.pathByAddingChild(targetNode); 66 67 return linkPath; 68 } 69 70 } 71 72 | Popular Tags |