Created
September 13, 2010 00:15
-
-
Save joehoyle/576640 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* AppController.j | |
* CollectionDemo | |
* | |
* Created by You on September 13, 2010. | |
* Copyright 2010, Your Company All rights reserved. | |
*/ | |
@import <Foundation/CPObject.j> | |
@implementation AppController : CPObject | |
{ | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
contentView = [theWindow contentView]; | |
var data = [1,2,3,4,5,6]; | |
var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(50, 50, 600, 50)]; | |
var collectionView = [[CPCollectionView alloc] initWithFrame:[scrollView bounds]]; | |
var collectionViewItem = [[CPCollectionViewItem alloc] init]; | |
var itemPrototypeView = [[myItem alloc] initWithFrame:CGRectMakeZero()]; | |
[itemPrototypeView setBackgroundColor:[CPColor greenColor]]; | |
[collectionViewItem setView:itemPrototypeView]; | |
[collectionView setMinItemSize:CGSizeMake(600, 100)]; | |
[collectionView setMaxItemSize:CGSizeMake(600, 150)]; | |
[collectionView setMaxNumberOfColumns:1]; | |
[collectionView setItemPrototype:collectionViewItem]; | |
[collectionView setBackgroundColor:[CPColor redColor]]; | |
[collectionView setContent:data]; | |
[theWindow orderFront:self]; | |
[contentView addSubview:collectionView]; | |
} | |
@end | |
// An item on the CPCollectionView | |
@implementation myItem : CPView | |
{ | |
CPTableView sitesTable; | |
CPScrollView sitesScrollView; | |
CPArray sites; | |
} | |
- (id)initWithFrame:(CGRect)aFrame | |
{ | |
[super initWithFrame:aFrame]; | |
sites = ["Site a", "Site b", "Site z"]; | |
//ceate the tableview | |
sitesTable = [[CPTableView alloc] initWithFrame:CGRectMake(0, 0, 600, 100 )]; | |
[sitesTable setDataSource:self]; | |
[sitesTable setDelegate:self]; | |
[sitesTable setHeaderView:nil]; | |
[sitesTable setCornerView:nil]; | |
[sitesTable registerForDraggedTypes:[CPArray arrayWithObject:@"CPTableViewTestDragType"]]; | |
[sitesTable setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleNone]; | |
[sitesTable setIntercellSpacing:CGSizeMake(0,0)]; | |
// add the column | |
var column = [[CPTableColumn alloc] initWithIdentifier:@"column1"]; | |
[column setDataView:[[MyTableColumnDataView alloc] initWithFrame:CGRectMakeZero()]]; | |
[sitesTable addTableColumn:column]; | |
//create the scroll view | |
sitesScrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 15, 600, 100 )]; | |
[sitesScrollView setDocumentView:sitesTable]; | |
[sitesScrollView setHasHorizontalScroller:NO]; | |
[sitesScrollView setHasVerticalScroller:NO]; | |
[self addSubview:sitesScrollView]; | |
return self; | |
} | |
// CPTableView datasource methods | |
- (int)numberOfRowsInTableView:(CPTableView)tableView | |
{ | |
console.log('numberOfRowsInTableView: ' + [sites count] ); | |
return [sites count]; | |
} | |
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row | |
{ | |
console.log( 'objectValueForTableColumn: ' + [sites objectAtIndex:row] ); | |
return [sites objectAtIndex:row]; | |
} | |
//CPCollectionViewItem | |
- (void)setRepresentedObject:(id)aValue | |
{ | |
console.log( 'setRepresentedObject: ' + aValue); | |
[sitesTable reloadData]; | |
} | |
//CPCoding | |
- (void)encodeWithCoder:(CPCoder)coder { | |
[super encodeWithCoder:coder]; | |
[coder encodeObject:sitesTable forKey:@"sitesTable"]; | |
[coder encodeObject:sitesScrollView forKey:@"sitesScrollView"]; | |
[coder encodeObject:sites forKey:@"sites"]; | |
} | |
- (void)initWithCoder:(CPCoder)coder { | |
[super initWithCoder:coder]; | |
sites = [coder decodeObjectForKey:@"sites"]; | |
sitesScrollView = [coder decodeObjectForKey:@"sitesScrollView"]; | |
sitesTable = [coder decodeObjectForKey:@"sitesTable"]; | |
return self; | |
} | |
@end | |
@implementation MyTableColumnDataView : CPTextField | |
{ | |
} | |
- (void)setObjectValue:(id)aValue | |
{ | |
[super setObjectValue:aValue]; | |
// This is always set to "undefined" | |
console.log( 'setObjectValue: ' + aValue ); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment