001: /*
002: * ListTagsFormatter.java
003: *
004: * Copyright (C) 2002 Peter Graves
005: * $Id: ListTagsFormatter.java,v 1.1.1.1 2002/09/24 16:07:43 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: public final class ListTagsFormatter extends Formatter {
025: private static final byte FORMAT_TEXT = 0;
026: private static final byte FORMAT_HEADER_NAME = 1;
027: private static final byte FORMAT_HEADER_VALUE = 2;
028: private static final byte FORMAT_MATCHING_TEXT = 3;
029: private static final byte FORMAT_STATUS = 4;
030: private static final byte FORMAT_VISITED = 5;
031:
032: public ListTagsFormatter(Buffer buffer) {
033: this .buffer = buffer;
034: }
035:
036: public LineSegmentList formatLine(Line line) {
037: clearSegmentList();
038: if (line instanceof TagLine)
039: return formatTagLine((TagLine) line);
040: else if (line instanceof FileLine)
041: return formatFileLine((FileLine) line);
042: else
043: return formatHeaderLine(line);
044: }
045:
046: private LineSegmentList formatHeaderLine(Line line) {
047: final String text = getDetabbedText(line);
048: int index = text.indexOf(':');
049: if (index > 0) {
050: addSegment(text, 0, index + 1, FORMAT_HEADER_NAME);
051: addSegment(text, index + 1, FORMAT_HEADER_VALUE);
052: return segmentList;
053: }
054: addSegment(text, FORMAT_TEXT);
055: return segmentList;
056: }
057:
058: private LineSegmentList formatTagLine(TagLine line) {
059: final String text = getDetabbedText(line);
060: final String name = line.getTag().getMethodName();
061: if (name != null) {
062: int index = text.indexOf(name);
063: if (index >= 0) {
064: if (index > 0)
065: addSegment(text, 0, index, FORMAT_TEXT);
066: addSegment(text, index, index + name.length(),
067: FORMAT_MATCHING_TEXT);
068: if (index + name.length() < text.length())
069: addSegment(text, index + name.length(), FORMAT_TEXT);
070: return segmentList;
071: }
072: }
073: addSegment(text, FORMAT_TEXT);
074: return segmentList;
075: }
076:
077: private LineSegmentList formatFileLine(FileLine line) {
078: final String text = getDetabbedText(line);
079: int index = text.indexOf(':');
080: if (index > 0) {
081: addSegment(text, 0, index + 1, FORMAT_HEADER_NAME);
082: addSegment(text, index + 1, FORMAT_HEADER_VALUE);
083: } else
084: addSegment(text, line.visited() ? FORMAT_VISITED
085: : FORMAT_TEXT);
086: return segmentList;
087: }
088:
089: public FormatTable getFormatTable() {
090: if (formatTable == null) {
091: formatTable = new FormatTable("ListTagsMode");
092: formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
093: formatTable.addEntryFromPrefs(FORMAT_HEADER_NAME,
094: "headerName", "keyword");
095: formatTable.addEntryFromPrefs(FORMAT_HEADER_VALUE,
096: "headerValue", "operator");
097: formatTable.addEntryFromPrefs(FORMAT_MATCHING_TEXT,
098: "matchingText", "function");
099: formatTable.addEntryFromPrefs(FORMAT_STATUS, "status",
100: "comment");
101: formatTable.addEntryFromPrefs(FORMAT_VISITED, "visited",
102: "disabled");
103: }
104: return formatTable;
105: }
106: }
|