//  Created by Joe Becker on 3/7/05.
//  Copyright 2005 __MyCompanyName__. All rights reserved.

#import "AppController.h"
#import "TrackingGraphView.h"
#import "NavigationView.h"
#import "StatView.h"
#import "DataView.h"

@implementation AppController

- (void)openDocument:(id)sender
{
	[super openDocument:sender];
	
	[navController  setGmtShipTrack:gmtShipTrack];
	[dataController setGmtShipTrack:gmtShipTrack];
	[statController setGmtShipTrack:gmtShipTrack];
	
	// this next one seems out of order, but the "graph: " method reads the "cartCountCell", so if we don't clear
	// that cell first, the carter count will not get set to zero.
	[[[dataController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	[[[statController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	
	
	[[navController graphView] graph:self];
	[[navController graphView] zoomToDataExtent:gmtShipTrack];
	[[navController graphView] setFormula:aFile];
	
	[[dataController graphView] graph:self];
	[[dataController graphView] zoomToDataExtent:gmtShipTrack];
	[[dataController graphView] setFormula:aFile];
	
	[[statController graphView] graph:self];
	[[statController graphView] zoomToDataExtent:gmtShipTrack];
	[[statController graphView] setFormula:aFile];
	
	//return;	
	[[[navController graphView] window] makeKeyAndOrderFront:self];
	[[[navController graphView] window] setAcceptsMouseMovedEvents:YES];
	[[[navController graphView] window] makeFirstResponder:[navController graphView]];

}

- (IBAction)addCarter:(id)sender {
	
	[gmtShipTrack addCarterCorrection];
	[(StatView *)[statController graphView] updateStatsFields];
	
	[[[dataController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	[[[statController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	
	[[navController graphView] graph:self];
	[[dataController graphView] graph:self];
	[[statController graphView] graph:self];
}

- (IBAction)subCarter:(id)sender {
	
	[gmtShipTrack subCarterCorrection];
	[(StatView *)[statController graphView] updateStatsFields];
	
	[[[dataController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	[[[statController graphView] carterCountCell] setDoubleValue:[gmtShipTrack carterCount]];
	
	[[navController graphView] graph:self];
	[[dataController graphView] graph:self];
	[[statController graphView] graph:self];
}


@end
