KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > ListTagsBuffer


1 /*
2  * ListTagsBuffer.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: ListTagsBuffer.java,v 1.2 2002/10/10 17:51:47 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26
27 public final class ListTagsBuffer extends Buffer
28 {
29     private final String JavaDoc name; // The tag name.
30
private Marker marker;
31
32     private String JavaDoc lastFileName;
33     private String JavaDoc lastClassName;
34
35     public ListTagsBuffer(Editor editor, String JavaDoc command, String JavaDoc name, List JavaDoc 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 JavaDoc tags)
66     {
67         try {
68             lockWrite();
69         }
70         catch (InterruptedException JavaDoc e) {
71             Log.debug(e);
72             return;
73         }
74         try {
75             lastFileName = lastClassName = null;
76             appendLine("Tag: \"" + name + '"');
77             Iterator JavaDoc 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         // In the current implementation, the tags for a given file will be
93
// grouped together in the tag file.
94
if (tag instanceof GlobalTag) {
95             String JavaDoc 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 JavaDoc 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