public
Description: My OS X Thermometer client.
Clone URL: git://github.com/dustin/osx-thermometer.git
Search Repo:
osx-thermometer / LogController.m
100644 60 lines (49 sloc) 1.348 kb
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
// arch-tag: A99AED00-7A7E-11D9-AF1E-000A957659CC
#import "LogController.h"
#import "Thermometer.h"
#import "SparklineCell.h"
 
@implementation LogController
 
-(void)awakeFromNib
{
  NSLog(@"LogController awoke from nib.");
 
  NSTableColumn *col=[outline tableColumnWithIdentifier: @"graph"];
  SparklineCell *cell=[[SparklineCell alloc] init];
  [col setDataCell: cell];
  [cell release];
  
  [[NSNotificationCenter defaultCenter]
        addObserver:self
        selector:@selector(dataUpdated:)
        name:DATA_UPDATED
        object:nil];
    [[NSNotificationCenter defaultCenter]
    addObserver:self
    selector:@selector(unitChange:)
    name:UNIT_CHANGE
    object:nil];
 
  [self setUnits:[[NSUserDefaults standardUserDefaults] objectForKey:@"units"]];
}
 
-(void)setUnits:(NSString *)to
{
  NSTableColumn *col=[outline tableColumnWithIdentifier: @"reading"];
  NSString *newLabel=[[NSString alloc] initWithFormat:@"Reading (%@)", to];
  [[col headerCell] setStringValue: newLabel];
  [newLabel release];
}
 
-(void)dataUpdated:(id)anObject
{
  [outline reloadData];
}
 
-(void)unitChange:(id)anObject
{
  // Update the log reading header to indicate the units
  NSString *u=[anObject object];
  [self setUnits: u];
 
  // And reload the data
  [outline reloadData];
}
 
-(IBAction)showWindow:(id)sender
{
  [super showWindow:sender];
  [outline reloadData];
}
 
@end