ftp.nice.ch/Attic/openStep/developer/resources/MiscKit.2.0.5.s.gnutar.gz#/MiscKit2/Frameworks/MiscAppKit/MiscTreeDiagram.subproj/MiscNodeStyle.m

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

/*	MiscNodeStyle.m

	Copyright 1996 Uwe Hoffmann.

	This notice may not be removed from this source code.
	The use and distribution of this software is governed by the
	terms of the MiscKit license agreement.  Refer to the license
	document included with the MiscKit distribution for the terms.

	Version 2 (August 1996)
*/

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#import "MiscNodeStyle.h"

@implementation MiscNodeStyle
/*"Instances of this class encapsulate style attributes for nodes in the MiscTreeDiagram framework.
Attributes found here can be different for every node in the tree. Attributes common to all nodes
in a tree are held in a MiscTreeStyle instance. It is recommended to set these attributes indirectly
through a MiscTreeDiagram instance which controls the tree.

Most attributes are self-explanatory. The exception is probably the attribute %{automatic resize},
which controls the behaviour of a node when the label of the node changes. If automatic resize is
turned on the node will resize to accomodate the new label in its entirety.

The style of a node is defined by attributes saved in four different classes: MiscLayoutTree,
MiscDiagramTree, MiscNodeStyle and MiscTreeStyle. Every MiscDiagramTree instance holds
an instance of MiscNodeStyle and the MiscTreeDiagram instance controlling the tree holds
an instance of MiscTreeStyle."*/

- init
{
	[super init];
	fillColor = [[NSColor whiteColor] retain];
	outlineColor = [[NSColor blackColor] retain];
	linewidth = 0.15;
	fill = YES;
	outline = YES;
	automaticResize = NO;
        textPlacement = MiscMiddleTextPlacement;
        childEnding = MiscNoEnding;
        parentEnding = MiscNoEnding;
	return self;
}

- (void)dealloc
{
        [fillColor release];
        [outlineColor release];
        return [super dealloc];
}

- (BOOL)isEqual:(id)anObject
{
    	MiscNodeStyle *co;
    
    	if(!anObject)
            	return NO;
    	if(anObject == self)
            	return YES;
        if(![anObject isKindOfClass:[self class]])
            	return NO;
        co = (MiscNodeStyle *)anObject;
        if([fillColor isEqual:co->fillColor] &&
           [outlineColor isEqual:co->outlineColor] &&
           childEnding == co->childEnding &&
           parentEnding == co->parentEnding &&
           textPlacement == co->textPlacement &&
           automaticResize == co->automaticResize &&
           outline == co->outline &&
           fill == co->fill &&
           linewidth == co->linewidth)
            	return YES;
        else
            	return NO;
}

- (NSColor *)fillColor
/*"Returns the fill color attribute of the receiver."*/
{
	return fillColor;
}

- (void)setFillColor:(NSColor *)aColor
/*"Sets the fill color attribute of the receiver."*/
{
    	if(!aColor || [fillColor isEqual:aColor])
            	return;
    	[fillColor release];
	fillColor = [aColor copyWithZone:[self zone]];
}

- (NSColor *)outlineColor
/*"Returns the outline color attribute of the receiver."*/
{
	return outlineColor;
}

- (void)setOutlineColor:(NSColor *)aColor
/*"Sets the outline color attribute of the receiver."*/
{
    	if(!aColor || [outlineColor isEqual:aColor])
            	return;
    	[outlineColor release];
     	outlineColor = [aColor copyWithZone:[self zone]];
}

- (BOOL)fill
/*"Returns the fill attribute of the receiver."*/
{
	return fill;
}

- (void)setFill:(BOOL)aBOOL
/*"Sets the fill attribute of the receiver."*/
{
	fill = aBOOL;
}

- (BOOL)outline
/*"Returns the outline attribute of the receiver."*/
{
	return outline;
}

- (void)setOutline:(BOOL)aBOOL
/*"Sets the outline attribute of the receiver."*/
{
	outline = aBOOL;
}

- (float)linewidth
/*"Returns the linewidth attribute of the receiver."*/
{
	return linewidth;
}

- (void)setLinewidth:(float)aLinewidth
/*"Sets the linewidth attribute of the receiver."*/
{
	linewidth = aLinewidth;
}

- (BOOL)automaticResize
/*"Returns the automatic resize attribute of the receiver. This attribute
controls the behaviour of a node when the label changes. When the attribute
is turned on the node resizes to fit the label."*/
{
	return automaticResize;
}

- (void)setAutomaticResize:(BOOL)aBOOL
/*"Sets the automatic resize attribute of the receiver."*/
{
	automaticResize = aBOOL;
}

- (MiscTextPlacement)textPlacement
/*"Returns the text placement attribute of the receiver."*/
{
    	return textPlacement;
}

- (void)setTextPlacement:(MiscTextPlacement)aTextPlacement
/*"Sets the text placement attribute of the receiver."*/
{
    	textPlacement = aTextPlacement;
}

- (MiscEndingType)childEnding
/*"Returns the child ending attribute of the receiver. This attribute sets the line
ending for lines entering a node with the node as a child. Lines in a tree connect only nodes
in parent-child relationship."*/
{
    	return childEnding;
}

- (void)setChildEnding:(MiscEndingType)anEnding
/*"Sets the child ending attribute of the receiver."*/
{
    	childEnding = anEnding;
}

- (MiscEndingType)parentEnding
/*"Returns the parent ending attribute of the receiver. This attribute sets the line
ending for lines entering a node with the node as a parent. Lines in a tree connect only nodes
in parent-child relationship."*/
{
    	return parentEnding;
}

- (void)setParentEnding:(MiscEndingType)anEnding
/*"Sets the parent ending attribute of the receiver."*/
{
    	parentEnding = anEnding;
}

- (void)encodeWithCoder:(NSCoder *)coder
{
	[coder encodeObject:fillColor];
        [coder encodeObject:outlineColor];
	[coder encodeValuesOfObjCTypes:"cccf", &automaticResize,&fill,&outline,&linewidth];
	[coder encodeValueOfObjCType:@encode(MiscTextPlacement) at:&textPlacement];
	[coder encodeValueOfObjCType:@encode(MiscEndingType) at:&childEnding];
	[coder encodeValueOfObjCType:@encode(MiscEndingType) at:&parentEnding];
}

- initWithCoder:(NSCoder *)coder
{
	fillColor = [[coder decodeObject] copyWithZone:[self zone]];
     	outlineColor = [[coder decodeObject] copyWithZone:[self zone]];
	[coder decodeValuesOfObjCTypes:"cccf", &automaticResize,&fill,&outline,&linewidth];
	[coder decodeValueOfObjCType:@encode(MiscTextPlacement) at:&textPlacement];
	[coder decodeValueOfObjCType:@encode(MiscEndingType) at:&childEnding];
	[coder decodeValueOfObjCType:@encode(MiscEndingType) at:&parentEnding];
	return self;
}

- copyWithZone:(NSZone *)zone
{
   	MiscNodeStyle *theCopy;

   	theCopy = (MiscNodeStyle *)NSCopyObject(self, 0, zone);
        theCopy->fillColor = [fillColor copyWithZone:zone];
        theCopy->outlineColor = [outlineColor copyWithZone:zone];
	return theCopy;
}

- copy
{
	return [self copyWithZone:NSDefaultMallocZone()];
}

@end

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