-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBCTableWebView.m
153 lines (85 loc) · 3.26 KB
/
BCTableWebView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// BCTableWebView.m
// Bartender
//
// Created by Tom Houpt on 12/7/15.
// Copyright 2012 Behavioral Cybernetics LLC. All rights reserved.
//
#import "BCTableWebView.h"
#import "DailyData.h"
#import "BarExperiment.h"
@implementation BCTableWebView
-(id)initWithTableView:(NSTableView *)table; {
NSRect frameRect = NSMakeRect(0,0,490,720);
// NOTE: this should be paper size?
// or should it be calculated from size of NSTableView?
self = [super initWithFrame:frameRect frameName:nil groupName:nil];
if (self) {
tableView = table;
if (nil == htmlString) {
htmlString = [[NSMutableString alloc] init];
[self appendDailyDataInfoToString:htmlString];
[self appendHtmlFromTableToString:htmlString];
[[self mainFrame] loadHTMLString:htmlString baseURL:nil];
}
}
return self;
}
-(void) appendDailyDataInfoToString:(NSMutableString *)buffer; {
// expt_code: expt_name
[buffer appendFormat:@"<P><STRONG>%@</STRONG></P>",[[dailyData theExperiment] codeName]];
// Days completed: expt_days
[buffer appendFormat:@"<P>Days completed: %ld</P>", [[dailyData theExperiment] numberOfDays]];
// Phase: phase name; Day phase_day
[buffer appendFormat:@"<P>Phase: %@ Day %ld</P>", [dailyData phaseName], [dailyData phaseDayIndex]];
// weighed on:
[buffer appendFormat:@"<P>Weighed on: %@</P>", [dailyData onTimeString]];
// weighed off:
[buffer appendFormat:@"<P>Weighed off: %@</P>", [dailyData onTimeString]];
}
- (void) appendHtmlFromTableToString:(NSMutableString *)buffer; {
[buffer appendString: @"<table>\r"];
[self appendHeadersToString:buffer];
NSInteger rowIndex;
NSInteger numRows = [tableView numberOfRows];
for (rowIndex=0;rowIndex<numRows;rowIndex++) {
[self appendRowAtIndex:rowIndex toString:buffer];
}
[buffer appendString: @"</table>\r"];
}
-(void)appendHeadersToString:(NSMutableString *)buffer; {
[buffer appendString: @"\t<TR>\r"];
for (NSTableColumn *aTableColumn in [tableView tableColumns]) {
[buffer appendString: @"\t\t<TH>"];
[buffer appendString:[[aTableColumn headerCell] stringValue]];
[buffer appendString: @"</TH>\r"];
}
[buffer appendString: @"\t</TR\r>"];
}
-(void)appendRowAtIndex:(NSInteger)rowIndex toString:(NSMutableString *)buffer; {
[buffer appendString: @"\t<TR>"];
for (NSTableColumn *aTableColumn in [tableView tableColumns]) {
[buffer appendString: @"\t\t<TD>"];
NSString *objectValue = [[tableView dataSource] tableView:tableView objectValueForTableColumn:aTableColumn row:rowIndex];
if (objectValue) { [buffer appendString:objectValue]; }
else { [buffer appendString:@"--"]; }
[buffer appendString: @"</TD>\r"];
}
[buffer appendString: @"\t</TR>\r"];
}
- (NSString *)stringForObjectValue:(id)anObject; {
// Textual representation of cell content
// taken from "MyValueFormatter.m" of "QTMetadataEditor" sample code
NSString *resultString;
if ([anObject isMemberOfClass:[NSData class]]) {
// resultString = [MyValueFormatter hexStringFromData:(NSData *)anObject];
}
else if ([anObject isMemberOfClass:[NSString class]]) {
resultString = anObject;
}
else if ([anObject isMemberOfClass:[NSNumber class]]) {
resultString = [anObject stringValue];
}
return resultString;
}
@end