2 // ImageFamilyPickerCell.m
5 // Created by Mike Mayo on 10/23/10.
6 // The OpenStack project is provided under the Apache 2.0 license.
9 #import "ImageFamilyPickerCell.h"
10 #import "OpenStackAccount.h"
13 #define kScaleY 1.53061224
14 #define kScaleX .29109589
16 #define kPickerY -86.0
18 #define kImageFamily 3
21 @implementation ImageFamilyPickerCell
23 @synthesize account, tableView, images, selectedFamily;
26 NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:9];
27 NSArray *stringKeys = [NSArray arrayWithObjects:@"ubuntu", @"redhat", @"gentoo", @"centos", @"debian", @"windows", @"arch", kCustomImage, @"fedora", nil];
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];
38 NSMutableArray *keyedImages = [dict objectForKey:stringKey];
39 [keyedImages addObject:image];
44 images = [[NSDictionary alloc] initWithDictionary:dict];
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
52 self.account = openStackAccount;
53 self.tableView = aTableView;
54 selectedFamily = @"ubuntu";
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;
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];
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];
87 #pragma mark Picker View
89 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
93 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
97 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
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";
115 selectedFamily = kCustomImage;
118 [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kImages] withRowAnimation:UITableViewRowAnimationFade];
119 //[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:kImageFamily] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
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];
125 NSString *filename = @"";
126 NSString *family = @"";
129 filename = @"ubuntu-icon.png";
131 } else if (row == 1) {
132 filename = @"redhat-icon.png";
134 } else if (row == 2) {
135 filename = @"gentoo-icon.png";
137 } else if (row == 3) {
138 filename = @"windows-icon.png";
140 } else if (row == 4) {
141 filename = @"debian-icon.png";
143 } else if (row == 5) {
144 filename = @"centos-icon.png";
146 } else if (row == 6) {
147 filename = @"arch-icon.png";
149 } else if (row == 7) {
150 filename = @"fedora-icon.png";
153 filename = @"openstack_icon.png";
159 UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:filename]];
161 img.frame = CGRectMake(86.0, -30.0, 110.0, 110.0);
163 [viewForRow addSubview:img];
168 UIFont *font = [UIFont boldSystemFontOfSize:20.0];
170 label = [[[UILabel alloc] initWithFrame:CGRectMake(0, 90, 278, 35)] autorelease];
173 label.textAlignment = UITextAlignmentCenter;
174 label.textColor = [UIColor blackColor];
176 label.backgroundColor = [UIColor clearColor];
178 [viewForRow addSubview:label];
180 //CGAffineTransform rotate = CGAffineTransformMakeRotation(1.57);
181 //[viewForRow setTransform:rotate];
183 CGAffineTransform rotate = viewForRow.transform;
184 rotate = CGAffineTransformRotate(rotate, -4.71238898);
185 rotate = CGAffineTransformScale(rotate, kScaleX, kScaleY);
188 CGAffineTransform t0 = CGAffineTransformMakeTranslation(3, 22.5);
189 viewForRow.transform = CGAffineTransformConcat(rotate,t0);
195 - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
197 [super setSelected:selected animated:animated];
199 // Configure the view for the selected state
206 [selectedFamily release];