Skip to content

Instantly share code, notes, and snippets.

@Alos
Created September 25, 2008 05:21
Show Gist options
  • Save Alos/12766 to your computer and use it in GitHub Desktop.
Save Alos/12766 to your computer and use it in GitHub Desktop.
import <Foundation/CPObject.j>
@implementation SFTable : CPView
{
CPCollectionView collectionView;
CPPanel bgPanel
CPArray model;
CPArray title;
}
-(void) initWithTitles:(CPArray) someTitles model:(CPArray)aModel frame:(CGRect)bounds{
bgPanel = [[CPPanel alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
self = [super initWithFrame:bounds];
[self drawTitles:someTitles];
model=aModel;
//para nuestro grid
collectionView = [[CPCollectionView alloc] initWithFrame: CGRectMake(0, 30, CGRectGetWidth(bounds), CGRectGetHeight(bounds)/ 4.0 )];
//los scrolls por si son muchos
var scrollView = [[CPScrollView alloc] initWithFrame: CGRectMake(0, 30, CGRectGetWidth(bounds), CGRectGetHeight(bounds)/ 4.0 )];
[scrollView setAutohidesScrollers: YES];
[scrollView setDocumentView: collectionView];
[[scrollView contentView] setBackgroundColor: [CPColor colorWithCalibratedRed:213.0/255.0 green:221.0/255.0 blue:230.0/255.0 alpha:1.0]];
[scrollView setHasHorizontalScroller:NO]
[scrollView setAutoresizingMask: CPViewWidthSizable];
//los items q representan los renglones
var listItem = [[CPCollectionViewItem alloc] init];
var celdas = [[SFCell alloc] initWithFrame:CGRectMakeZero()];
[listItem setView: celdas];
[collectionView setItemPrototype: listItem];
[collectionView setMaxNumberOfColumns:1];
[collectionView setMinItemSize:CPSizeMake(CGRectGetWidth(bounds), 30)];
[collectionView setMaxItemSize:CPSizeMake(CGRectGetWidth(bounds), 30)];
[collectionView setContent: model];
var container = [bgPanel contentView];
[container addSubview: scrollView];
return self;
}
-(void)drawTitles:(CPArray)titles{
var container = [bgPanel contentView];
for(var i=0; i<[titles count];i++){
[container addSubview:[titles objectAtIndex:i]];
}
}
-(void)setModel:(CPArray)aModel{
model=aModel;
[collectionView reloadContent];
}
-(void)addItem():(CPObject)anItem{
[model addObject:anItem];
[collectionView setModel: model];
[collectionView reloadContent];
}
@end
@implementation SFCell : CPView
{
CPTextField titleView;
CPTextField authorView;
CPView highlightView;
}
- (void)setRepresentedObject:(JSObject)anObject
{
if(!titleView)
{
titleView = [[CPTextField alloc] initWithFrame:CGRectInset( [self bounds], 4, 4)];
[titleView setFont: [CPFont systemFontOfSize: 16.0]];
[titleView setTextColor: [CPColor blackColor]];
[self addSubview: titleView];
}
[titleView setStringValue: [anObject songTitle]];
[titleView sizeToFit];
[titleView setFrameOrigin: CGPointMake(10,0.0)];
if(!authorView)
{
authorView = [[CPTextField alloc] initWithFrame:CGRectInset([self bounds], 4, 4)];
[authorView setFont: [CPFont systemFontOfSize: 16.0]];
[authorView setTextColor: [CPColor blackColor]];
[self addSubview: authorView];
}
[authorView setStringValue: [anObject artist]];
[authorView sizeToFit];
[authorView setFrameOrigin: CGPointMake(400,0.0)];
/*if(colored){
[titleView setBackgroundColor:[CPColor whiteColor]];
[authorView setBackgroundColor:[CPColor whiteColor]];
colored=NO;
}else{
colored=YES;
}*/
}
- (void)setSelected:(BOOL)flag
{
if(!highlightView)
{
highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
[highlightView setBackgroundColor: [CPColor lightGrayColor]];
}
if(flag)
{
[self addSubview:highlightView positioned:CPWindowBelow relativeTo: titleView];
[titleView setTextColor: [CPColor whiteColor]];
[authorView setTextColor: [CPColor whiteColor]];
}
else
{
[highlightView removeFromSuperview];
[titleView setTextColor: [CPColor blackColor]];
[authorView setTextColor: [CPColor blackColor]];
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment