| 1 |
// |
| 2 |
// XspfMRule_Subclasses.m |
| 3 |
// XspfManager |
| 4 |
// |
| 5 |
// Created by Hori,Masaki on 09/12/19. |
| 6 |
// |
| 7 |
|
| 8 |
/* |
| 9 |
This source code is release under the New BSD License. |
| 10 |
Copyright (c) 2009-2010, masakih |
| 11 |
All rights reserved. |
| 12 |
|
| 13 |
ソースコード形式かバイナリ形式か、変更するかしないかを問わず、以下の条件を満たす場合に |
| 14 |
限り、再頒布および使用が許可されます。 |
| 15 |
|
| 16 |
1, ソースコードを再頒布する場合、上記の著作権表示、本条件一覧、および下記免責条項を含 |
| 17 |
めること。 |
| 18 |
2, バイナリ形式で再頒布する場合、頒布物に付属のドキュメント等の資料に、上記の著作権表 |
| 19 |
示、本条件一覧、および下記免責条項を含めること。 |
| 20 |
3, 書面による特別の許可なしに、本ソフトウェアから派生した製品の宣伝または販売促進に、 |
| 21 |
コントリビューターの名前を使用してはならない。 |
| 22 |
本ソフトウェアは、著作権者およびコントリビューターによって「現状のまま」提供されており、 |
| 23 |
明示黙示を問わず、商業的な使用可能性、および特定の目的に対する適合性に関する暗黙の保証 |
| 24 |
も含め、またそれに限定されない、いかなる保証もありません。著作権者もコントリビューター |
| 25 |
も、事由のいかんを問わず、 損害発生の原因いかんを問わず、かつ責任の根拠が契約であるか |
| 26 |
厳格責任であるか(過失その他の)不法行為であるかを問わず、仮にそのような損害が発生する |
| 27 |
可能性を知らされていたとしても、本ソフトウェアの使用によって発生した(代替品または代用 |
| 28 |
サービスの調達、使用の喪失、データの喪失、利益の喪失、業務の中断も含め、またそれに限定 |
| 29 |
されない)直接損害、間接損害、偶発的な損害、特別損害、懲罰的損害、または結果損害につい |
| 30 |
て、一切責任を負わないものとします。 |
| 31 |
------------------------------------------------------------------- |
| 32 |
Copyright (c) 2009-2010, masakih |
| 33 |
All rights reserved. |
| 34 |
|
| 35 |
Redistribution and use in source and binary forms, with or without |
| 36 |
modification, are permitted provided that the following conditions |
| 37 |
are met: |
| 38 |
|
| 39 |
1, Redistributions of source code must retain the above copyright |
| 40 |
notice, this list of conditions and the following disclaimer. |
| 41 |
2, Redistributions in binary form must reproduce the above copyright |
| 42 |
notice, this list of conditions and the following disclaimer in |
| 43 |
the documentation and/or other materials provided with the |
| 44 |
distribution. |
| 45 |
3, The names of its contributors may be used to endorse or promote |
| 46 |
products derived from this software without specific prior |
| 47 |
written permission. |
| 48 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 49 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 50 |
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 51 |
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 52 |
COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 53 |
INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 54 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 55 |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 56 |
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 57 |
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
| 58 |
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 59 |
POSSIBILITY OF SUCH DAMAGE. |
| 60 |
*/ |
| 61 |
|
| 62 |
|
| 63 |
#import "XspfMRule.h" |
| 64 |
#import "XspfMRule_private.h" |
| 65 |
|
| 66 |
#import "HMLabelField.h" |
| 67 |
|
| 68 |
|
| 69 |
@implementation XspfMSeparatorRule |
| 70 |
+ (id)separatorRule |
| 71 |
{ |
| 72 |
return [[[self alloc] initSparetorRule] autorelease]; |
| 73 |
} |
| 74 |
- (id)initSparetorRule |
| 75 |
{ |
| 76 |
[super init]; |
| 77 |
|
| 78 |
return self; |
| 79 |
} |
| 80 |
- (id)displayValue |
| 81 |
{ |
| 82 |
return [NSMenuItem separatorItem]; |
| 83 |
} |
| 84 |
- (id)displayValueForRuleEditor:(NSRuleEditor *)ruleEditor inRow:(NSInteger)row |
| 85 |
{ |
| 86 |
return [NSMenuItem separatorItem]; |
| 87 |
} |
| 88 |
- (NSDictionary *)predicatePartsWithDisplayValue:(id)value forRuleEditor:(NSRuleEditor *)ruleEditor inRow:(NSInteger)row |
| 89 |
{ |
| 90 |
return nil; |
| 91 |
} |
| 92 |
@end |
| 93 |
|
| 94 |
@implementation XspfMFieldRule |
| 95 |
+ (id)ruleWithFieldType:(XspfMFieldType)aType |
| 96 |
{ |
| 97 |
return [[[self alloc] initWithFieldType:aType tag:XspfMDefaultTag] autorelease]; |
| 98 |
} |
| 99 |
- (id)initWithFieldType:(XspfMFieldType)aType |
| 100 |
{ |
| 101 |
return [self initWithFieldType:aType tag:XspfMDefaultTag]; |
| 102 |
} |
| 103 |
+ (id)ruleWithFieldType:(XspfMFieldType)aType tag:(NSInteger)aTag |
| 104 |
{ |
| 105 |
return [[[self alloc] initWithFieldType:aType tag:aTag] autorelease]; |
| 106 |
} |
| 107 |
- (id)initWithFieldType:(XspfMFieldType)aType tag:(NSInteger)aTag |
| 108 |
{ |
| 109 |
[super init]; |
| 110 |
|
| 111 |
type = aType; |
| 112 |
tag = aTag; |
| 113 |
|
| 114 |
return self; |
| 115 |
} |
| 116 |
|
| 117 |
+ (id)fieldRuleWithValue:(NSString *)value |
| 118 |
{ |
| 119 |
return [[[self alloc] initWithValue:value] autorelease]; |
| 120 |
} |
| 121 |
- (id)initWithValue:(NSString *)value |
| 122 |
{ |
| 123 |
XspfMFieldType aType = XspfMUnknownType; |
| 124 |
NSInteger aTag = XspfMDefaultTag; |
| 125 |
|
| 126 |
if([value hasPrefix:@"textField"]) { |
| 127 |
aType = XspfMTextFieldType; |
| 128 |
} else if([value hasPrefix:@"dateField"]) { |
| 129 |
aType = XspfMDateFieldType; |
| 130 |
if([value isEqualToString:@"dateField"]) { |
| 131 |
aTag = XspfMPrimaryDateFieldTag; |
| 132 |
} else { |
| 133 |
aTag = XspfMSecondaryDateFieldTag; |
| 134 |
} |
| 135 |
} else if([value hasPrefix:@"rateField"]) { |
| 136 |
aType = XspfMRateFieldType; |
| 137 |
} else if([value hasPrefix:@"numberField"]) { |
| 138 |
aType = XspfMNumberFieldType; |
| 139 |
if([value isEqualToString:@"numberField"]) { |
| 140 |
aTag = XspfMPrimaryNumberFieldTag; |
| 141 |
} else { |
| 142 |
aTag = XspfMSecondaryNumberFieldTag; |
| 143 |
} |
| 144 |
} else if([value hasPrefix:@"labelField"]) { |
| 145 |
aType = XspfMLabelFieldType; |
| 146 |
} |
| 147 |
|
| 148 |
if(aType == XspfMUnknownType) { |
| 149 |
[super init]; |
| 150 |
[self release]; |
| 151 |
return nil; |
| 152 |
} |
| 153 |
|
| 154 |
self = [self initWithFieldType:aType tag:aTag]; |
| 155 |
[self setValue:value]; |
| 156 |
return self; |
| 157 |
} |
| 158 |
|
| 159 |
#pragma mark == NSCopying Protocol == |
| 160 |
- (id)copyWithZone:(NSZone *)zone |
| 161 |
{ |
| 162 |
XspfMFieldRule *result = [super copyWithZone:zone]; |
| 163 |
result->type = type; |
| 164 |
result->tag = tag; |
| 165 |
|
| 166 |
return result; |
| 167 |
} |
| 168 |
|
| 169 |
#pragma mark == NSCoding Protocol == |
| 170 |
static NSString *const XspfMRuleTagKey = @"XspfMRuleTagKey"; |
| 171 |
static NSString *const XspfMRuleTypeKey = @"XspfMRuleTypeKey"; |
| 172 |
- (id)initWithCoder:(NSCoder *)decoder |
| 173 |
{ |
| 174 |
self = [super initWithCoder:decoder]; |
| 175 |
tag = [decoder decodeIntegerForKey:XspfMRuleTagKey]; |
| 176 |
type = [decoder decodeIntegerForKey:XspfMRuleTypeKey]; |
| 177 |
|
| 178 |
return self; |
| 179 |
} |
| 180 |
- (void)encodeWithCoder:(NSCoder *)encoder |
| 181 |
{ |
| 182 |
[super encodeWithCoder:encoder]; |
| 183 |
|
| 184 |
[encoder encodeInteger:tag forKey:XspfMRuleTagKey]; |
| 185 |
[encoder encodeInteger:type forKey:XspfMRuleTypeKey]; |
| 186 |
} |
| 187 |
|
| 188 |
- (BOOL)isEqual:(id)other |
| 189 |
{ |
| 190 |
if(![super isEqual:other]) return NO; |
| 191 |
|
| 192 |
XspfMFieldRule *o = other; |
| 193 |
if(tag != o->tag) return NO; |
| 194 |
if(type != o->type) return NO; |
| 195 |
|
| 196 |
return YES; |
| 197 |
} |
| 198 |
|
| 199 |
- (Class)fieldClass |
| 200 |
{ |
| 201 |
Class result = Nil; |
| 202 |
switch(type) { |
| 203 |
case XspfMTextFieldType: |
| 204 |
case XspfMNumberFieldType: |
| 205 |
result = [NSTextField class]; |
| 206 |
break; |
| 207 |
case XspfMDateFieldType: |
| 208 |
result = [NSDatePicker class]; |
| 209 |
break; |
| 210 |
case XspfMRateFieldType: |
| 211 |
result = [NSLevelIndicator class]; |
| 212 |
break; |
| 213 |
case XspfMLabelFieldType: |
| 214 |
result = [HMLabelField class]; |
| 215 |
break; |
| 216 |
default: |
| 217 |
// |
| 218 |
break; |
| 219 |
} |
| 220 |
return result; |
| 221 |
} |
| 222 |
- (SEL)fieldCreateSelector |
| 223 |
{ |
| 224 |
SEL result = Nil; |
| 225 |
switch(type) { |
| 226 |
case XspfMTextFieldType: |
| 227 |
result = @selector(textField); |
| 228 |
break; |
| 229 |
case XspfMNumberFieldType: |
| 230 |
result = @selector(numberField); |
| 231 |
break; |
| 232 |
case XspfMDateFieldType: |
| 233 |
result = @selector(datePicker); |
| 234 |
break; |
| 235 |
case XspfMRateFieldType: |
| 236 |
result = @selector(ratingIndicator); |
| 237 |
break; |
| 238 |
case XspfMLabelFieldType: |
| 239 |
result = @selector(labelField); |
| 240 |
break; |
| 241 |
default: |
| 242 |
// |
| 243 |
break; |
| 244 |
} |
| 245 |
return result; |
| 246 |
} |
| 247 |
- (id)displayValue |
| 248 |
{ |
| 249 |
id res = [self performSelector:[self fieldCreateSelector]]; |
| 250 |
[res setTag:tag]; |
| 251 |
|
| 252 |
return res; |
| 253 |
} |
| 254 |
- (id)displayValueForRuleEditor:(NSRuleEditor *)ruleEditor inRow:(NSInteger)row |
| 255 |
{ |
| 256 |
id result = nil; |
| 257 |
|
| 258 |
// find same type field in row. |
| 259 |
id displayValues = [ruleEditor displayValuesForRow:row]; |
| 260 |
Class fieldCalss = [self fieldClass]; |
| 261 |
for(id field in displayValues) { |
| 262 |
if([field isKindOfClass:fieldCalss] && [field tag] == tag) { |
| 263 |
result = field; |
| 264 |
break; |
| 265 |
} |
| 266 |
} |
| 267 |
if(!result) result = [self displayValue]; |
| 268 |
|
| 269 |
return result; |
| 270 |
} |
| 271 |
@end |
| 272 |
|