KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * ListTagsFormatter.java
3  *
4  * Copyright (C) 2002 Peter Graves
5  * $Id: ListTagsFormatter.java,v 1.1.1.1 2002/09/24 16:07:43 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 public final class ListTagsFormatter extends Formatter
25 {
26     private static final byte FORMAT_TEXT = 0;
27     private static final byte FORMAT_HEADER_NAME = 1;
28     private static final byte FORMAT_HEADER_VALUE = 2;
29     private static final byte FORMAT_MATCHING_TEXT = 3;
30     private static final byte FORMAT_STATUS = 4;
31     private static final byte FORMAT_VISITED = 5;
32
33     public ListTagsFormatter(Buffer buffer)
34     {
35         this.buffer = buffer;
36     }
37
38     public LineSegmentList formatLine(Line line)
39     {
40         clearSegmentList();
41         if (line instanceof TagLine)
42             return formatTagLine((TagLine)line);
43         else if (line instanceof FileLine)
44             return formatFileLine((FileLine)line);
45         else
46             return formatHeaderLine(line);
47     }
48
49     private LineSegmentList formatHeaderLine(Line line)
50     {
51         final String JavaDoc text = getDetabbedText(line);
52         int index = text.indexOf(':');
53         if (index > 0) {
54             addSegment(text, 0, index+1, FORMAT_HEADER_NAME);
55             addSegment(text, index+1, FORMAT_HEADER_VALUE);
56             return segmentList;
57         }
58         addSegment(text, FORMAT_TEXT);
59         return segmentList;
60     }
61
62     private LineSegmentList formatTagLine(TagLine line)
63     {
64         final String JavaDoc text = getDetabbedText(line);
65         final String JavaDoc name = line.getTag().getMethodName();
66         if (name != null) {
67             int index = text.indexOf(name);
68             if (index >= 0) {
69                 if (index > 0)
70                     addSegment(text, 0, index, FORMAT_TEXT);
71                 addSegment(text, index, index + name.length(), FORMAT_MATCHING_TEXT);
72                 if (index + name.length() < text.length())
73                     addSegment(text, index + name.length(), FORMAT_TEXT);
74                 return segmentList;
75             }
76         }
77         addSegment(text, FORMAT_TEXT);
78         return segmentList;
79     }
80
81     private LineSegmentList formatFileLine(FileLine line)
82     {
83         final String JavaDoc text = getDetabbedText(line);
84         int index = text.indexOf(':');
85         if (index > 0) {
86             addSegment(text, 0, index+1, FORMAT_HEADER_NAME);
87             addSegment(text, index+1, FORMAT_HEADER_VALUE);
88         } else
89             addSegment(text, line.visited() ? FORMAT_VISITED : FORMAT_TEXT);
90         return segmentList;
91     }
92
93     public FormatTable getFormatTable()
94     {
95         if (formatTable == null) {
96             formatTable = new FormatTable("ListTagsMode");
97             formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
98             formatTable.addEntryFromPrefs(FORMAT_HEADER_NAME, "headerName", "keyword");
99             formatTable.addEntryFromPrefs(FORMAT_HEADER_VALUE, "headerValue", "operator");
100             formatTable.addEntryFromPrefs(FORMAT_MATCHING_TEXT, "matchingText", "function");
101             formatTable.addEntryFromPrefs(FORMAT_STATUS, "status", "comment");
102             formatTable.addEntryFromPrefs(FORMAT_VISITED, "visited", "disabled");
103         }
104         return formatTable;
105     }
106 }
107
Popular Tags