-
Notifications
You must be signed in to change notification settings - Fork 8
/
ImageForStateTransformer.m
56 lines (49 loc) · 1.13 KB
/
ImageForStateTransformer.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
#import "ImageForStateTransformer.h"
/*!
* Returns a different NSImage depending on whether the given value is true or false.
*
* @truename ComBelkadanUtils_ImageForStateTransformer
*/
@implementation ImageForStateTransformer
+ (Class)transformedValueClass
{
return [NSImage class];
}
+ (BOOL)allowsReverseTransformation
{
return YES;
}
- (id)transformedValue:(id)original
{
if ([original respondsToSelector:@selector(boolValue)] && [original boolValue])
return trueImage;
else
return falseImage;
}
- (id)reverseTransformedValue:(id)value
{
if ([value isEqual:trueImage])
return [NSNumber numberWithBool:YES];
else
return [NSNumber numberWithBool:NO];
}
/*!
* The designated initializer; creates a transformer that shows <code>theTrueImage</code>
* when given a true value and <code>theFalseImage</code> when given a false value.
*/
- (id)initWithTrueImage:(NSImage *)theTrueImage falseImage:(NSImage *)theFalseImage
{
if (self = [super init])
{
trueImage = [theTrueImage copy];
falseImage = [theFalseImage copy];
}
return self;
}
- (void)dealloc
{
[trueImage release];
[falseImage release];
[super dealloc];
}
@end