ftp.nice.ch/pub/next/developer/resources/classes/UHInspector.1.2.N.bs.tar.gz#/UHInspector_1.2/InspectorDemo/Demo.m

This is Demo.m in view mode; [Download] [Up]

#import "Demo.h"
#import "UHInspectorManager.h"
#import "Clipper.h"
#import "Gain.h"
#import "Sine.h"

@implementation Demo

- init
{
	[super init];
	
	selection=[[List alloc] initCount:2];	//object selection list
	
	/* First get the inspector manager, which will load its own nib. */
	inspectorManager=[[UHInspectorManager alloc] init];
	[inspectorManager setDelegate:self];	//this object will get notifications
	[inspectorManager enableDoubleInspector:NO];
	
	/* Now get the objects to be inspected for this demo. Not all inspectable objects
		must respond to setLabel:, but I know that these do. */
	clipper1=[[[Clipper alloc] init] setLabel:"clipper 1"];
	clipper2=[[[Clipper alloc] init] setLabel:"clipper 2"];
	gain1=[[[Gain alloc] init] setLabel:"gain 1"];
	gain2=[[[Gain alloc] init] setLabel:"gain 2"];
	sine=[[[Sine alloc] init] setLabel:"sine"];
	return self;
}

/* The demo window has radio buttons to request various inspections. */
- doInspect:sender
{	
	switch([sender selectedTag]){
		case 0:		//an item that has no inspector (this object!)
			[inspectorManager inspect:self requestor:self];
			break;
		case 1:		//a clipper instance
			[inspectorManager inspect:clipper1 requestor:self];
			break;
		case 2:		//a different clipper instance
			[inspectorManager inspect:clipper2 requestor:self];
			break;
		case 3:		//a gain instance
			[inspectorManager inspect:gain1 requestor:self];
			break;
		case 4:		//a different gain instance
			[inspectorManager inspect:gain2 requestor:self];
			break;
		case 5:		//two clippers
			[selection empty];
			[selection addObject:clipper1];
			[selection addObject:clipper2];
			[inspectorManager inspectList:selection requestor:self];
			break;
		case 6:		//two gains
			[selection empty];
			[selection addObject:gain1];
			[selection addObject:gain2];
			[inspectorManager inspectList:selection requestor:self];
			break;
		case 7:		//a clipper and a gain
			[selection empty];
			[selection addObject:clipper1];
			[selection addObject:gain1];
			[inspectorManager inspectList:selection requestor:self];
			break;
		case 8:		//a sine (example of inspector with buttons)
			[inspectorManager inspect:sine requestor:self];
			break;
	}
    return self;
}

/* Message to delegate from UHInspectorManager when inspector is changed in inspector manager. */
- inspectorChanged:sender
{
	sprintf(buf,"Inspector changed to %s.",[[sender currentInspector] name]);
	[delegateMsgField setStringValue:buf];
	return self;
}

/* Message to requestor from inspector (UHInspector subclass) when a single object is inspected. */
- objectWasInspected:object
{
	if([object respondsTo:@selector(label)])
		sprintf(buf,"Object inspected has label %s.",[object label]);
	else
		sprintf(buf,"Object inspected has no label.");	
	[requestorMsgField setStringValue:buf];

	return self;
}

/* Message to requestor from inspector (UHInspector subclass) when an object list is inspected. */
- objectListWasInspected:objectList
{
	if([objectList count]==1){
		id object=[objectList objectAt:0];
		if([object respondsTo:@selector(label)])
			sprintf(buf,"Object inspected has label %s.",[object label]);
		else
			sprintf(buf,"Object inspected has no label.");	
		[requestorMsgField setStringValue:buf];
	}
	else
		[requestorMsgField setStringValue:"Multiple objects inspected."];

	return self;
}

/* Inspector panel must be explicityl ordered front. */
- showInspector:sender
{
	[inspectorManager showInspector:self];
    return self;
}


@end

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.