1 21 22 package org.armedbear.j; 23 24 import java.util.Iterator ; 25 import java.util.List ; 26 27 public final class ListTagsBuffer extends Buffer 28 { 29 private final String name; private Marker marker; 31 32 private String lastFileName; 33 private String lastClassName; 34 35 public ListTagsBuffer(Editor editor, String command, String name, List tags) 36 { 37 super(); 38 this.name = name; 39 if (editor.getBuffer().getFile() != null) 40 marker = new Marker(editor.getBuffer(), editor.getDot()); 41 initializeUndo(); 42 type = TYPE_LIST_OCCURRENCES; 43 mode = ListTagsMode.getMode(); 44 formatter = mode.getFormatter(this); 45 readOnly = true; 46 setTransient(true); 47 load(tags); 48 FastStringBuffer sb = new FastStringBuffer(command); 49 sb.append(" \""); 50 sb.append(name); 51 sb.append('"'); 52 title = sb.toString(); 53 setInitialized(true); 54 } 55 56 public Position getInitialDotPos() 57 { 58 for (Line line = getFirstLine(); line != null; line = line.next()) { 59 if (line instanceof TagLine) 60 return new Position(line, 0); 61 } 62 return new Position(getFirstLine(), 0); 63 } 64 65 private void load(List tags) 66 { 67 try { 68 lockWrite(); 69 } 70 catch (InterruptedException e) { 71 Log.debug(e); 72 return; 73 } 74 try { 75 lastFileName = lastClassName = null; 76 appendLine("Tag: \"" + name + '"'); 77 Iterator iter = tags.iterator(); 78 while (iter.hasNext()) { 79 Tag tag = (Tag) iter.next(); 80 appendTag(tag); 81 } 82 renumber(); 83 setLoaded(true); 84 } 85 finally { 86 unlockWrite(); 87 } 88 } 89 90 private void appendTag(Tag tag) 91 { 92 if (tag instanceof GlobalTag) { 95 String fileName = ((GlobalTag)tag).getFileName(); 96 if (fileName != null && !fileName.equals(lastFileName)) { 97 appendLine(new FileLine(fileName)); 98 lastFileName = fileName; 99 lastClassName = null; 100 } 101 } 102 String className = tag.getClassName(); 103 if (className != null && !className.equals(lastClassName)) { 104 appendLine("Class: ".concat(className)); 105 lastClassName = className; 106 } 107 appendLine(new TagLine(tag)); 108 } 109 110 public void jumpToTag(Editor editor, boolean killList) 111 { 112 if (editor.getDot() == null) 113 return; 114 final Line dotLine = editor.getDotLine(); 115 if (!(dotLine instanceof TagLine)) 116 return; 117 final Tag tag = ((TagLine)dotLine).getTag(); 118 if (tag == null) { 119 Debug.bug(); 120 return; 121 } 122 Editor ed = editor.getOtherEditor(); 123 if (ed == null) 124 ed = editor; 125 if (marker != null) 126 ed.pushMarker(marker); 127 tag.gotoTag(ed); 128 if (killList) { 129 Editor otherEditor = ed.getOtherEditor(); 130 if (otherEditor != null) 131 ed.getFrame().closeEditor(otherEditor); 132 kill(); 133 } 134 } 135 } 136 | Popular Tags |