|
| 1 | +/* |
| 2 | + File: AtomicElement.m |
| 3 | + Abstract: Simple object that encapsulate the Atomic Element values and images for the states. |
| 4 | + Version: 1.11 |
| 5 | + |
| 6 | + Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple |
| 7 | + Inc. ("Apple") in consideration of your agreement to the following |
| 8 | + terms, and your use, installation, modification or redistribution of |
| 9 | + this Apple software constitutes acceptance of these terms. If you do |
| 10 | + not agree with these terms, please do not use, install, modify or |
| 11 | + redistribute this Apple software. |
| 12 | + |
| 13 | + In consideration of your agreement to abide by the following terms, and |
| 14 | + subject to these terms, Apple grants you a personal, non-exclusive |
| 15 | + license, under Apple's copyrights in this original Apple software (the |
| 16 | + "Apple Software"), to use, reproduce, modify and redistribute the Apple |
| 17 | + Software, with or without modifications, in source and/or binary forms; |
| 18 | + provided that if you redistribute the Apple Software in its entirety and |
| 19 | + without modifications, you must retain this notice and the following |
| 20 | + text and disclaimers in all such redistributions of the Apple Software. |
| 21 | + Neither the name, trademarks, service marks or logos of Apple Inc. may |
| 22 | + be used to endorse or promote products derived from the Apple Software |
| 23 | + without specific prior written permission from Apple. Except as |
| 24 | + expressly stated in this notice, no other rights or licenses, express or |
| 25 | + implied, are granted by Apple herein, including but not limited to any |
| 26 | + patent rights that may be infringed by your derivative works or by other |
| 27 | + works in which the Apple Software may be incorporated. |
| 28 | + |
| 29 | + The Apple Software is provided by Apple on an "AS IS" basis. APPLE |
| 30 | + MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION |
| 31 | + THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS |
| 32 | + FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND |
| 33 | + OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. |
| 34 | + |
| 35 | + IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL |
| 36 | + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 37 | + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 38 | + INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, |
| 39 | + MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED |
| 40 | + AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), |
| 41 | + STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE |
| 42 | + POSSIBILITY OF SUCH DAMAGE. |
| 43 | + |
| 44 | + Copyright (C) 2010 Apple Inc. All Rights Reserved. |
| 45 | + |
| 46 | + */ |
| 47 | + |
| 48 | +#import "AtomicElement.h" |
| 49 | + |
| 50 | + |
| 51 | +@implementation AtomicElement |
| 52 | + |
| 53 | +@synthesize atomicNumber; |
| 54 | +@synthesize name; |
| 55 | +@synthesize symbol; |
| 56 | +@synthesize state; |
| 57 | +@synthesize group; |
| 58 | +@synthesize period; |
| 59 | +@synthesize vertPos; |
| 60 | +@synthesize horizPos; |
| 61 | +@synthesize radioactive; |
| 62 | +@synthesize atomicWeight; |
| 63 | +@synthesize discoveryYear; |
| 64 | + |
| 65 | +- (id)initWithDictionary:(NSDictionary *)aDictionary { |
| 66 | + if ([self init]) { |
| 67 | + self.atomicNumber = [aDictionary valueForKey:@"atomicNumber"]; |
| 68 | + self.atomicWeight = [aDictionary valueForKey:@"atomicWeight"]; |
| 69 | + self.discoveryYear = [aDictionary valueForKey:@"discoveryYear"]; |
| 70 | + self.radioactive = [[aDictionary valueForKey:@"radioactive"] boolValue]; |
| 71 | + self.name = [aDictionary valueForKey:@"name"]; |
| 72 | + self.symbol = [aDictionary valueForKey:@"symbol"]; |
| 73 | + self.state = [aDictionary valueForKey:@"state"]; |
| 74 | + self.group = [aDictionary valueForKey:@"group"]; |
| 75 | + self.period = [aDictionary valueForKey:@"period"]; |
| 76 | + self.vertPos = [aDictionary valueForKey:@"vertPos"]; |
| 77 | + self.horizPos = [aDictionary valueForKey:@"horizPos"]; |
| 78 | + |
| 79 | + } |
| 80 | + return self; |
| 81 | +} |
| 82 | + |
| 83 | +- (void)dealloc { |
| 84 | + [atomicNumber release]; |
| 85 | + [atomicWeight release]; |
| 86 | + [discoveryYear release]; |
| 87 | + [name release]; |
| 88 | + [symbol release]; |
| 89 | + [state release]; |
| 90 | + [group release]; |
| 91 | + [period release]; |
| 92 | + [vertPos release]; |
| 93 | + [horizPos release]; |
| 94 | + [super dealloc]; |
| 95 | +} |
| 96 | + |
| 97 | +// this returns the position of the element in the classic periodic table locations |
| 98 | +-(CGPoint)positionForElement { |
| 99 | + return CGPointMake([[self horizPos] intValue] * 26-8,[[self vertPos] intValue]*26+35); |
| 100 | + |
| 101 | +} |
| 102 | + |
| 103 | +- (UIImage *)stateImageForAtomicElementTileView { |
| 104 | + return [UIImage imageNamed:[NSString stringWithFormat:@"%@_37.png",state]]; |
| 105 | +} |
| 106 | + |
| 107 | + |
| 108 | +- (UIImage *)stateImageForAtomicElementView { |
| 109 | + return [UIImage imageNamed:[NSString stringWithFormat:@"%@_256.png",state]]; |
| 110 | +} |
| 111 | + |
| 112 | +- (UIImage *)stateImageForPeriodicTableView { |
| 113 | + return [UIImage imageNamed:[NSString stringWithFormat:@"%@_24.png",state]]; |
| 114 | +} |
| 115 | + |
| 116 | + |
| 117 | +- (UIImage *)flipperImageForAtomicElementNavigationItem { |
| 118 | + |
| 119 | + // return a 30 x 30 image that is a reduced version |
| 120 | + // of the AtomicElementTileView content |
| 121 | + // this is used to display the flipper button in the navigation bar |
| 122 | + CGSize itemSize=CGSizeMake(30.0,30.0); |
| 123 | + UIGraphicsBeginImageContext(itemSize); |
| 124 | + |
| 125 | + UIImage *backgroundImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_30.png",state]]; |
| 126 | + CGRect elementSymbolRectangle = CGRectMake(0,0, itemSize.width, itemSize.height); |
| 127 | + [backgroundImage drawInRect:elementSymbolRectangle]; |
| 128 | + |
| 129 | + // draw the element name |
| 130 | + [[UIColor whiteColor] set]; |
| 131 | + |
| 132 | + // draw the element number |
| 133 | + UIFont *font = [UIFont boldSystemFontOfSize:8]; |
| 134 | + CGPoint point = CGPointMake(2,1); |
| 135 | + [[self.atomicNumber stringValue] drawAtPoint:point withFont:font]; |
| 136 | + |
| 137 | + // draw the element symbol |
| 138 | + font = [UIFont boldSystemFontOfSize:13]; |
| 139 | + CGSize stringSize = [self.symbol sizeWithFont:font]; |
| 140 | + point = CGPointMake((elementSymbolRectangle.size.width-stringSize.width)/2,10); |
| 141 | + |
| 142 | + [self.symbol drawAtPoint:point withFont:font]; |
| 143 | + |
| 144 | + UIImage *theImage=UIGraphicsGetImageFromCurrentImageContext(); |
| 145 | + UIGraphicsEndImageContext(); |
| 146 | + return theImage; |
| 147 | +} |
| 148 | + |
| 149 | + |
| 150 | + |
| 151 | +@end |
0 commit comments