All pastes #809699 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-12-09 04:25 UTC
rendered paste body
#import "iConverter.h"
#import "MainView.h"
#import "TwoView.h"

static MainView *sharedInstance = nil;
BOOL curveIsEnabled = YES;
BOOL forceGridView = NO;

@implementation UIView (Color)

+ (CGColorRef)colorWithRed:(float)red green:(float)green blue:(float)blue alpha:(float)alpha;
{
    float rgba[4] = {red, green, blue, alpha};
    CGColorSpaceRef rgbColorSpace = (CGColorSpaceRef)[(id)CGColorSpaceCreateDeviceRGB() autorelease];
    CGColorRef color = (CGColorRef)[(id)CGColorCreate(rgbColorSpace, rgba) autorelease];
    return color;
}

@end


@implementation MainView

+ (MainView *) sharedInstance {
	return ( sharedInstance ? sharedInstance : ( sharedInstance = [[self alloc] init] ) );
}



-(id)init{
	struct CGRect rect = [UIHardware fullScreenApplicationContentRect];
    rect.origin.x = rect.origin.y = 0.0f;

	return [self initWithFrame:rect];	
}

// designated initializer
-(id)initWithFrame:(CGRect) rect {
	self = [super initWithFrame: rect];
 
	sharedInstance = self;


	topBar = [[UINavigationBar alloc] init];
	[topBar setFrame:CGRectMake(0.0f, 0.0f, 320.0f, 48.0f)];
 	[topBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle: @"iConverter"]];
	[topBar showButtonsWithLeftTitle: @"Quit" rightTitle: @"About" leftBack: YES ]; 
	[topBar enableAnimation];
	[topBar setBarStyle:0];
	[topBar setDelegate:self];

// prefs table begin ------
	
	UIPreferencesTable *preferencesTable = [[UIPreferencesTable alloc] initWithFrame:CGRectMake(0.0f, 45.0f, 320.0f, 415.0f)];	

	CGRect switchRect = CGRectMake(rect.size.width - 114.0f, 9.0f, 96.0f, 32.0f);
	CGRect installButtonRect = CGRectMake(20.0f, 9.0f, 100.0f, 46.0f);

	[preferencesTable setDataSource: self];
	[preferencesTable setDelegate: self];
	
	optionsGroup = [[UIPreferencesTableCell alloc] init];
	[optionsGroup setTitle:@"Enter Units"];

        geometryCell = [[UIPreferencesTextTableCell alloc] init];
	[geometryCell setTitle: @"Number of Units:"];
	[[geometryCell textField] setPreferredKeyboardType: 1];
	[geometryCell setValue:@""];

	
	forceGridViewCell = [[UIPreferencesTableCell alloc] init];
	[forceGridViewCell setTitle: @"Conversion Type: "];
	forceGridViewSwitch = [[UISwitchControl alloc] initWithFrame: switchRect];
	[forceGridViewSwitch setValue: forceGridView];
	[forceGridViewCell addSubview: forceGridViewSwitch];
	
	entriesCell = [[UIPreferencesTableCell alloc] init];
	[entriesCell setTitle: @"Edit Stack Contents"];

	installGroup = [[UIPreferencesTableCell alloc] init];
	[installGroup setTitle:@"Converted Total"];
	
	installCell = [[UIPreferencesTableCell alloc] init];

// Conversion Types	
	terminateGroup = [[UIPreferencesTableCell alloc] init];
	[terminateGroup setTitle:@"Select A Conversion"];

        TypeCentimeterToInches = [[UIPreferencesTextTableCell alloc] init];
	[TypeCentimeterToInches setTitle: @"Number of Units:"];
	[[TypeCentimeterToInches textField] setPreferredKeyboardType: 1];
	[TypeCentimeterToInches setValue:@""];

        TypeMTCell = [[UIPreferencesTableCell alloc] init];
	[TypeMTCell setTitle: @"Number of Units:"];
	[TypeMTCell setChecked:TRUE];

// End Conversion Types
	

	CGRect left = CGRectMake(0.0f, 0.0f, 14.0f, 46.0f);	
	CGRect middle = CGRectMake(14.0f, 0.0f, 1.0f, 46.0f);
	CGRect right = CGRectMake(15.0f, 0.0f, 14.0f, 46.0f);
	CDAnonymousStruct4 slices = { left, middle, right };

	installButton = [[UIThreePartButton alloc] initWithTitle:@"Convert"];
	[installButton setEnabled:YES];
	[installButton setAutosizesToFit:NO];
	[installButton setFrame:installButtonRect];
	[installButton setBackgroundSlices:slices];
	[installButton setBackgroundImage:[UIImage applicationImageNamed:@"UIButtonLarge.png"] ];
	[installButton setTitleColor:[UIView colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0] forState:0];
	[installButton addTarget:self action:@selector(installStack:) forEvents:1];

	[installCell addSubview: installButton];

