KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > debug > CommentsNode


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 package org.netbeans.modules.java.debug;
20
21 import java.util.Collections JavaDoc;
22 import java.util.List JavaDoc;
23 import org.netbeans.api.java.source.Comment;
24 import org.netbeans.editor.Coloring;
25 import org.netbeans.modules.editor.highlights.spi.Highlight;
26 import org.openide.nodes.AbstractNode;
27 import org.openide.nodes.Children;
28 import org.openide.nodes.Node;
29
30 /**
31  *
32  * @author Jan Lahoda
33  */

34 public class CommentsNode extends AbstractNode implements Highlight {
35
36     private List JavaDoc<Comment> comments;
37
38     /** Creates a new instance of CommentNode */
39     public CommentsNode(String JavaDoc displayName, List JavaDoc<Comment> comments) {
40         super(new ChildrenImpl(comments));
41         this.comments = comments;
42         setDisplayName(displayName);
43     }
44
45     public int getStart() {
46         int start = Integer.MAX_VALUE;
47         
48         for (Comment c : comments) {
49             if (start > c.pos()) {
50                 start = c.pos();
51             }
52         }
53         
54         return start == Integer.MAX_VALUE ? (-1) : start;
55     }
56
57     public int getEnd() {
58         int end = -1;
59         
60         for (Comment c : comments) {
61             if (end < c.endPos()) {
62                 end = c.endPos();
63             }
64         }
65         
66         return end;
67     }
68
69     public Coloring getColoring() {
70         return TreeNode.HIGHLIGHT;
71     }
72
73     private static final class ChildrenImpl extends Children.Keys {
74
75         private List JavaDoc<Comment> comments;
76         
77         public ChildrenImpl(List JavaDoc<Comment> comments) {
78             this.comments = comments;
79         }
80         
81         public void addNotify() {
82             setKeys(comments);
83         }
84         
85         public void removeNotify() {
86             setKeys(Collections.emptyList());
87         }
88         
89         protected Node[] createNodes(Object JavaDoc key) {
90             return new Node[] {new CommentNode((Comment) key)};
91         }
92         
93     }
94     
95 }
96
Popular Tags