home *** CD-ROM | disk | FTP | other *** search
- // ThingInspector.m
- // By Kevin Brain (ksbrain@zeus.UWaterloo.ca)
-
- // Acts as an intermediary between the Thing1 and Thing2
- // (Tank) attribute inspector view controls (layed out in
- // the file ThingInspector.nib) and the objects they inspect.
-
- #import "ThingInspector.h"
- #import "InspectMeApp.h"
- #import "Thing1.h"
- #import "Tank.h"
- #import "InspectorManager.h"
- #import <appkit/Control.h> // displaying attributes
-
- @implementation ThingInspector
-
- static id theThingInspector = nil; // just one per class
-
- // only a single instance of this class is permitted
- // use [ThingInspector new] to return the single instance
-
- + new
- {
- if (!theThingInspector) {
- theThingInspector = self = [super new];
- [NXApp loadNibSection:"ThingInspector.nib" owner:self];
- }
- else
- self = theThingInspector;
- return self;
- }
-
- - setupInspectors:(id)mainInspector
- {
- inspectorManager = [NXApp inspectorManager];
- thing1InspectorNum = [inspectorManager
- addInspector:(id)thing1InspectorBox
- title:(const char *)"Thing 1 Inspector"
- atLocation:LOWERLEFTX :LOWERLEFTY
- cached:YES cacheWindow:[thing1InspectorBox window]];
-
- tankInspectorNum = [inspectorManager
- addInspector:(id)tankInspectorBox
- title:(const char *)"Thing 2 Inspector"
- atLocation:LOWERLEFTX :LOWERLEFTY
- cached:YES cacheWindow:[tankInspectorBox window]];
-
- return self;
- }
-
- - setCurrentParameterReceiver:(id)newCurrent
- {
- currentParameterReceiver = newCurrent;
- return self;
- }
-
- - (unsigned int)thing1InspectorNum
- {
- return thing1InspectorNum;
- }
-
- - (unsigned int)tankInspectorNum
- {
- return tankInspectorNum;
- }
-
- - reflectThing1Attributes:(id)theObject
- {
- if(!theObject) return self;
-
- [outNumber setIntValue:[theObject number]];
- [outSize setIntValue:[theObject size]];
-
- switch([theObject shape]) {
- case SHAPE_CIRCLES:
- [outShape setTitle:"Circles"];
- break;
- case SHAPE_SQUARES:
- [outShape setTitle:"Squares"];
- break;
- }
- return self;
- }
-
- - reflectTankAttributes:(id)theObject
- {
- char buffer[15];
- if(!theObject) return self;
-
- sprintf(buffer,"%8.1f",[theObject capacity]);
- [outCapacity setStringValue:buffer];
- sprintf(buffer,"%8.1f",[theObject holding]);
- [outHolding setStringValue:buffer];
-
- return self;
- }
-
- /* Setting ingredient attribute values */
- /* Targets of inspector controls */
- /* NOTE: No range checking has been added to these methods yet. */
-
- - inspSetNumber:sender
- {
- [currentParameterReceiver setNumber:[sender intValue]];
- return self;
- }
-
- - inspSetSize:sender
- {
- [currentParameterReceiver setSize:[sender intValue]];
- return self;
- }
-
- - inspSetShape:sender
- {
- [currentParameterReceiver setShape:[[sender selectedCell] tag]];
- return self;
- }
-
- - inspSetCapacity:sender
- {
- [currentParameterReceiver setCapacity:[sender floatValue]];
- return self;
- }
-
- - inspSetHolding:sender
- {
- [currentParameterReceiver setHolding:[sender floatValue]];
- return self;
- }
-
-
- @end
-