
#import "IconController.h"

@implementation IconController


//** designated initializer
- init
{
	NSMutableArray	*temp;

	if (self = [super init]) {
		animator = [[MiscAppIconAnimator alloc] init];

		//** create array of images
		temp = [NSMutableArray array];
		[temp addObject:[NXImage findImageNamed:"Bronto"]];
		[temp addObject:[NXImage findImageNamed:"Raptor"]];
		[temp addObject:[NXImage findImageNamed:"TriTop"]];
		[animator setImageArray:temp];

		//** create array of pattern order
		temp = [NSMutableArray array];
		[temp addObject:[NSNumber numberWithInt:0]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:2]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:2]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:2]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:2]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:2]];
		[temp addObject:[NSNumber numberWithInt:1]];
		[temp addObject:[NSNumber numberWithInt:0]];
		[animator setAnimationPattern:temp];

		[animator setPatternLoops:1 ];
		return self;
	}
	return nil;
}

-free
{
	if (animator)
		[animator autorelease];
	return [super free];
}

- animate:sender
{
	[animator startAnimation:sender];
	[button setEnabled:YES];
    return self;
}

- stopAnimate:sender
{
	[animator stopAnimation];
	[button setEnabled:NO];
//	[animator displayImageAtIndex:2];
    return self;
}

- save:sender
{
	//** open file and save data
	if (![NSArchiver archiveRootObject:animator toFile:@"/Net/java/Users/Developers/t641_craig/anim.tst"]) {
		NXRunAlertPanel("File Alert", "Save failed!  Unable to write file.", NULL, NULL, NULL);
		return nil;
	}

	return self;
}

- load:sender
{
	//** open file and read data
	animator = [NSUnarchiver unarchiveObjectWithFile:@"/Net/java/Users/Developers/t641_craig/anim.tst"];
	if (!animator) {
		NXRunAlertPanel("File Alert", "Open failed!  Unable to read file.", NULL, NULL, NULL);
		return nil;
	}
	[animator retain];

	return self;
}



@end
