
#import "UHLineShapeInspector.h"
#import "UHLineShape.h"

@implementation UHLineShapeInspector

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

- setUpAngleBox
{
	if (choice == UH_VARIABLESLOPE){
		[[angleBox cell] setEnabled:YES];
		[angleSlider setFloatValue:[object angle]];
		[angleSlider setEnabled:YES];
		[angleText setFloatValue:[object angle]];
		[angleText setEditable:YES];
		[angleText setBackgroundGray:NX_WHITE];
		[minAngle setTextGray:NX_BLACK];
		[maxAngle setTextGray:NX_BLACK];
	}
	else {
		[[angleBox cell] setEnabled:NO];
		[angleSlider setFloatValue:0.0];
		[angleSlider setEnabled:NO];
		[angleText setStringValue:""];
		[angleText setEditable:NO];
		[angleText setBackgroundGray:NX_LTGRAY];
		[minAngle setTextGray:NX_DKGRAY];
		[maxAngle setTextGray:NX_DKGRAY];
	}
	return self;
}
- revert:sender
{
	[lineWidthSlider setFloatValue:[object lineWidth]];
	[lineWidthText setFloatValue:[object lineWidth]];
	[lineColorWell setColor: [object lineColor]]; 
	[tagText setIntValue:[object tag]];
	
	/* Set popuplist to reflect the correct choice of line type. */
	choice=[object choice];
	[choiceButton setTitle:[[choiceMenu findCellWithTag:choice] title]];
	
	[self setUpAngleBox];
	
	return [super revert:sender];	
}

- lineChoice:sender
{
	choice = [sender selectedTag];
 	[object setChoice:choice];
	[self setUpAngleBox];
	[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==angleSlider){
		[angleText setFloatValue:[sender floatValue]];
		[object setAngle:[sender floatValue]];
	}
	if(sender==angleText){
		[angleSlider setFloatValue:[sender floatValue]];
		[object setAngle:[sender floatValue]];
	}
	if(sender==tagText)[object setTag:[tagText intValue]];
	if(sender==lineColorWell)[object setLineColor:[lineColorWell color]];
				
	return [super ok:sender];
}

- (BOOL)wantsButtons
{
    return NO;
}

@end
