/* TimerInspector.m
 * Written By:  Thomas Burkholder
 *
 * You may freely copy, distribute, and reuse the code in this example.
 * NeXT disclaims any warranty of any kind, expressed or  implied, as to its
 * fitness for any particular use.
 */


#import "TimerInspector.h"

@implementation Timer (AttributesInspector)

- (const char *)getInspectorClassName
{
	return "TimerInspector";
}

- (NXImage *)getIBImage
{
	return [NXImage findImageNamed:"TimerIcon"];
}

@end

@implementation TimerInspector

static int thresholds[] = {NX_BASETHRESHOLD, 
							NX_RUNMODALTHRESHOLD, 
							NX_MODALRESPTHRESHOLD};
- init
{
	char buf[MAXPATHLEN+1];
	NXBundle *bundle;
	[super init];
	bundle = [NXBundle bundleForClass:[Timer class]];
	[bundle getPath:buf forResource:"TimerInspector" ofType:"nib"];
	[NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
	return self;
}

- ok:sender
{
	[window disableFlushWindow];
	[object setPeriod:[periodField doubleValue]];
	[object setPriority:[priorityField intValue]];
	[object setVisibleDebug:[visibleDebugSwitch state]];
	[object setWrap:[wrapSwitch state]];
	[object setSync:[syncSwitch state]];
	[object setSyncValue:[syncValueField intValue]];
	[object setStartValue:[startValueField floatValue]];
	[object setWrapValue:[wrapValueField floatValue]];
	[object setIncrementBy:[incrementByField floatValue]];
	[self revertInspector:sender];
	[window reenableFlushWindow];
	[window flushWindow];
	return [super ok:sender];
}

- revertInspector:sender
{
	[periodField setDoubleValue:[object period]];
	[priorityField setIntValue:[object priority]];
	[visibleDebugSwitch setState:[object visibleDebug]];
	[wrapSwitch setState:[object wrap]];
	[syncSwitch setState:[object sync]];
	[syncValueField setIntValue:[object syncValue]];
	[startValueField setFloatValue:[object startValue]];
	[wrapValueField setFloatValue:[object wrapValue]];
	[incrementByField setFloatValue:[object incrementBy]];
	return self;
}

- revert:sender
{
	[window disableFlushWindow];
	[self revertInspector:sender];
	[window reenableFlushWindow];
	[window flushWindow];
	return [super revert:sender];
}

- thresholdPopped:sender
{
	int val;
	val = [[sender selectedCell] tag];
	if (val < 0)
		return self;
	[priorityField setIntValue:thresholds[val]];
	return [self ok:self];
}

- (BOOL)wantsButtons
{
	return NO;
}

@end
