root / Classes / ImageFamilyPickerCell.m @ 700184fb
History | View | Annotate | Download (6.8 kB)
1 |
// |
---|---|
2 |
// ImageFamilyPickerCell.m |
3 |
// OpenStack |
4 |
// |
5 |
// Created by Mike Mayo on 10/23/10. |
6 |
// The OpenStack project is provided under the Apache 2.0 license. |
7 |
// |
8 |
|
9 |
#import "ImageFamilyPickerCell.h" |
10 |
#import "OpenStackAccount.h" |
11 |
#import "Image.h" |
12 |
|
13 |
#define kScaleY 1.53061224 |
14 |
#define kScaleX .29109589 |
15 |
#define kPickerX -4.0 |
16 |
#define kPickerY -86.0 |
17 |
|
18 |
#define kImageFamily 3 |
19 |
#define kImages 4 |
20 |
|
21 |
@implementation ImageFamilyPickerCell |
22 |
|
23 |
@synthesize account, tableView, images, selectedFamily; |
24 |
|
25 |
- (void)groupImages { |
26 |
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:9]; |
27 |
NSArray *stringKeys = [NSArray arrayWithObjects:@"ubuntu", @"redhat", @"gentoo", @"centos", @"debian", @"windows", @"arch", kCustomImage, @"fedora", nil]; |
28 |
|
29 |
for (int i = 0; i < [stringKeys count]; i++) { |
30 |
NSString *stringKey = [stringKeys objectAtIndex:i]; |
31 |
NSArray *keys = [self.account.images allKeys]; |
32 |
for (int j = 0; j < [keys count]; j++) { |
33 |
Image *image = [self.account.images objectForKey:[keys objectAtIndex:j]]; |
34 |
if ([image respondsToSelector:@selector(logoPrefix)] && [[image logoPrefix] isEqualToString:stringKey]) { |
35 |
if (![dict objectForKey:stringKey]) { |
36 |
[dict setObject:[[[NSMutableArray alloc] init] autorelease] forKey:stringKey]; |
37 |
} |
38 |
NSMutableArray *keyedImages = [dict objectForKey:stringKey]; |
39 |
[keyedImages addObject:image]; |
40 |
} |
41 |
} |
42 |
} |
43 |
|
44 |
images = [[NSDictionary alloc] initWithDictionary:dict]; |
45 |
[dict release]; |
46 |
} |
47 |
|
48 |
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier account:(OpenStackAccount *)openStackAccount tableView:(UITableView *)aTableView { |
49 |
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) { |
50 |
// Initialization code |
51 |
|
52 |
self.account = openStackAccount; |
53 |
self.tableView = aTableView; |
54 |
selectedFamily = @"ubuntu"; |
55 |
[self groupImages]; |
56 |
|
57 |
|
58 |
UIPickerView *picker = [[UIPickerView alloc] initWithFrame:CGRectMake(kPickerX, kPickerY, 320.0, 320.0)]; |
59 |
picker.delegate = self; |
60 |
picker.dataSource = self; |
61 |
picker.showsSelectionIndicator = NO; |
62 |
|
63 |
//Resize the picker, rotate it so that it is horizontal and set its position |
64 |
CGAffineTransform rotate = picker.transform; |
65 |
rotate = CGAffineTransformRotate(rotate, 4.71238898); |
66 |
rotate = CGAffineTransformScale(rotate, kScaleX, kScaleY); |
67 |
CGAffineTransform t0 = CGAffineTransformMakeTranslation(3, 22.5); |
68 |
picker.transform = CGAffineTransformConcat(rotate,t0); |
69 |
[self addSubview:picker]; |
70 |
|
71 |
// place a mask over the picker to hide the dark outlined area |
72 |
UIImageView *mask = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"image_picker_mask.png"]]; |
73 |
mask.userInteractionEnabled = NO; |
74 |
//mask.opaque = YES; //for performance |
75 |
mask.frame = CGRectMake(0.0, 0.0, 320.0, 87.0); |
76 |
[self addSubview:mask]; |
77 |
[self bringSubviewToFront:mask]; |
78 |
[mask release]; |
79 |
[picker release]; |
80 |
|
81 |
|
82 |
} |
83 |
return self; |
84 |
} |
85 |
|
86 |
#pragma mark - |
87 |
#pragma mark Picker View |
88 |
|
89 |
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { |
90 |
return 1; |
91 |
} |
92 |
|
93 |
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { |
94 |
return 9; |
95 |
} |
96 |
|
97 |
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { |
98 |
if (row == 0) { |
99 |
selectedFamily = @"ubuntu"; |
100 |
} else if (row == 1) { |
101 |
selectedFamily = @"redhat"; |
102 |
} else if (row == 2) { |
103 |
selectedFamily = @"gentoo"; |
104 |
} else if (row == 3) { |
105 |
selectedFamily = @"windows"; |
106 |
} else if (row == 4) { |
107 |
selectedFamily = @"debian"; |
108 |
} else if (row == 5) { |
109 |
selectedFamily = @"centos"; |
110 |
} else if (row == 6) { |
111 |
selectedFamily = @"arch"; |
112 |
} else if (row == 7) { |
113 |
selectedFamily = @"fedora"; |
114 |
} else { |
115 |
selectedFamily = kCustomImage; |
116 |
} |
117 |
|
118 |
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kImages] withRowAnimation:UITableViewRowAnimationFade]; |
119 |
//[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:kImageFamily] atScrollPosition:UITableViewScrollPositionBottom animated:NO]; |
120 |
} |
121 |
|
122 |
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { |
123 |
UIView *viewForRow = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 280, 94)] autorelease]; |
124 |
|
125 |
NSString *filename = @""; |
126 |
NSString *family = @""; |
127 |
|
128 |
if (row == 0) { |
129 |
filename = @"ubuntu-icon.png"; |
130 |
family = @"Ubuntu"; |
131 |
} else if (row == 1) { |
132 |
filename = @"redhat-icon.png"; |
133 |
family = @"Red Hat"; |
134 |
} else if (row == 2) { |
135 |
filename = @"gentoo-icon.png"; |
136 |
family = @"Gentoo"; |
137 |
} else if (row == 3) { |
138 |
filename = @"windows-icon.png"; |
139 |
family = @"Windows"; |
140 |
} else if (row == 4) { |
141 |
filename = @"debian-icon.png"; |
142 |
family = @"Debian"; |
143 |
} else if (row == 5) { |
144 |
filename = @"centos-icon.png"; |
145 |
family = @"CentOS"; |
146 |
} else if (row == 6) { |
147 |
filename = @"arch-icon.png"; |
148 |
family = @"Arch"; |
149 |
} else if (row == 7) { |
150 |
filename = @"fedora-icon.png"; |
151 |
family = @"Fedora"; |
152 |
} else { |
153 |
filename = @"openstack_icon.png"; |
154 |
family = @"Custom"; |
155 |
} |
156 |
|
157 |
|
158 |
|
159 |
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:filename]]; |
160 |
|
161 |
img.frame = CGRectMake(86.0, -30.0, 110.0, 110.0); |
162 |
img.opaque = YES; |
163 |
[viewForRow addSubview:img]; |
164 |
[img release]; |
165 |
|
166 |
UILabel *label; |
167 |
|
168 |
UIFont *font = [UIFont boldSystemFontOfSize:20.0]; |
169 |
|
170 |
label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 90, 278, 35)] autorelease]; |
171 |
|
172 |
label.text = family; |
173 |
label.textAlignment = UITextAlignmentCenter; |
174 |
label.textColor = [UIColor blackColor]; |
175 |
label.font = font; |
176 |
label.backgroundColor = [UIColor clearColor]; |
177 |
label.opaque = NO; |
178 |
[viewForRow addSubview:label]; |
179 |
|
180 |
//CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57); |
181 |
//[viewForRow setTransform:rotate]; |
182 |
|
183 |
CGAffineTransform rotate = viewForRow.transform; |
184 |
rotate = CGAffineTransformRotate(rotate, -4.71238898); |
185 |
rotate = CGAffineTransformScale(rotate, kScaleX, kScaleY); |
186 |
|
187 |
|
188 |
CGAffineTransform t0 = CGAffineTransformMakeTranslation(3, 22.5); |
189 |
viewForRow.transform = CGAffineTransformConcat(rotate,t0); |
190 |
|
191 |
return viewForRow; |
192 |
} |
193 |
|
194 |
|
195 |
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { |
196 |
|
197 |
[super setSelected:selected animated:animated]; |
198 |
|
199 |
// Configure the view for the selected state |
200 |
} |
201 |
|
202 |
- (void)dealloc { |
203 |
[account release]; |
204 |
[tableView release]; |
205 |
[images release]; |
206 |
[selectedFamily release]; |
207 |
[super dealloc]; |
208 |
} |
209 |
|
210 |
|
211 |
@end |