// prefs table end  ------

	bottomNavBar = [[UINavigationBar alloc] init];
	[bottomNavBar setFrame:CGRectMake(rect.origin.x, 415.0f, rect.size.width, 45.0f)];
	[bottomNavBar showLeftButton:nil withStyle:0 rightButton:@"Convert" withStyle:0];
	[bottomNavBar setDelegate:self];
	[bottomNavBar enableAnimation];


	[self addSubview:topBar];
	[self addSubview:preferencesTable];
	[self addSubview:bottomNavBar];
	[preferencesTable reloadData];

	return self;
}


// -----------------------------------------------------------------------------------
// - These classes create and control the Alert Box
// -----------------------------------------------------------------------------------
- (void)showAlert:(NSString *)aMessage withTitle:(NSString *)aTitle
{
	UIAlertSheet *alertSheet = [[UIAlertSheet alloc] initWithFrame:CGRectMake(0, 240, 320, 240)];
	[alertSheet setTitle:aTitle];
	[alertSheet setBodyText:aMessage];
	[alertSheet addButtonWithTitle:@"OK"];
	[alertSheet setDelegate:self];
	[alertSheet popupAlertAnimated:YES];
}


- (void)alertSheet:(UIAlertSheet *)sheet buttonClicked:(int)button
{
	[sheet dismissAnimated:YES];
}
// -----------------------------------------------------------------------------------
// - These classes create the Preference Table Groups, Cells And Rows
// -----------------------------------------------------------------------------------
- (UIPreferencesTableCell *)preferencesTable: (UIPreferencesTable *)table cellForRow: (int)row inGroup: (int)group {
	switch(group) {
		case 0: return optionsGroup;
		case 1:
			switch(row) {
				case 0: return geometryCell;
				case 1: return forceGridViewCell;
				case 2: return entriesCell;
				
		}
		case 2: return installGroup;
		case 3:
			switch(row) {
				case 0: return installCell;
			}
		case 4: return terminateGroup;
		case 5:
			switch(row) {
				case 0: return TypeMTCell;
				case 1: return TypeCentimeterToInches;
			}

		default: return nil;
	}
}


- (int) numberOfGroupsInPreferencesTable: (UIPreferencesTable *)table {
	return 7;
}


- (int) preferencesTable: (UIPreferencesTable *)table numberOfRowsInGroup: (int) group {
	switch(group) {
		case 0: return 0;
		case 1: return 2;
		case 2: return 0;
		case 3: return 1;
		case 4: return 1;
		case 5: return 2;
		default: return 0;
	}
}

- (UIPreferencesTableCell *)preferencesTable: (UIPreferencesTable *)table cellForGroup: (int)group {
	switch(group) {
		case 0: return optionsGroup;
		case 2: return installGroup;
		case 4: return terminateGroup;

		default: return nil;
	}
}

- (float)preferencesTable: (UIPreferencesTable *)table heightForRow: (int)row inGroup:(int)group withProposedHeight: (float)proposed {
	switch(group) {
		case 0: return 26.0f;
		case 2: return 26.0f;
		case 3:
			switch (row)
			{
			case 0 : return (46.0f+18.0f);
			case 1 : return (46.0f+18.0f);
			}
		case 4: return 18.0f;
		case 5:
			switch (row)
			{
			case 0 : return (46.0f+26.0f);
			case 1 : return (46.0f+26.0f);
			}
		default: return proposed;
	}
}


// -----------------------------------------------------------------------------------
// - This class catches the NavBar Control events
// -----------------------------------------------------------------------------------
-(void)navigationBar:(UINavigationBar*)bar buttonClicked:(int)button{

	if(bar == bottomNavBar) {
		// buttom navBar
		[[UITransitionApplication sharedInstance] showView:[TwoView sharedInstance]];
		return;

	}
	if (button == 0)//right, go to the help screen
	{
		
		[self showAlert:@"This application was developed by Jonathan McAllister coutesy of the iPhoneDevNetwork \n Please visit http://www.iphonedevnetwork.com/ " withTitle:@"About"];

		[[UITransitionApplication sharedInstance] showView:[MainView sharedInstance]];
		return;

	
	}

	if (button == 1) //left, go to the about screen
	{

		exit(0);

	}
}


- (void)(UIPreferencesTableCell *)preferencesTable: tableRowSelected
{
 
	switch ([preferencesTable selectedRow)] 
	{


				case 0: [self showAlert:@"This application was developed by Jonathan McAllister coutesy of the iPhoneDevNetwork \n Please visit http://www.iphonedevnetwork.com/ " withTitle:@"About"];
				case 1: return TypeCentimeterToInches;


	}
}



@end