001: /*
002: * ListTagsBuffer.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: ListTagsBuffer.java,v 1.2 2002/10/10 17:51:47 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.util.Iterator;
025: import java.util.List;
026:
027: public final class ListTagsBuffer extends Buffer {
028: private final String name; // The tag name.
029: private Marker marker;
030:
031: private String lastFileName;
032: private String lastClassName;
033:
034: public ListTagsBuffer(Editor editor, String command, String name,
035: List tags) {
036: super ();
037: this .name = name;
038: if (editor.getBuffer().getFile() != null)
039: marker = new Marker(editor.getBuffer(), editor.getDot());
040: initializeUndo();
041: type = TYPE_LIST_OCCURRENCES;
042: mode = ListTagsMode.getMode();
043: formatter = mode.getFormatter(this );
044: readOnly = true;
045: setTransient(true);
046: load(tags);
047: FastStringBuffer sb = new FastStringBuffer(command);
048: sb.append(" \"");
049: sb.append(name);
050: sb.append('"');
051: title = sb.toString();
052: setInitialized(true);
053: }
054:
055: public Position getInitialDotPos() {
056: for (Line line = getFirstLine(); line != null; line = line
057: .next()) {
058: if (line instanceof TagLine)
059: return new Position(line, 0);
060: }
061: return new Position(getFirstLine(), 0);
062: }
063:
064: private void load(List tags) {
065: try {
066: lockWrite();
067: } catch (InterruptedException e) {
068: Log.debug(e);
069: return;
070: }
071: try {
072: lastFileName = lastClassName = null;
073: appendLine("Tag: \"" + name + '"');
074: Iterator iter = tags.iterator();
075: while (iter.hasNext()) {
076: Tag tag = (Tag) iter.next();
077: appendTag(tag);
078: }
079: renumber();
080: setLoaded(true);
081: } finally {
082: unlockWrite();
083: }
084: }
085:
086: private void appendTag(Tag tag) {
087: // In the current implementation, the tags for a given file will be
088: // grouped together in the tag file.
089: if (tag instanceof GlobalTag) {
090: String fileName = ((GlobalTag) tag).getFileName();
091: if (fileName != null && !fileName.equals(lastFileName)) {
092: appendLine(new FileLine(fileName));
093: lastFileName = fileName;
094: lastClassName = null;
095: }
096: }
097: String className = tag.getClassName();
098: if (className != null && !className.equals(lastClassName)) {
099: appendLine("Class: ".concat(className));
100: lastClassName = className;
101: }
102: appendLine(new TagLine(tag));
103: }
104:
105: public void jumpToTag(Editor editor, boolean killList) {
106: if (editor.getDot() == null)
107: return;
108: final Line dotLine = editor.getDotLine();
109: if (!(dotLine instanceof TagLine))
110: return;
111: final Tag tag = ((TagLine) dotLine).getTag();
112: if (tag == null) {
113: Debug.bug();
114: return;
115: }
116: Editor ed = editor.getOtherEditor();
117: if (ed == null)
118: ed = editor;
119: if (marker != null)
120: ed.pushMarker(marker);
121: tag.gotoTag(ed);
122: if (killList) {
123: Editor otherEditor = ed.getOtherEditor();
124: if (otherEditor != null)
125: ed.getFrame().closeEditor(otherEditor);
126: kill();
127: }
128: }
129: }
|