Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /XspfManager/XspfMRule.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 348 - (hide annotations) (download)
Sun May 9 01:25:25 2010 UTC (13 years, 11 months ago) by masakih
File size: 18790 byte(s)
XspfMRule関連をごっそり変更。
1 masaki 120 //
2 masakih 348 // XspfMRule.m
3 masaki 120 // XspfManager
4     //
5     // Created by Hori,Masaki on 09/11/29.
6     // Copyright 2009 masakih. All rights reserved.
7     //
8    
9 masakih 348 #import "XspfMRule.h"
10 masaki 170 #import "XspfMRule_private.h"
11 masaki 120
12 masaki 243 #import "XspfMLabelField.h"
13     #import "XspfMLabelCell.h"
14 masaki 120
15 masaki 243
16 masaki 152 @implementation XspfMRule (XspfMAccessor)
17     - (void)setChildren:(NSArray *)newChildren
18 masaki 120 {
19 masaki 158 if(!newChildren) newChildren = [NSMutableArray array];
20 masaki 152
21     [children autorelease];
22 masaki 158 children = [[NSMutableArray alloc] initWithArray:newChildren copyItems:YES];
23 masaki 120 }
24 masaki 152 - (void)addChild:(XspfMRule *)child
25     {
26     [children addObject:child];
27     }
28     - (void)setPredicateParts:(NSDictionary *)parts
29     {
30     [predicateHints autorelease];
31     predicateHints = [parts mutableCopy];
32     }
33     - (void)setExpression:(id)expression forKey:(id)key
34     {
35     [predicateHints setObject:expression forKey:key];
36     }
37     - (void)setValue:(NSString *)newValue
38     {
39 masaki 153 if([_value isEqualToString:newValue]) return;
40 masaki 152
41 masaki 153 [_value autorelease];
42     _value = [newValue copy];
43 masaki 152 }
44 masaki 153 - (NSString *)value { return _value; }
45 masaki 143 @end
46 masaki 152
47     @implementation XspfMRule
48     @dynamic value;
49    
50     - (NSInteger)numberOfChildren
51 masaki 120 {
52 masaki 152 return [children count];
53 masaki 120 }
54 masaki 152 - (id)childAtIndex:(NSInteger)index
55 masaki 120 {
56 masaki 152 return [children objectAtIndex:index];
57     }
58     - (id)displayValueForRuleEditor:(NSRuleEditor *)ruleEditor inRow:(NSInteger)row
59     {
60 masaki 153 return _value;
61 masaki 152 }
62     - (NSDictionary *)predicatePartsWithDisplayValue:(id)displayValue forRuleEditor:(NSRuleEditor *)ruleEditor inRow:(NSInteger)row
63     {
64     id result = [NSMutableDictionary dictionary];
65 masaki 142
66 masaki 152 NSRuleEditorRowType rowType = [ruleEditor rowTypeForRow:row];
67     if(rowType == NSRuleEditorRowTypeCompound) {
68     return predicateHints;
69     }
70    
71     if([predicateHints valueForKey:@"XspfMIgnoreExpression"]) return nil;
72    
73 masaki 166 id operatorType = [predicateHints valueForKey:NSRuleEditorPredicateOperatorType];
74     id option = [predicateHints valueForKey:NSRuleEditorPredicateOptions];
75     id leftExp = [predicateHints valueForKey:NSRuleEditorPredicateLeftExpression];
76     id rightExp = [predicateHints valueForKey:NSRuleEditorPredicateRightExpression];
77 masaki 152 id customRightExp = [predicateHints valueForKey:@"XspfMPredicateRightExpression"];
78    
79     if(operatorType) {
80     [result setValue:operatorType forKey:NSRuleEditorPredicateOperatorType];
81     }
82     if(option) {
83     [result setValue:option forKey:NSRuleEditorPredicateOptions];
84     }
85     if(leftExp) {
86     id exp = nil;
87     if([leftExp isEqual:@"value"]) {
88     exp = [NSExpression expressionForKeyPath:displayValue];
89     } else {
90     exp = [NSExpression expressionForKeyPath:leftExp];
91     }
92     if(exp) {
93     [result setValue:exp forKey:NSRuleEditorPredicateLeftExpression];
94     }
95     }
96     if(rightExp) {
97     SEL selector = NSSelectorFromString(rightExp);
98     id exp = nil;
99     if(selector) {
100     exp = [NSExpression expressionForConstantValue:[displayValue performSelector:selector]];
101     } else {
102     exp = [NSExpression expressionForConstantValue:rightExp];
103     }
104     if(exp) {
105     [result setValue:exp forKey:NSRuleEditorPredicateRightExpression];
106     }
107     }
108     if(customRightExp) {
109     SEL selector = NSSelectorFromString(customRightExp);
110     id arg01 = [predicateHints valueForKey:@"XspfMRightExpressionArg01"];
111     id arg02 = [predicateHints valueForKey:@"XspfMRightExpressionArg02"];
112 masakih 348 if([arg01 isEqual:@"displayValues"]) {
113     arg01 = [ruleEditor displayValuesForRow:row];
114     }
115     if([arg02 isEqual:@"displayValues"]) {
116     arg02 = [ruleEditor displayValuesForRow:row];
117     }
118 masaki 152
119 masakih 348 id rhs = nil;
120 masaki 152 if(arg02 && arg01) {
121 masakih 348 rhs = [self performSelector:selector withObject:arg01 withObject:arg02];
122 masaki 152 } else if(arg01) {
123 masakih 348 rhs = [self performSelector:selector withObject:arg01];
124 masaki 152 } else {
125 masakih 348 rhs = [self performSelector:selector];
126     }
127     if(rhs) {
128 masaki 163 [result setValue:rhs forKey:NSRuleEditorPredicateRightExpression];
129 masaki 152 }
130     }
131    
132 masaki 163 NSString *selName = [predicateHints valueForKey:@"XspfMCustomSelector"];
133     if(selName) {
134 masaki 154 id args = nil;
135     NSString *argSelName = [predicateHints valueForKey:@"XspfMCustomSelectorArgumentsCteator"];
136     if(argSelName) {
137     SEL argSel = NSSelectorFromString(argSelName);
138     id argSelArg01 = [predicateHints valueForKey:@"XspfMCustomSelectorArgumentsCteatorArg01"];
139     if([argSelArg01 isEqual:@"displayValues"]) {
140     argSelArg01 = [ruleEditor displayValuesForRow:row];
141     }
142     id argSelArg02 = [predicateHints valueForKey:@"XspfMCustomSelectorArgumentsCteatorArg02"];
143     if([argSelArg02 isEqual:@"displayValues"]) {
144     argSelArg02 = [ruleEditor displayValuesForRow:row];
145     }
146     if(argSelArg02) {
147     args = [self performSelector:argSel withObject:argSelArg01 withObject:argSelArg02];
148     } else if(argSelArg01) {
149     args = [self performSelector:argSel withObject:argSelArg01];
150     } else {
151     args = [self performSelector:argSel];
152     }
153     } else {
154     id arg01 = [predicateHints valueForKey:@"XspfMCustomSelectorArg01"];
155     args = [NSArray arrayWithObjects:[NSExpression expressionForConstantValue:arg01], nil];
156     }
157 masaki 152
158 masakih 348 id target = [NSExpression expressionForConstantValue:[[self class] functionHost]];
159 masaki 165 id rhs = [NSExpression expressionForFunction:target selectorName:selName arguments:args];
160 masaki 166 [result setValue:rhs forKey:NSRuleEditorPredicateRightExpression];
161 masaki 152 }
162    
163 masaki 187 // HMLog(HMLogLevelDebug, @"predicate\tcriterion -> %@, value -> %@, row -> %d, result -> %@", predicateHints, displayValue, row, result);
164 masaki 152
165     return result;
166 masaki 142 }
167 masaki 152
168 masaki 153 - (id)displayValue { return _value; }
169 masaki 120
170 masaki 338
171     #pragma mark#### Variables for add/change criteria of Library. ####
172 masakih 348 static NSArray *leftKeys = nil;
173     static NSArray *stringKeys = nil;
174     static NSArray *dateKeys = nil;
175     static NSArray *numberKeys = nil;
176     static BOOL useRating = NO;
177     static BOOL useLabel = NO;
178    
179     + (void)registerStringTypeKeyPaths:(NSArray *)keyPaths
180     {
181     if(stringKeys) {
182     [stringKeys release];
183     [leftKeys release];
184     leftKeys = nil;
185     }
186     stringKeys = [[NSArray arrayWithArray:keyPaths] retain];
187     }
188     + (void)registerDateTypeKeyPaths:(NSArray *)keyPaths
189     {
190     if(dateKeys) {
191     [dateKeys release];
192     [leftKeys release];
193     leftKeys = nil;
194     }
195     dateKeys = [[NSArray arrayWithArray:keyPaths] retain];
196     }
197     + (void)registerNumberTypeKeyPaths:(NSArray *)keyPaths
198     {
199     if(numberKeys) {
200     [numberKeys release];
201     [leftKeys release];
202     leftKeys = nil;
203     }
204     numberKeys = [[NSArray arrayWithArray:keyPaths] retain];
205     }
206     + (void)setUseRating:(BOOL)flag
207     {
208     if(flag && useRating || !flag && !useRating) {
209     [leftKeys release];
210     leftKeys = nil;
211     }
212     useRating = flag;
213     }
214     + (void)setUseLablel:(BOOL)flag
215     {
216     if(flag && useLabel || !flag && !useLabel) {
217     [leftKeys release];
218     leftKeys = nil;
219     }
220     useLabel = flag;
221     }
222 masaki 338 + (NSArray *)leftKeys
223     {
224     if(!leftKeys) {
225 masakih 348
226     id temp = [NSMutableArray array];
227     [temp addObjectsFromArray:stringKeys];
228     [temp addObjectsFromArray:dateKeys];
229     [temp addObjectsFromArray:numberKeys];
230     if(useRating) {
231     [temp addObject:@"rating"];
232     }
233     if(useLabel) {
234     [temp addObject:@"label"];
235     }
236     leftKeys = [[NSArray arrayWithArray:temp] retain];
237 masaki 338 }
238     return leftKeys;
239     }
240 masakih 348 static inline BOOL isDateKeyPath(NSString *keyPath)
241 masaki 338 {
242 masakih 348 return [dateKeys containsObject:keyPath];
243 masaki 338 }
244 masakih 348 + (BOOL)isDateKeyPath:(NSString *)keyPath
245 masaki 338 {
246 masakih 348 return isDateKeyPath(keyPath);
247 masaki 338 }
248     - (BOOL)isDateKeyPath:(NSString *)keyPath
249     {
250     return isDateKeyPath(keyPath);
251     }
252 masakih 348 static inline BOOL isStringKeyPath(NSString *keyPath)
253     {
254     return [stringKeys containsObject:keyPath];
255     }
256     + (BOOL)isStringKeyPath:(NSString *)keyPath
257     {
258     return isStringKeyPath(keyPath);
259     }
260 masaki 338 - (BOOL)isStringKeyPath:(NSString *)keyPath
261     {
262 masakih 348 return isStringKeyPath(keyPath);
263 masaki 338 }
264 masakih 348 static inline BOOL isNumberKeyPath(NSString *keyPath)
265     {
266     return [numberKeys containsObject:keyPath];
267     }
268     + (BOOL)isNumberKeyPath:(NSString *)keyPath
269     {
270     return isNumberKeyPath(keyPath);
271     }
272     - (BOOL)isNumberKeyPath:(NSString *)keyPath
273     {
274     return isNumberKeyPath(keyPath);
275     }
276     + (BOOL)isRateKeyPath:(NSString *)keyPath
277     {
278     return [keyPath isEqualToString:@"rating"];
279     }
280 masaki 338 - (BOOL)isRateKeyPath:(NSString *)keyPath
281     {
282     return [keyPath isEqualToString:@"rating"];
283     }
284 masakih 348 + (BOOL)isLabelKeyPath:(NSString *)keyPath
285 masaki 338 {
286     return [keyPath isEqualToString:@"label"];
287     }
288 masakih 348 - (BOOL)isLabelKeyPath:(NSString *)keyPath
289 masaki 338 {
290 masakih 348 return [keyPath isEqualToString:@"label"];
291 masaki 338 }
292    
293 masaki 164 #pragma mark == NSCopying Protocol ==
294 masaki 152 - (id)copyWithZone:(NSZone *)zone
295 masaki 142 {
296 masaki 152 XspfMRule *result = [[[self class] allocWithZone:zone] init];
297 masaki 158 [result setChildren:children];
298     [result setPredicateParts:predicateHints];
299     [result setValue:_value];
300 masaki 152
301     return result;
302 masaki 142 }
303 masaki 152
304 masaki 164 #pragma mark == NSCoding Protocol ==
305     static NSString *const XspfMRuleChildrenKey = @"XspfMRuleChildrenKey";
306     static NSString *const XspfMRulePredicateHintsKey = @"XspfMRulePredicateHintsKey";
307     static NSString *const XspfMRuleValueKey = @"XspfMRuleValueKey";
308     - (id)initWithCoder:(NSCoder *)decoder
309     {
310     self = [self init];
311    
312     [self setChildren:[decoder decodeObjectForKey:XspfMRuleChildrenKey]];
313     [self setPredicateParts:[decoder decodeObjectForKey:XspfMRulePredicateHintsKey]];
314     [self setValue:[decoder decodeObjectForKey:XspfMRuleValueKey]];
315    
316     return self;
317     }
318     - (void)encodeWithCoder:(NSCoder *)encoder
319     {
320     [encoder encodeObject:children forKey:XspfMRuleChildrenKey];
321     [encoder encodeObject:predicateHints forKey:XspfMRulePredicateHintsKey];
322     [encoder encodeObject:_value forKey:XspfMRuleValueKey];
323     }
324    
325 masaki 152 - (BOOL)isEqual:(id)other
326 masaki 120 {
327 masaki 152 if([super isEqual:other]) return YES;
328     if(![other isKindOfClass:[XspfMRule class]]) return NO;
329 masaki 120
330 masaki 152 XspfMRule *o = other;
331 masaki 153 if(![_value isEqualToString:o->_value]) return NO;
332 masaki 152 // if(![children isEqual:o->children]) return NO;
333     // if(![predicateHints isEqual:o->predicateHints]) return NO;
334    
335 masaki 120 return YES;
336     }
337 masaki 152 - (NSUInteger)hash
338     {
339 masaki 153 return _value ? [_value hash] : [super hash];
340 masaki 152 }
341    
342 masaki 120 - (id)description
343     {
344 masaki 152 return [NSString stringWithFormat:@"%@ {\n\t%@ = %@;\n\t%@ = %@;\n\t%@ = %@;}",
345     NSStringFromClass([self class]),
346 masaki 153 @"value", _value,
347 masaki 152 @"hints", predicateHints,
348     @"children", children,
349     nil];
350 masaki 120 }
351     @end
352    
353 masaki 152 @implementation XspfMRule (XspfMCreation)
354 masaki 120
355 masaki 152 - (id)init
356 masaki 120 {
357 masaki 152 [super init];
358    
359     children = [[NSMutableArray array] retain];
360     predicateHints = [[NSMutableDictionary dictionary] retain];
361    
362     return self;
363 masaki 120 }
364 masaki 152
365     - (id)initWithValue:(NSString *)newValue children:(NSArray *)newChildren predicateHints:(NSDictionary *)parts
366 masaki 120 {
367 masaki 152 [self init];
368 masaki 120
369 masaki 152 if([newValue isEqualToString:@"separator"]) {
370     [self release];
371     return [[XspfMSeparatorRule alloc] initSparetorRule];
372     }
373    
374 masaki 170 id fieldRule = [XspfMFieldRule fieldRuleWithValue:newValue];
375     if(fieldRule) {
376 masaki 152 [self release];
377 masaki 170 self = [fieldRule retain];
378 masaki 152 }
379    
380     [self setValue:newValue];
381     [self setChildren:newChildren];
382     [self setPredicateParts:parts];
383    
384 masaki 120 return self;
385     }
386 masaki 152 + (id)ruleWithValue:(NSString *)newValue children:(NSArray *)newChildren predicateHints:(NSDictionary *)parts
387 masaki 120 {
388 masaki 152 return [[[self alloc] initWithValue:newValue children:newChildren predicateHints:parts] autorelease];
389 masaki 120 }
390 masaki 152
391     + (NSArray *)compoundRule
392 masaki 120 {
393 masaki 152 id comp = [self ruleWithValue:@"of the following are true" children:nil predicateHints:[NSDictionary dictionary]];
394    
395     id allExp = [NSNumber numberWithUnsignedInt:NSAndPredicateType];
396     id all = [self ruleWithValue:@"All"
397     children:[NSArray arrayWithObject:comp]
398     predicateHints:[NSDictionary dictionaryWithObject:allExp forKey:NSRuleEditorPredicateCompoundType]];
399    
400     id anyExp = [NSNumber numberWithUnsignedInt:NSOrPredicateType];
401     id any = [self ruleWithValue:@"Any"
402     children:[NSArray arrayWithObject:comp]
403     predicateHints:[NSDictionary dictionaryWithObject:anyExp forKey:NSRuleEditorPredicateCompoundType]];
404    
405     return [NSArray arrayWithObjects:all, any, nil];
406 masaki 120 }
407 masaki 152
408     - (NSDictionary *)predicateHintsWithPlist:(NSDictionary *)plist
409 masaki 120 {
410 masaki 152 NSMutableDictionary *result = [NSMutableDictionary dictionaryWithDictionary:plist];
411     [result removeObjectForKey:@"criteria"];
412     [result removeObjectForKey:@"value"];
413    
414     return result;
415 masaki 120 }
416 masaki 152
417     + (id)ruleWithPlist:(id)plist
418 masaki 120 {
419 masaki 152 return [[[self alloc] initWithPlist:plist] autorelease];
420 masaki 120 }
421 masaki 152 - (id)initWithPlist:(id)plist
422 masaki 120 {
423 masaki 152 if(![plist isKindOfClass:[NSDictionary class]]) {
424     [self init];
425     [self release];
426     return nil;
427     }
428    
429     id pValue = [plist valueForKey:@"value"];
430     id criteria = [plist valueForKey:@"criteria"];
431     id pChildren = [NSMutableArray array];
432     for(id criterion in criteria) {
433     id c = [[self class] ruleWithPlist:criterion];
434     if(c) [pChildren addObject:c];
435     }
436     id hints = [self predicateHintsWithPlist:plist];
437    
438     return [self initWithValue:pValue children:pChildren predicateHints:hints];
439 masaki 120 }
440 masaki 152
441     - (void)dealloc
442 masaki 120 {
443 masaki 152 [children release];
444     [predicateHints release];
445 masaki 153 [_value release];
446 masaki 152
447     [super dealloc];
448 masaki 120 }
449 masaki 152
450 masaki 120 @end
451    
452 masaki 153 @implementation XspfMRule (XspfMPrivate)
453 masaki 142
454 masaki 153 - (NSView *)textField
455     {
456     id text = [[[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
457     [[text cell] setControlSize:NSSmallControlSize];
458     [text setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
459     [text setStringValue:@"1234567890"];
460     [text sizeToFit];
461     [text setStringValue:@""];
462    
463     return text;
464     }
465     - (NSView *)datePicker
466     {
467     id date = [[[NSDatePicker alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
468     [[date cell] setControlSize:NSSmallControlSize];
469     [date setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
470     [date setDatePickerElements:NSYearMonthDayDatePickerElementFlag];
471     [date setDrawsBackground:YES];
472     [date setDateValue:[NSDate dateWithTimeIntervalSinceNow:0.0]];
473     [date sizeToFit];
474    
475     return date;
476     }
477     - (NSView *)ratingIndicator
478     {
479     id rate = [[[NSLevelIndicator alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
480     id cell = [rate cell];
481     [cell setControlSize:NSSmallControlSize];
482     [rate setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
483     [rate setMinValue:0];
484     [rate setMaxValue:5];
485     [cell setLevelIndicatorStyle:NSRatingLevelIndicatorStyle];
486     [cell setEditable:YES];
487 masakih 346 [cell setHighlighted:YES];
488 masaki 153 [rate sizeToFit];
489    
490 masakih 346 [rate setAction:@selector(continuousHighlighted:)];
491 masakih 348 [rate setTarget:[[self class] functionHost]];
492 masakih 346
493 masaki 153 return rate;
494     }
495 masakih 346 - (void)setHighlightRate:(id)rate
496     {
497     [[rate cell] setHighlighted:YES];
498     }
499     - (IBAction)continuousHighlighted:(id)sender
500     {
501     [self performSelector:@selector(setHighlightRate:) withObject:sender afterDelay:0.0];
502     }
503 masaki 153 - (NSView *)numberField
504     {
505     id text = [[[NSTextField alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
506     [[text cell] setControlSize:NSSmallControlSize];
507     [text setFont:[NSFont controlContentFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
508 masakih 348 [text setStringValue:@"1234"];
509 masaki 153 NSNumberFormatter *formatter = [[[NSNumberFormatter alloc] init] autorelease];
510     [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
511     [formatter setMinimum:[NSNumber numberWithInt:0]];
512     [text setFormatter:formatter];
513     [text sizeToFit];
514     [text setStringValue:@"1"];
515    
516     return text;
517     }
518 masaki 243 - (NSView *)labelField
519     {
520 masakih 348 // HMLog(HMLogLevelDebug, @"Enter -> %@", NSStringFromSelector(_cmd));
521 masaki 243 id label = [[[XspfMLabelField alloc] initWithFrame:NSMakeRect(0,0,100,19)] autorelease];
522     [label sizeToFit];
523 masaki 251 [label setLabelStyle:XspfMSquareStyle];
524     [label setDrawX:YES];
525 masaki 243
526     return label;
527     }
528 masaki 153 @end
529 masaki 152 @implementation XspfMRule (XspfMExpressionBuilder)
530 masakih 348 + (id)functionHost
531     {
532     static id host = nil;
533     if(host) return host;
534     @synchronized(self) {
535     if(!host) {
536     host = [[self alloc] init];
537     }
538     }
539     return host;
540     }
541 masaki 156 - (NSArray *)twoNumberAndUnitArgs:(NSArray *)displayValues
542     {
543     id value03 = [displayValues objectAtIndex:2];
544     id arg01 = [NSNumber numberWithInt:[[value03 objectValue] intValue]];
545    
546     id value05 = [displayValues objectAtIndex:4];
547     id arg02 = [NSNumber numberWithInt:[[value05 objectValue] intValue]];
548    
549     id value06 = [displayValues objectAtIndex:5];
550     id arg03 = nil;
551 masakih 348 if([value06 isEqualToString:@"Hours"]) {
552     arg03 = [NSNumber numberWithInt:XspfMHoursUnitType];
553     } else if([value06 isEqualToString:@"Days"]) {
554 masaki 163 arg03 = [NSNumber numberWithInt:XspfMDaysUnitType];
555 masaki 156 } else if([value06 isEqualToString:@"Weeks"]) {
556 masaki 163 arg03 = [NSNumber numberWithInt:XpsfMWeeksUnitType];
557 masaki 156 } else if([value06 isEqualToString:@"Months"]) {
558 masaki 163 arg03 = [NSNumber numberWithInt:XspfMMonthsUnitType];
559 masaki 156 } else if([value06 isEqualToString:@"Years"]) {
560 masaki 163 arg03 = [NSNumber numberWithInt:XspfMYearsUnitType];
561 masaki 156 }
562    
563     if([arg01 compare:arg02] == NSOrderedDescending) {
564     id t = arg01;
565     arg01 = arg02;
566     arg02 = t;
567     }
568    
569     return [NSArray arrayWithObjects:[NSExpression expressionForConstantValue:arg01],
570     [NSExpression expressionForConstantValue:arg02],
571     [NSExpression expressionForConstantValue:arg03],
572     nil];
573     }
574 masaki 154 - (NSArray *)numberAndUnitArgs:(NSArray *)displayValues
575     {
576     id value03 = [displayValues objectAtIndex:2];
577     id arg01 = [NSNumber numberWithInt:[[value03 objectValue] intValue]];
578    
579     id value04 = [displayValues objectAtIndex:3];
580     id arg02 = nil;
581 masakih 348 if([value04 isEqualToString:@"Hours"]) {
582     arg02 = [NSNumber numberWithInt:XspfMHoursUnitType];
583     } else if([value04 isEqualToString:@"Days"]) {
584 masaki 163 arg02 = [NSNumber numberWithInt:XspfMDaysUnitType];
585 masaki 154 } else if([value04 isEqualToString:@"Weeks"]) {
586 masaki 163 arg02 = [NSNumber numberWithInt:XpsfMWeeksUnitType];
587 masaki 154 } else if([value04 isEqualToString:@"Months"]) {
588 masaki 163 arg02 = [NSNumber numberWithInt:XspfMMonthsUnitType];
589 masaki 154 } else if([value04 isEqualToString:@"Years"]) {
590 masaki 163 arg02 = [NSNumber numberWithInt:XspfMYearsUnitType];
591 masaki 154 }
592    
593     return [NSArray arrayWithObjects:[NSExpression expressionForConstantValue:arg01],
594     [NSExpression expressionForConstantValue:arg02], nil];
595     }
596 masaki 152 - (NSExpression *)rangeDateFromDisplayValues:(NSArray *)displayValues
597     {
598     id field01 = nil;
599     id field02 = nil;
600    
601     Class datepickerclass = [NSDatePicker class];
602     for(id v in displayValues) {
603     if([v isKindOfClass:datepickerclass]) {
604     if([v tag] == XspfMPrimaryDateFieldTag) {
605     field01 = v;
606     } else {
607     field02 = v;
608     }
609     }
610 masaki 142 }
611    
612 masaki 152 if(!field01 || !field02) return nil;
613    
614     id value01, value02;
615     value01 = [field01 dateValue]; value02 = [field02 dateValue];
616     if([value01 compare:value02] == NSOrderedDescending) {
617     id t = value02;
618     value02 = value01;
619     value01 = t;
620 masaki 142 }
621    
622 masaki 152 id expression01, expression02;
623     expression01 = [NSExpression expressionForConstantValue:value01];
624     expression02 = [NSExpression expressionForConstantValue:value02];
625    
626     return [NSExpression expressionForAggregate:[NSArray arrayWithObjects:expression01, expression02, nil]];
627 masaki 142 }
628 masakih 348 - (NSExpression *)rangeNumberFromDisplayValues:(NSArray *)displayValues
629     {
630     id field01 = nil;
631     id field02 = nil;
632    
633     Class numberFieldClass = [NSTextField class];
634     for(id v in displayValues) {
635     if([v isKindOfClass:numberFieldClass]) {
636     if([v tag] == XspfMPrimaryNumberFieldTag) {
637     field01 = v;
638     } else {
639     field02 = v;
640     }
641     }
642     }
643    
644     if(!field01 || !field02) return nil;
645    
646     NSInteger value01, value02;
647     value01 = [field01 integerValue]; value02 = [field02 integerValue];
648     if(value01 > value02) {
649     NSInteger t = value02;
650     value02 = value01;
651     value01 = t;
652     }
653    
654     id expression01, expression02;
655     expression01 = [NSExpression expressionForConstantValue:[NSNumber numberWithInteger:value01]];
656     expression02 = [NSExpression expressionForConstantValue:[NSNumber numberWithInteger:value02]];
657    
658     return [NSExpression expressionForAggregate:[NSArray arrayWithObjects:expression01, expression02, nil]];
659     }
660 masaki 120 @end
661 masaki 152

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26