KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > refactoring > java > ui > tree > ElementGrip


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.refactoring.java.ui.tree;
21
22 import com.sun.source.tree.Tree;
23 import com.sun.source.util.TreePath;
24 import javax.lang.model.element.Element;
25 import javax.swing.Icon JavaDoc;
26 import org.netbeans.api.java.source.CompilationInfo;
27 import org.netbeans.api.java.source.TreePathHandle;
28 import org.netbeans.api.java.source.UiUtils;
29 import org.openide.filesystems.FileObject;
30
31 /**
32  *
33  * @author Jan Becicka
34  */

35 public final class ElementGrip {
36     private TreePathHandle delegateElementHandle;
37     private String JavaDoc toString;
38     private FileObject fileObject;
39     private Icon JavaDoc icon;
40     
41     /**
42      * Creates a new instance of ElementGrip
43      */

44     public ElementGrip(TreePath treePath, CompilationInfo info) {
45         this.delegateElementHandle = TreePathHandle.create(treePath, info);
46         this.toString = UiUtils.getHeader(treePath, info, UiUtils.PrintPart.NAME);
47         this.fileObject = info.getFileObject();
48         this.icon = UiUtils.getDeclarationIcon(info.getTrees().getElement(treePath));
49     }
50     
51     public Icon JavaDoc getIcon() {
52         return icon;
53     }
54     public String JavaDoc toString() {
55         return toString;
56     }
57
58     public ElementGrip getParent() {
59         return ElementGripFactory.getDefault().getParent(this);
60     }
61
62     public TreePath resolve(CompilationInfo info) {
63         return delegateElementHandle.resolve(info);
64     }
65
66     public Element resolveElement(CompilationInfo info) {
67         return delegateElementHandle.resolveElement(info);
68     }
69
70     public Tree.Kind getKind() {
71         return delegateElementHandle.getKind();
72     }
73     
74     public FileObject getFileObject() {
75         return fileObject;
76     }
77     
78     public TreePathHandle getHandle() {
79         return delegateElementHandle;
80     }
81     
82 }
83
Popular Tags