| 1 |
#import "MailTextFormatManager.h" |
| 2 |
#import "TextFormatter.h" |
| 3 |
#import "LineTextFormatter.h" |
| 4 |
static MailTextFormatManager *mailTextFormatManager; |
| 5 |
@implementation MailTextFormatManager |
| 6 |
+(MailTextFormatManager *)sharedMailTextFormatManager{ |
| 7 |
// 暫定実装。本当は、ユーザーに設定させるべきもの。 |
| 8 |
if(!mailTextFormatManager){ |
| 9 |
mailTextFormatManager = [[MailTextFormatManager alloc] init]; |
| 10 |
[mailTextFormatManager addHeaderTextFormatter: |
| 11 |
[[TextFormatter alloc] initWithName:@"default" |
| 12 |
pattern:@"" |
| 13 |
foregroundColor:[NSColor blackColor] |
| 14 |
backgroundColor:[NSColor whiteColor] |
| 15 |
font:[NSFont fontWithName:@"HiraKakuPro-W3" size:13.0]]]; |
| 16 |
[mailTextFormatManager addContentsTextFormatter: |
| 17 |
[[TextFormatter alloc] initWithName:@"default" |
| 18 |
pattern:@"" |
| 19 |
foregroundColor:[NSColor blackColor] |
| 20 |
backgroundColor:[NSColor whiteColor] |
| 21 |
font:[NSFont fontWithName:@"HiraKakuPro-W3" size:12.0]]]; |
| 22 |
|
| 23 |
[mailTextFormatManager addContentsTextFormatter: |
| 24 |
[[LineTextFormatter alloc] initWithName:@"inyo" |
| 25 |
pattern:@">" |
| 26 |
foregroundColor:[NSColor colorWithCalibratedRed:0.26 |
| 27 |
green:0.28 |
| 28 |
blue:1.0 |
| 29 |
alpha:1.0] |
| 30 |
backgroundColor:[NSColor whiteColor] |
| 31 |
font:[NSFont fontWithName:@"HiraKakuPro-W3" size:12.0]]]; |
| 32 |
} |
| 33 |
return mailTextFormatManager; |
| 34 |
} |
| 35 |
-(id)init{ |
| 36 |
self = [super init]; |
| 37 |
_headerFormatter = [[NSMutableArray alloc] init]; |
| 38 |
_contentsFormatter = [[NSMutableArray alloc] init]; |
| 39 |
return self; |
| 40 |
} |
| 41 |
-(id)initWithHeaderFormatter:(NSArray *)headerFormatter |
| 42 |
contentsFormatter:(NSArray *)contentsFormatter{ |
| 43 |
self = [super init]; |
| 44 |
_headerFormatter = [headerFormatter retain]; |
| 45 |
_contentsFormatter = [contentsFormatter retain]; |
| 46 |
return self; |
| 47 |
} |
| 48 |
-(void)dealloc{ |
| 49 |
[_headerFormatter release]; |
| 50 |
[_contentsFormatter release]; |
| 51 |
[super dealloc]; |
| 52 |
} |
| 53 |
-(void)addHeaderTextFormatter:(TextFormatter *)textFormatter{ |
| 54 |
[_headerFormatter addObject:textFormatter]; |
| 55 |
} |
| 56 |
-(void)addContentsTextFormatter:(TextFormatter *)textFormatter{ |
| 57 |
[_contentsFormatter addObject:textFormatter]; |
| 58 |
} |
| 59 |
-(void)removeHeaderTextFormatter:(TextFormatter *)textFormatter{ |
| 60 |
[_headerFormatter removeObject:textFormatter]; |
| 61 |
} |
| 62 |
-(void)removeContentsTextFormatter:(TextFormatter *)textFormatter{ |
| 63 |
[_contentsFormatter removeObject:textFormatter]; |
| 64 |
} |
| 65 |
-(unsigned int)countHeaderTextFormatter{ |
| 66 |
return [_headerFormatter count]; |
| 67 |
} |
| 68 |
-(unsigned int)countContentsTextFormatter{ |
| 69 |
return [_contentsFormatter count]; |
| 70 |
} |
| 71 |
-(void)insertHeaderTextFormatter:(TextFormatter *)textFormatter |
| 72 |
atIndex:(unsigned int)index{ |
| 73 |
if(index < [_headerFormatter count]){ |
| 74 |
index = [_headerFormatter count]; |
| 75 |
} |
| 76 |
[_headerFormatter insertObject:textFormatter atIndex:index]; |
| 77 |
} |
| 78 |
-(void)insertContentsTextFormatter:(TextFormatter *)textFormatter |
| 79 |
atIndex:(unsigned int)index{ |
| 80 |
if(index < [_contentsFormatter count]){ |
| 81 |
index = [_contentsFormatter count]; |
| 82 |
} |
| 83 |
[_contentsFormatter insertObject:textFormatter atIndex:index]; |
| 84 |
} |
| 85 |
-(unsigned int)indexOfHeaderTextFormatter:(TextFormatter *)textFormatter{ |
| 86 |
return [_headerFormatter indexOfObject:textFormatter]; |
| 87 |
} |
| 88 |
-(unsigned int)indexOfContentsTextFormatter:(TextFormatter *)textFormatter{ |
| 89 |
return [_contentsFormatter indexOfObject:textFormatter]; |
| 90 |
} |
| 91 |
-(NSAttributedString *)formatHeader:(NSString *)string{ |
| 92 |
unsigned int i; |
| 93 |
NSAttributedString *attributedString |
| 94 |
= [[NSAttributedString alloc]initWithString:string]; |
| 95 |
for(i = 0; i < [_headerFormatter count]; i++){ |
| 96 |
attributedString = [[_headerFormatter objectAtIndex:i] |
| 97 |
formatWithAttributedString:attributedString]; |
| 98 |
} |
| 99 |
return attributedString; |
| 100 |
} |
| 101 |
-(NSAttributedString *)formatContents:(NSString *)string{ |
| 102 |
unsigned int i; |
| 103 |
NSAttributedString *attributedString |
| 104 |
= [[NSAttributedString alloc] initWithString:string]; |
| 105 |
for(i = 0; i < [_contentsFormatter count]; i++){ |
| 106 |
attributedString = [[_contentsFormatter objectAtIndex:i] |
| 107 |
formatWithAttributedString:attributedString]; |
| 108 |
} |
| 109 |
return attributedString; |
| 110 |
} |
| 111 |
@end |