2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include <NGObjWeb/NGObjWeb.h>
24 @interface WOThresholdColoredNumber : WODynamicElement
26 WOAssociation *lowColor;
27 WOAssociation *highColor;
28 WOAssociation *threshold;
30 WOAssociation *numberFormat;
34 #import <Foundation/NSNumberFormatter.h>
37 @implementation WOThresholdColoredNumber
39 - (id)initWithName:(NSString *)_name
40 associations:(NSDictionary *)_config
41 template:(WOElement *)_temp
43 if ((self = [super initWithName:_name associations:_config template:_temp])) {
44 self->lowColor = WOExtGetProperty(_config, @"lowColor");
45 self->highColor = WOExtGetProperty(_config, @"highColor");
46 self->threshold = WOExtGetProperty(_config, @"threshold");
47 self->value = WOExtGetProperty(_config, @"value");
48 self->numberFormat = WOExtGetProperty(_config, @"numberformat");
54 RELEASE(self->lowColor);
55 RELEASE(self->highColor);
56 RELEASE(self->threshold);
58 RELEASE(self->numberFormat);
66 - (void)appendToResponse:(WOResponse *)_resp inContext:(WOContext *)_ctx {
68 NSString *low; // lowColor association
69 NSString *high; // highColor association
70 NSNumber *t; // threshold association
71 NSNumber *v; // value association
72 NSString *nFormat; // numberFormat association
74 NSString *result = nil;
76 comp = [_ctx component];
77 low = [self->lowColor stringValueInComponent:comp];
78 high = [self->highColor stringValueInComponent:comp];
79 t = [self->threshold valueInComponent:comp];
80 v = [self->value valueInComponent:comp];
81 nFormat = [self->numberFormat stringValueInComponent:comp];
83 if (![v isKindOfClass:[NSNumber class]]) {
85 NSLog(@"WARNING! WOThresholdColoredNumber 'value' is not a NSNumber");
86 result = @"[WARNING! WOThresholdColoredNumber:'value' must be a NSNumber]";
92 NSNumberFormatter *formatter;
94 formatter = AUTORELEASE([[NSNumberFormatter alloc] init]);
95 [formatter setFormat:nFormat];
96 result = [formatter stringForObjectValue:v];
99 result = [v stringValue];
101 color = ([v compare:t] == NSOrderedAscending) ? low : high;
104 [_resp appendContentString:@"<FONT COLOR=\""];
105 [_resp appendContentString:color];
106 [_resp appendContentString:@"\">"];
108 [_resp appendContentString:result];
110 [_resp appendContentString:@"</FONT>"];
113 @end /* WOThresholdColoredNumber */