01: /*
02: * JdbFormatter.java
03: *
04: * Copyright (C) 2000-2003 Peter Graves
05: * $Id: JdbFormatter.java,v 1.4 2003/05/23 17:42:47 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.jdb;
23:
24: import org.armedbear.j.Buffer;
25: import org.armedbear.j.Editor;
26: import org.armedbear.j.FormatTable;
27: import org.armedbear.j.Formatter;
28: import org.armedbear.j.Line;
29: import org.armedbear.j.LineSegmentList;
30: import org.armedbear.j.Utilities;
31:
32: public final class JdbFormatter extends Formatter {
33: private static final String prompt = Jdb.getPrompt();
34: private static final int promptLength = prompt.length();
35:
36: // Formats.
37: public static final byte JDB_FORMAT_TEXT = 0;
38: public static final byte JDB_FORMAT_PROMPT = 1;
39: public static final byte JDB_FORMAT_INPUT = 2;
40: public static final byte JDB_FORMAT_OUTPUT = 3;
41: public static final byte JDB_FORMAT_LOG = 4;
42:
43: public JdbFormatter(Buffer buffer) {
44: this .buffer = buffer;
45: }
46:
47: public LineSegmentList formatLine(Line line) {
48: clearSegmentList();
49: if (line == null) {
50: addSegment("", JDB_FORMAT_TEXT);
51: return segmentList;
52: }
53: int flags = line.flags();
54: String text = getDetabbedText(line);
55: if (flags == JDB_FORMAT_OUTPUT) {
56: addSegment(text, JDB_FORMAT_OUTPUT);
57: } else if (text.startsWith(prompt)) {
58: addSegment(text, 0, promptLength, JDB_FORMAT_PROMPT);
59: if (text.length() > promptLength)
60: addSegment(text, promptLength, JDB_FORMAT_INPUT);
61: } else
62: addSegment(text, JDB_FORMAT_LOG);
63: return segmentList;
64: }
65:
66: public FormatTable getFormatTable() {
67: if (formatTable == null) {
68: formatTable = new FormatTable("JdbMode");
69: formatTable.addEntryFromPrefs(JDB_FORMAT_TEXT, "text");
70: formatTable.addEntryFromPrefs(JDB_FORMAT_PROMPT, "prompt");
71: formatTable.addEntryFromPrefs(JDB_FORMAT_INPUT, "input");
72: formatTable.addEntryFromPrefs(JDB_FORMAT_OUTPUT, "output",
73: "text");
74: formatTable.addEntryFromPrefs(JDB_FORMAT_LOG, "log",
75: "comment");
76: }
77: return formatTable;
78: }
79: }
|