01: /*
02: * P4ChangelistFormatter.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: P4ChangelistFormatter.java,v 1.1.1.1 2002/09/24 16:09:02 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * 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 P4ChangelistFormatter extends Formatter {
25: private static final byte FORMAT_TEXT = 0;
26: private static final byte FORMAT_COMMENT = 1;
27: private static final byte FORMAT_KEY = 2;
28: private static final byte FORMAT_VALUE = 3;
29:
30: public P4ChangelistFormatter(Buffer buffer) {
31: this .buffer = buffer;
32: }
33:
34: public LineSegmentList formatLine(Line line) {
35: clearSegmentList();
36: String text = getDetabbedText(line);
37: final String comment;
38: int hash = text.indexOf('#');
39: if (hash >= 0) {
40: comment = text.substring(hash);
41: text = text.substring(0, hash);
42: } else
43: comment = null;
44: int colon = text.indexOf(':');
45: if (colon >= 0) {
46: int space = text.indexOf('\t');
47: if (space < 0)
48: space = text.indexOf(' ');
49: if (space < 0 || colon < space) {
50: addSegment(text, 0, colon + 1, FORMAT_KEY);
51: addSegment(text, colon + 1, FORMAT_VALUE);
52: } else
53: addSegment(text, FORMAT_TEXT);
54: } else
55: addSegment(text, FORMAT_TEXT);
56: if (comment != null)
57: addSegment(comment, FORMAT_COMMENT);
58: return segmentList;
59: }
60:
61: public FormatTable getFormatTable() {
62: if (formatTable == null) {
63: formatTable = new FormatTable("P4Changelist");
64: formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
65: formatTable.addEntryFromPrefs(FORMAT_COMMENT, "comment");
66: formatTable
67: .addEntryFromPrefs(FORMAT_KEY, "key", "function");
68: formatTable
69: .addEntryFromPrefs(FORMAT_VALUE, "value", "text");
70: }
71: return formatTable;
72: }
73: }
|