
/*---------------------------------------------------------

	Inspector for a Palette object
	
	This is an inspector for a linePalette object.  you
	can set the line grey, arrow caps on the ends, and 
	the line width from it; it appears in the IB project
	window like any other IB inspector.
	
	The main methods are revert:, which queries the object
	it's inspecting and sets the inspector's state accordingly;
	ok: which applies the inspector's values to the object 
	being inspected; and init, which loads the nib file.  There
	are a couple class methods at the start for NeXt-ie stuff.

 ---------------------------------------------------------*/

#import "LinesInspector.h"
#import "ActionLine.h"

#import <nib/InterfaceBuilder.h>
#import <appkit/Application.h>
#import <appkit/Cell.h>
#import <appkit/NXColorWell.h>
#import <appkit/Control.h>
#import <appkit/Matrix.h>
#import <appkit/NXColorPanel.h>
#import <appkit/NXColorWell.h>
#import <appkit/Scroller.h>
#import <appkit/TextField.h>

@implementation LinesInspector

/*
 * finishLoading: and startUnloading are required 
 * for dynamic loading. If you are building a custom 
 * Interface Builder, these methods can be removed.
 */
 
+ finishLoading:(struct mach_header *)header 
{
    NIBDidLoadClass(self, header);
    return nil;
}

+ startUnloading 
{
    NIBWillUnloadClass(self);
    return nil;
}

- init
{
	/*---------------------------------------------------------
	   Load the nib file.
	---------------------------------------------------------*/
	
    [super init];
    [NXApp loadNibSection:"LinesInspector.nib" owner:self];
				
    return self;
}

- revert:sender
{
	/*---------------------------------------------------------
    set the state of the inspector to equal the state of the
		object being inspected.
		
		"object" is a NeXT sorta thing for the palette object.
		Things are pretty wild and wooly in 2.x.
	---------------------------------------------------------*/
		
		// Set the state of the checkboxes to reflect the existence of line caps/arrows.
		
	[[lineCapsRadio cellAt:0:0] setState:[object startArrow]];
	[[lineCapsRadio cellAt:1:0] setState:[object endArrow]];
	[lineCapsRadio display];
	
		// Get the line width reflected correctly, both in the scroller and a text field.
			
	[widthScroller setFloatValue:[object lineWidth]];
	[widthScroller display];
	[lineWidthField setFloatValue:[object lineWidth]];
	[lineWidthField display];
	
	[enabledCheck setState:[object isEnabled]];

		// Get the greyscale/color reflected correctly in the color well.
	
	if([enabledCheck state])	
		[lineColorWell setColor:[object enabledColor]];
	 else
		[lineColorWell setColor:[object disabledColor]];
	
						
  return [super revert:sender];
}

- ok:sender
{
	/*---------------------------------------------------------
	   Set the state of the object to reflect that of
		 the inspector.
	---------------------------------------------------------*/
	
				// Line width.
				
		[object setLineWidth:[widthScroller floatValue]];
		
				// Line color
		
		if([enabledCheck state])				
			[object setEnabledColor:[lineColorWell color]];
		 else
		 	[object setDisabledColor:[lineColorWell color]];
		
			// Arrows on the ends.
			
		[object setStartArrow:[[lineCapsRadio cellAt:0:0] state]];
		[object setEndArrow:[[lineCapsRadio cellAt:1:0] state]];
		
		[object setEnabled:[enabledCheck state]];
	
    return [super ok:sender];
}

- setColorHit:sender;												// color button hit
{
  /*--------------------------------------------------------------------
	   One of the buttons that can set the color of the line to one of
		 the box-stock NXGRAYS has been hit.  Figure out which by the
		 cell position, and set the color well appropriately.
	--------------------------------------------------------------------*/
	NXColor	stockGray;
		
	switch([sender selectedRow])
		{
			case WHITE_BUTTON: 	stockGray = NX_COLORWHITE;
													break;
							
		  case LTGRAY_BUTTON: stockGray = NX_COLORLTGRAY;
													break;
							
			case DKGRAY_BUTTON: stockGray = NX_COLORDKGRAY;
													break;
							
			case BLACK_BUTTON: 	stockGray = NX_COLORBLACK;
													break;
		}
		
	[lineColorWell setColor:stockGray];
	
	return self;
}		

- setEnabledHit:sender;											// enabled check box hit
{
  /*---------------------------------------------------------------------
	   Switch some stuff around so we can get into the other mode.
		 eg, the line color well should reflect the "enabled" state 
		 if that check is on, so we can use the same color well to set
		 both the enabled and disabled colors.  This UI has some 
		 usability problems, but it's OK for now.
	---------------------------------------------------------------------*/
		
	if([enabledCheck state])
		{
			[lineColorBox setTitle:"Enabled line color"];
			[lineColorWell setColor:[object enabledColor]];
		}
	 else
	 	{
			[lineColorBox setTitle:"Disabled line color"];
			[lineColorWell setColor:[object disabledColor]];
		}
	
	[lineColorBox display];
		
	return self;
}

- colorPanelHit:sender;											// user wants to see the color panel
{
  /*---------------------------------------------------------------------
	   Bring up a color panel so the user can set something besides greys.
	---------------------------------------------------------------------*/
	
	[[NXColorPanel newColorMask:NX_ALLMODESMASK] makeKeyAndOrderFront:self];
	
	return self;
}
	
@end
