
#import "UHShapeInspector.h"
#import "UHShape.h"

@implementation UHShapeInspector

- init
{
    char buf[MAXPATHLEN + 1];
    id bundle;
    
    [super init];
    
    bundle = [NXBundle bundleForClass:[self class]];
    [bundle getPath:buf 
            forResource:[self name] 
            ofType:"nib"];
    [NXApp loadNibFile:buf 
           owner:self 
           withNames:NO 
           fromZone:[self zone]];
    return self;
}

- revert:sender
{
	[lineWidthSlider setFloatValue:[object lineWidth]];
	[lineWidthText setFloatValue:[object lineWidth]];
	[lineColorWell setColor: [object lineColor]]; 
	[fillColorWell setColor: [object fillColor]]; 
	[borderedButton setState:[object isBordered]];
	[filledButton setState:[object isFilled]];
	[tagText setIntValue:[object tag]];
	
	/* Set radio button to reflect the correct choice of shape. */
	choice=[object choice];
	[choiceMatrix selectCellWithTag:choice];
	
	return [super revert:sender];	
}

- selectChoice:sender
{
	choice = [sender selectedTag];
 	[object setChoice:choice];
	[super ok:sender];
	return self;
}

- ok:sender
{
	if(sender==lineWidthSlider){
		[lineWidthText setFloatValue:[sender floatValue]];
		[object setLineWidth:[sender floatValue]];
	}
	if(sender==lineWidthText){
		[lineWidthSlider setFloatValue:[sender floatValue]];
		[object setLineWidth:[sender floatValue]];
	}
	if(sender==tagText)[object setTag:[sender intValue]];
	if(sender==lineColorWell)[object setLineColor:[sender color]];
	if(sender==fillColorWell)[object setFillColor:[sender color]];
	if(sender==borderedButton)[object setBordered:[sender state]];		
	if(sender==filledButton)[object setFilled:[sender state]];		
	return [super ok:sender];
}

- (BOOL)wantsButtons
{
    return NO;
}

@end
