1 19 package org.netbeans.modules.java.editor.overridden; 20 21 import java.awt.Point ; 22 import java.awt.Toolkit ; 23 import java.util.ArrayList ; 24 import java.util.Collections ; 25 import java.util.List ; 26 import javax.swing.SwingUtilities ; 27 import javax.swing.text.JTextComponent ; 28 import javax.swing.text.Position ; 29 import javax.swing.text.StyledDocument ; 30 import org.netbeans.api.java.source.UiUtils; 31 import org.openide.filesystems.FileObject; 32 import org.openide.text.Annotation; 33 import org.openide.text.NbDocument; 34 import org.openide.util.NbBundle; 35 36 40 class IsOverriddenAnnotation extends Annotation { 41 42 private StyledDocument document; 43 private Position pos; 44 private String shortDescription; 45 private AnnotationType type; 46 private List <ElementDescription> declarations; 47 48 public IsOverriddenAnnotation(StyledDocument document, Position pos, AnnotationType type, String shortDescription, List <ElementDescription> declarations) { 49 this.document = document; 50 this.pos = pos; 51 this.type = type; 52 this.shortDescription = shortDescription; 53 this.declarations = declarations; 54 } 55 56 public String getShortDescription() { 57 return shortDescription; 58 } 59 60 public String getAnnotationType() { 61 switch(type) { 62 case IS_OVERRIDDEN: 63 64 return "org-netbeans-modules-editor-java-is_overridden"; 65 case HAS_IMPLEMENTATION: 66 67 return "org-netbeans-modules-editor-java-has_implementations"; 68 case IMPLEMENTS: 69 70 return "org-netbeans-modules-editor-java-implements"; 71 case OVERRIDES: 72 73 return "org-netbeans-modules-editor-java-overrides"; 74 default: 75 76 throw new IllegalStateException ("Currently not implemented: " + type); 77 } 78 } 79 80 public void attach() { 81 NbDocument.addAnnotation(document, pos, -1, this); 82 } 83 84 public void detachImpl() { 85 NbDocument.removeAnnotation(document, this); 86 } 87 88 public String toString() { 89 return "[IsOverriddenAnnotation: " + shortDescription + "]"; 90 } 91 92 public Position getPosition() { 93 return pos; 94 } 95 96 public String debugDump() { 97 List <String > elementNames = new ArrayList <String >(); 98 99 for(ElementDescription desc : declarations) { 100 elementNames.add(desc.getDisplayName()); 101 } 102 103 Collections.sort(elementNames); 104 105 return "IsOverriddenAnnotation: type=" + type.name() + ", elements:" + elementNames.toString(); 106 } 107 108 void mouseClicked(JTextComponent c, Point p) { 109 Point position = new Point (p); 110 111 SwingUtilities.convertPointToScreen(position, c); 112 113 performGoToAction(type, declarations, position, shortDescription); 114 } 115 116 static void performGoToAction(AnnotationType type, List <ElementDescription> declarations, Point position, String shortDescription) { 117 if (type == AnnotationType.IMPLEMENTS || type == AnnotationType.OVERRIDES) { 118 if (declarations.size() == 1) { 119 ElementDescription desc = declarations.get(0); 120 FileObject file = desc.getSourceFile(); 121 122 if (file != null) { 123 UiUtils.open(file, desc.getHandle()); 124 } else { 125 Toolkit.getDefaultToolkit().beep(); 126 } 127 128 return ; 129 } 130 } 131 132 String caption; 133 134 switch (type) { 135 case IMPLEMENTS: 136 caption = NbBundle.getMessage(IsOverriddenAnnotation.class, "CAP_Implements"); 137 break; 138 case OVERRIDES: 139 caption = NbBundle.getMessage(IsOverriddenAnnotation.class, "CAP_Overrides"); 140 break; 141 case HAS_IMPLEMENTATION: 142 case IS_OVERRIDDEN: 143 caption = shortDescription; 144 break; 145 default: 146 throw new IllegalStateException ("Currently not implemented: " + type); 147 } 148 149 PopupUtil.showPopup(new IsOverriddenPopup(caption, declarations), caption, position.x, position.y, true, 0); 150 } 151 } | Popular Tags |