ftp.nice.ch/pub/next/developer/resources/classes/SwapView.2.0.N.b.tar.gz#/SwapView_2.0r/ExampleCode/InspectorController.m

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

/*
 * Author: Greg Burd, Mr. Average Developer
 *    (I would like to be a member of the NeXT Developer Support Team.)
 *
 * You may freely copy, distribute and reuse the code in this example.  
 * I disclaim any warranty of any kind, expressed or implied, as to 
 * its fitness for any particular use.
 */

#import <appkit/Application.h>
#import <appkit/PopUpList.h>
#import <appkit/Matrix.h>
#import <strings.h>
#import "SwapView.h"

#import "InspectorController.h"

/*
 * local global to help speed up the swapping out of views by keeping track
 * of the titles
 */
static const char *theTitle;

@implementation InspectorController

- init
{	
	[super init];
	
    /* get our panel etc. */
	[NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO];
	
	/* set target action of the popUp */
    [[popUpCover target] setTarget:self];
	[[popUpCover target] setAction:@selector(popUpAction:)];
	
	/* set the swapView's delegate so we get the message (this could be done
	 * in IB, but I do it here for clarity). */
	[swapView setDelegate:self];
	
	/* set up the matrix so that it can receive the command-key events */
	//[[[popUpCover window] contentView] setNextResponder:[popUpCover target]];
	
	/* swap in the first inspector */
	theTitle = [popUpCover title];
	
	/* this is the default for SwapView, we can make it anything we want */
	[swapView setBackgroundGray:NX_LTGRAY];
	/* now swap in the first inspector */
	[swapView swapIt];
	
	return self;
}

/* this is to allow us to junp to any inspector given its key name */
- inspectName:(char *)str
{
	if (str) { theTitle = str; }
	[swapView swapIt];
	
	return self;
}

- showInspector
{
	/* I separate this so that you can show and hide the inspector at will */
  	[inspectorPanel makeKeyAndOrderFront:self];
	return self;
}

- popUpAction:sender
{
	/* set up a pointer to the selectedCell of the matrix */
	 theTitle = [[sender selectedCell] title];
	 /* and swap out the view */
	 [swapView swapIt];

	return self;
}

// delegate method of swapView

	/*
	 * This is the delegate call every time the swap view gets a - swapIt
	 * message.  What this should return is the id of a panel, which is
	 * off screen, and buffered, but not defered (SwapView needs its gstate).
	 * SwapView will take the contentView of the panel and swap it in while
	 * also removing the old view, if any, and placing it back into its old
	 * panel.
	 */

- whatPanel
{
	/*
	 * now jsut do a set of 'ifs' to find out what panel to give to the
	 * SwapView
	 */
	 
	if(theTitle) {
	
	/* make sure that the Button title matches the inspector name 
	 * this doesn't happen with a command key call
	 */
	if (strcmp(theTitle,[popUpCover title])) {
		[popUpCover setTitle:theTitle];
	}

	if (!strcmp(theTitle,"Info..."))
		return infoPanel;
	
	if (!strcmp(theTitle,"First Inspector"))
		return firstInspectorPanel;
	
	if (!strcmp(theTitle,"Second Inspector"))
		return secondInspectorPanel;
	
	if (!strcmp(theTitle,"Third Inspector"))
					return thirdInspectorPanel;
	
	if (!strcmp(theTitle,"Fourth Inspector"))
		return fourthInspectorPanel;
	}
	
	/* the button title has no related inspector, this should never happen. */
	return (id)NULL;
}

/* HINT::  those panels should all be nibs so they have controllers
			and the above code should load the nib section if it
			already isn't loaded.  It should load here because you only
			want to take up memory when it is demanded. */

- free
{
	return [super free];
}
@end

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