001: /*
002: * MailboxFormatter.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: MailboxFormatter.java,v 1.1.1.1 2002/09/24 16:10:09 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.mail;
023:
024: import org.armedbear.j.Formatter;
025: import org.armedbear.j.Buffer;
026: import org.armedbear.j.Editor;
027: import org.armedbear.j.Line;
028: import org.armedbear.j.LineSegment;
029: import org.armedbear.j.LineSegmentList;
030: import org.armedbear.j.Property;
031: import org.armedbear.j.Utilities;
032: import org.armedbear.j.FormatTable;
033:
034: public final class MailboxFormatter extends Formatter {
035: private static final boolean SHOW_MESSAGE_NUMBERS = Editor
036: .preferences().getBooleanProperty(
037: Property.SHOW_MESSAGE_NUMBERS);
038:
039: private static final byte FORMAT_TEXT = 0;
040: private static final byte FORMAT_DELETED = 1;
041: private static final byte FORMAT_TAGGED = 2;
042:
043: private static final byte FORMAT_TO = 3; // '+', 'T', 'C', 'F', '!'
044: private static final byte FORMAT_FLAGS = 4;
045: private static final byte FORMAT_DATE = 5;
046: private static final byte FORMAT_FROM = 6;
047: private static final byte FORMAT_SIZE = 7;
048: private static final byte FORMAT_SUBJECT = 8;
049:
050: private static final byte FORMAT_FLAGGED_TO = 9;
051: private static final byte FORMAT_FLAGGED_FLAGS = 10;
052: private static final byte FORMAT_FLAGGED_DATE = 11;
053: private static final byte FORMAT_FLAGGED_FROM = 12;
054: private static final byte FORMAT_FLAGGED_SIZE = 13;
055: private static final byte FORMAT_FLAGGED_SUBJECT = 14;
056:
057: private static final int TO_COLUMN_WIDTH = 2;
058: private static final int FLAGS_COLUMN_WIDTH = 3;
059: private static final int DATE_COLUMN_WIDTH = 14;
060: private static final int FROM_COLUMN_WIDTH = 22;
061: private static final int SIZE_COLUMN_WIDTH = 6;
062:
063: private static final int TO_COLUMN = SHOW_MESSAGE_NUMBERS ? 6 : 0;
064: private static final int FLAGS_COLUMN = TO_COLUMN + TO_COLUMN_WIDTH;
065: private static final int DATE_COLUMN = FLAGS_COLUMN
066: + FLAGS_COLUMN_WIDTH;
067: private static final int FROM_COLUMN = DATE_COLUMN
068: + DATE_COLUMN_WIDTH;
069: private static final int SIZE_COLUMN = FROM_COLUMN
070: + FROM_COLUMN_WIDTH;
071: private static final int SUBJECT_COLUMN = SIZE_COLUMN
072: + SIZE_COLUMN_WIDTH;
073:
074: public MailboxFormatter(Buffer buffer) {
075: this .buffer = buffer;
076: }
077:
078: public LineSegmentList formatLine(Line line) {
079: String text;
080: if (Editor.tabsAreVisible())
081: text = Utilities.makeTabsVisible(line.getText(), buffer
082: .getTabWidth());
083: else
084: text = Utilities
085: .detab(line.getText(), buffer.getTabWidth());
086: clearSegmentList();
087: if (line instanceof MailboxLine) {
088: MailboxEntry entry = ((MailboxLine) line).getMailboxEntry();
089: if (entry.isTagged()) {
090: addSegment(text, FORMAT_TAGGED);
091: } else if (entry.isDeleted()) {
092: addSegment(text, FORMAT_DELETED);
093: } else if (entry.isFlagged()) {
094: if (TO_COLUMN > 0)
095: addSegment(text, 0, TO_COLUMN, FORMAT_TEXT);
096: addSegment(text, TO_COLUMN, FLAGS_COLUMN,
097: FORMAT_FLAGGED_TO);
098: addSegment(text, FLAGS_COLUMN, DATE_COLUMN,
099: FORMAT_FLAGGED_FLAGS);
100: addSegment(text, DATE_COLUMN, FROM_COLUMN,
101: FORMAT_FLAGGED_DATE);
102: addSegment(text, FROM_COLUMN, SIZE_COLUMN,
103: FORMAT_FLAGGED_FROM);
104: addSegment(text, SIZE_COLUMN, SUBJECT_COLUMN,
105: FORMAT_FLAGGED_SIZE);
106: addSegment(text, SUBJECT_COLUMN, FORMAT_FLAGGED_SUBJECT);
107: } else {
108: // Not flagged.
109: if (TO_COLUMN > 0)
110: addSegment(text, 0, TO_COLUMN, FORMAT_TEXT);
111: addSegment(text, TO_COLUMN, FLAGS_COLUMN, FORMAT_TO);
112: addSegment(text, FLAGS_COLUMN, DATE_COLUMN,
113: FORMAT_FLAGS);
114: addSegment(text, DATE_COLUMN, FROM_COLUMN, FORMAT_DATE);
115: addSegment(text, FROM_COLUMN, SIZE_COLUMN, FORMAT_FROM);
116: addSegment(text, SIZE_COLUMN, SUBJECT_COLUMN,
117: FORMAT_SIZE);
118: addSegment(text, SUBJECT_COLUMN, FORMAT_SUBJECT);
119: }
120: } else
121: addSegment(text, FORMAT_TEXT);
122: return segmentList;
123: }
124:
125: public FormatTable getFormatTable() {
126: if (formatTable == null) {
127: formatTable = new FormatTable("MailboxMode");
128: formatTable.addEntryFromPrefs(FORMAT_TEXT, "text");
129: formatTable.addEntryFromPrefs(FORMAT_DELETED, "deleted",
130: "disabled");
131: formatTable.addEntryFromPrefs(FORMAT_TAGGED, "marked");
132: formatTable.addEntryFromPrefs(FORMAT_TO, "to", "function");
133: formatTable
134: .addEntryFromPrefs(FORMAT_FLAGS, "flags", "text");
135: formatTable.addEntryFromPrefs(FORMAT_DATE, "date",
136: "keyword");
137: formatTable.addEntryFromPrefs(FORMAT_FROM, "from",
138: "function");
139: formatTable.addEntryFromPrefs(FORMAT_SIZE, "size", "text");
140: formatTable.addEntryFromPrefs(FORMAT_SUBJECT, "subject",
141: "string");
142: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_TO,
143: "flaggedTo", "to");
144: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_FLAGS,
145: "flaggedFlags", "flags");
146: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_DATE,
147: "flaggedDate", "date");
148: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_FROM,
149: "flaggedFrom", "from");
150: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_SIZE,
151: "flaggedSize", "size");
152: formatTable.addEntryFromPrefs(FORMAT_FLAGGED_SUBJECT,
153: "flaggedSubject", "subject");
154: }
155: return formatTable;
156: }
157: }
|