KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > jclasslib > browser > ConstantPoolHyperlinkListener


1 /*
2     This library is free software; you can redistribute it and/or
3     modify it under the terms of the GNU General Public
4     License as published by the Free Software Foundation; either
5     version 2 of the license, or (at your option) any later version.
6 */

7
8 package org.gjt.jclasslib.browser;
9
10 import javax.swing.*;
11 import javax.swing.tree.TreeNode JavaDoc;
12 import javax.swing.tree.TreePath JavaDoc;
13 import java.awt.event.MouseAdapter JavaDoc;
14 import java.awt.event.MouseEvent JavaDoc;
15
16 /**
17     Listens for mouse clicks and manages linking into the constat pool.
18  
19     @author <a HREF="mailto:jclasslib@ej-technologies.com">Ingo Kegel</a>
20     @version $Revision: 1.6 $ $Date: 2003/08/18 08:02:07 $
21 */

22 public class ConstantPoolHyperlinkListener extends MouseAdapter JavaDoc {
23
24     private BrowserServices services;
25     private int constantPoolIndex;
26
27     /**
28         Constructor.
29         @param services the browser services
30         @param constantPoolIndex the index of the constant pool to lonk to.
31      */

32     public ConstantPoolHyperlinkListener(BrowserServices services, int constantPoolIndex) {
33         
34         this.services = services;
35         this.constantPoolIndex = constantPoolIndex;
36     }
37     
38     public void mouseClicked(MouseEvent JavaDoc event) {
39         link(services, constantPoolIndex);
40     }
41
42     /**
43         Link to a specific constant pool entry.
44         @param services browser services
45         @param constantPoolIndex the index of the constant pool entry
46      */

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 JavaDoc newPath = linkPath(services, constantPoolIndex);
55         tree.setSelectionPath(newPath);
56         tree.scrollPathToVisible(newPath);
57     }
58     
59     private static TreePath JavaDoc linkPath(BrowserServices services, int constantPoolIndex) {
60         
61         TreePath JavaDoc constantPoolPath = services.getBrowserComponent().getTreePane().getPathForCategory(BrowserTreeNode.NODE_CONSTANT_POOL);
62         
63         BrowserTreeNode constantPoolNode = (BrowserTreeNode)constantPoolPath.getLastPathComponent();
64         TreeNode JavaDoc targetNode = constantPoolNode.getChildAt(constantPoolIndex - 1);
65         TreePath JavaDoc linkPath = constantPoolPath.pathByAddingChild(targetNode);
66         
67         return linkPath;
68     }
69     
70 }
71
72
Popular Tags