//
//  EXPSetupWindowController.m
//  Expression
//
//  Created by ashley on 04/01/2009.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "EXPSetupWindowController.h"
#import "EXPDocument.h"
#import "EXPModelObject.h"

@implementation EXPSetupWindowController

- (id)init
{
	[NSBundle loadNibNamed:@"EXPSetupWindow" owner:self];
	[super initWithWindow:[self window]];
    return self;
}

- (void) setDocument:(id)document
{
	_doc = document;
}

- (id) document
{
	return _doc;
}

- (void) refresh
{
	EXPDocument *doc = [self document];
	EXPModelObject *modelObject = [doc modelObject];
	[StartTimeField setStringValue:[modelObject option:@"tstart"]];
	[StopTimeField setStringValue:[modelObject option:@"tstop"]];
	[OutstepField setStringValue:[modelObject option:@"outstep"]];
	[ToleranceField setStringValue:[modelObject option:@"epsilon"]];
	
	[ModelNameField setStringValue:[modelObject name]];
	
	[integratorButton removeAllItems];
	[integratorButton addItemWithTitle:@"Runge Kutta 2(3) + Delay"];
	
	BOOL fixedStep = [modelObject fixedStep];
	[fixedStepButton setState:fixedStep?NSOnState:NSOffState];

}	

- (IBAction) doneButtonPressed:(id)sender
{
	[[self window] orderOut:self];

	EXPDocument *document = [self document];
	EXPModelObject *modelObject = [document modelObject];
	[modelObject setOption:[StartTimeField stringValue] forName:@"tstart"];
	[modelObject setOption:[StopTimeField stringValue] forName:@"tstop"];
	[modelObject setOption:[OutstepField stringValue] forName:@"outstep"];
	[modelObject setOption:[ToleranceField stringValue] forName:@"epsilon"];
	[modelObject setName:[ModelNameField stringValue]];

} 

@end