/* BBAtomLibraryBrowserController.h				 
 *
 * This subclass of MiscSwapContentsCtrl is in charge of the organic section
 * of the atomlibrary
 *
 * For more interface-info see the header file. In depth information
 * can be found here in the source-code.
 *
 * Written by: 		Thomas Engel
 * Created:    		12.01.1994 (Copyleft)
 * Last modified: 	15.05.1994
 */

#import "BBAtomLibraryBrowserController.h"
#import "BBAtomLibraryManager.h"
#import "../BBBasicAtom.h"
#import "../BBAppManager.h"

@implementation BBAtomLibraryBrowserController

-revert:sender
{
	// Ok. we will swap in. So Lets set up the browser & first column.
	// we have a lot to do with the atomList so lets cache it.

	atomList = [[[NXApp delegate] atomLibrary] atomList];

	[browser setTarget:self];
	[browser setAction:@selector(selectNewAtom:)];
	[browser setDoubleAction:@selector(selectNewAtom:)];
	[browser loadColumnZero];

	return [super revert:self];
}

- selectNewAtom:sender
{
	// Lets find the selected Cell and take its tag...very simple.

	int	theTag;

	theTag = [[browser selectedCell] tag];
	[[[NXApp delegate] atomLibrary] selectBasicAtomWithProtons:(short)theTag];
	return self;
}

- (int)browser:sender fillMatrix:matrix inColumn:(int)column
{
	// We just fill the matrix with the needed number of cells.
	// According the atoms inside the list.
	
	int	i, n;
	
	n = [atomList count];
	for( i=0; i<n; i++ ) [matrix addRow];

	return n;
}

- browser:sender loadCell:cell atRow:(int)row inColumn:(int)column
{
	// Just set the atoms name as the String value.
	
	id		anAtom;

	anAtom = [atomList objectAt:row];
	[cell setStringValue:[anAtom name]];
	[cell setTag:[anAtom protons]];
	[cell setLoaded:YES];
	[cell setLeaf:YES];

	return self;
}

@end

/*
 * History: 14.05.94 Switched to new name: BB...
 *
 *			12.01.94 First implementation.
 *
 *
 * Bugs: - Hmm...yes..sure. Well the name should be: C...Kohlenstoff not
 *		   just Kohlenstoff
 *
 *		 - To implement the switching we will maintain our own list which will
 *		   be sorted the way we need it.
 */