1 19 package org.netbeans.modules.java.debug; 20 21 import java.util.Collections ; 22 import java.util.List ; 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 34 public class CommentsNode extends AbstractNode implements Highlight { 35 36 private List <Comment> comments; 37 38 39 public CommentsNode(String displayName, List <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 <Comment> comments; 76 77 public ChildrenImpl(List <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 key) { 90 return new Node[] {new CommentNode((Comment) key)}; 91 } 92 93 } 94 95 } 96 | Popular Tags |