1 21 22 package org.armedbear.j; 23 24 import java.awt.Component ; 25 import java.awt.Graphics ; 26 import javax.swing.Icon ; 27 import javax.swing.ImageIcon ; 28 import javax.swing.undo.CompoundEdit ; 29 30 public class LocalTag extends Tag implements Constants 31 { 32 private final Position pos; 33 private final int type; 34 private int flags; 35 36 protected LocalTag(String name, Line line) 37 { 38 super(name, line.getText()); 39 pos = new Position(line, 0); 40 type = TAG_METHOD; 41 } 42 43 protected LocalTag(String name, Position pos) 44 { 45 super(name, pos.getLine().getText()); 46 this.pos = new Position(pos); 47 type = TAG_METHOD; 48 } 49 50 protected LocalTag(String name, Position pos, int type, int flags) 51 { 52 super(name, pos.getLine().getText()); 53 this.pos = new Position(pos); 54 this.type = type; 55 this.flags = flags; 56 } 57 58 protected LocalTag(String name, Position pos, int type) 59 { 60 super(name, pos.getLine().getText()); 61 this.pos = new Position(pos); 62 this.type = type; 63 } 64 65 public String getMethodName() 66 { 67 return name; 68 } 69 70 public String getLongName() 71 { 72 return name; 73 } 74 75 public String getClassName() 76 { 77 return null; 78 } 79 80 public final Position getPosition() 81 { 82 return pos; 83 } 84 85 public final Line getLine() 86 { 87 return pos.getLine(); 88 } 89 90 public final int lineNumber() 91 { 92 return pos.lineNumber(); 93 } 94 95 public final int getType() 96 { 97 return type; 98 } 99 100 public final boolean isPublic() 101 { 102 return (flags & TAG_VISIBILITY_MASK) == TAG_PUBLIC; 103 } 104 105 public final boolean isProtected() 106 { 107 return (flags & TAG_VISIBILITY_MASK) == TAG_PROTECTED; 108 } 109 110 public final boolean isPrivate() 111 { 112 return (flags & TAG_VISIBILITY_MASK) == TAG_PRIVATE; 113 } 114 115 private static ImageIcon interfaceIcon; 116 private static ImageIcon classIcon; 117 private static ImageIcon methodIcon; 118 private static ImageIcon fieldIcon; 119 120 private static ImageIcon publicIcon; 121 private static ImageIcon protectedIcon; 122 private static ImageIcon privateIcon; 123 124 public Icon getIcon() 125 { 126 ImageIcon base = null; 127 ImageIcon overlay = null; 128 switch (type) { 129 case TAG_INTERFACE: 130 case TAG_IMPLEMENTS: 131 case TAG_TYPE: if (interfaceIcon == null) 133 interfaceIcon = Utilities.getIconFromFile("interface.png"); 134 base = interfaceIcon; 135 break; 136 case TAG_CLASS: 137 case TAG_EXTENDS: 138 case TAG_CONDITION: case TAG_STRUCT: if (classIcon == null) 141 classIcon = Utilities.getIconFromFile("class.png"); 142 base = classIcon; 143 break; 144 case TAG_METHOD: 145 case TAG_MACRO: case TAG_DEFUN: default: 148 if (methodIcon == null) 149 methodIcon = Utilities.getIconFromFile("method.png"); 150 base = methodIcon; 151 break; 152 case TAG_FIELD: 153 case TAG_CONSTANT: case TAG_PARAMETER: case TAG_VAR: if (fieldIcon == null) 157 fieldIcon = Utilities.getIconFromFile("field.png"); 158 base = fieldIcon; 159 break; 160 } 161 if (isPublic()) { 162 if (publicIcon == null) 163 publicIcon = Utilities.getIconFromFile("public.png"); 164 overlay = publicIcon; 165 } else if (isProtected()) { 166 if (protectedIcon == null) 167 protectedIcon = Utilities.getIconFromFile("protected.png"); 168 overlay = protectedIcon; 169 } else if (isPrivate()) { 170 if (privateIcon == null) 171 privateIcon = Utilities.getIconFromFile("private.png"); 172 overlay = privateIcon; 173 } 174 return new OverlayIcon(base, overlay); 175 } 176 177 public String toString() 178 { 179 return getMethodName(); 180 } 181 182 public String getSidebarText() 183 { 184 return getMethodName(); 185 } 186 187 public String getToolTipText() 188 { 189 return getLongName(); 190 } 191 192 public void gotoTag(Editor editor) 193 { 194 if (editor.getBuffer().contains(pos.getLine())) { 195 CompoundEdit compoundEdit = editor.beginCompoundEdit(); 196 editor.addUndo(SimpleEdit.FOLD); 197 editor.unfoldMethod(pos.getLine()); 198 editor.moveDotTo(pos); 199 TagCommands.centerTag(editor); 200 editor.endCompoundEdit(compoundEdit); 201 editor.getBuffer().repaint(); 202 editor.updateDisplay(); 203 } 204 } 205 206 private static class OverlayIcon extends ImageIcon 207 { 208 private ImageIcon base; 209 private ImageIcon overlay; 210 211 private OverlayIcon(ImageIcon base, ImageIcon overlay) 212 { 213 this.base = base; 214 this.overlay = overlay; 215 } 216 217 public synchronized void paintIcon(Component c, Graphics g, int x, int y) 218 { 219 if (base != null) 220 base.paintIcon(c, g, x, y); 221 if (overlay != null) 222 overlay.paintIcon(c, g, x, y); 223 } 224 225 public final int getIconWidth() 226 { 227 return base.getIconWidth(); 228 } 229 230 public final int getIconHeight() 231 { 232 return base.getIconHeight(); 233 } 234 } 235 } 236 | Popular Tags |