Skip to content

Instantly share code, notes, and snippets.

@NorthIsUp
Created March 18, 2010 05:12
Show Gist options
  • Save NorthIsUp/336067 to your computer and use it in GitHub Desktop.
Save NorthIsUp/336067 to your computer and use it in GitHub Desktop.
/*
* AppController.j
* NewApplication
*
* Created by You on July 5, 2009.
* Copyright 2009, Your Company All rights reserved.
*/
@import <Foundation/CPObject.j>
/*This is the "window" class, this should be made awesome*/
@implementation CISimpleWindowView : CPView
{
CPScrollView scrollView;
CPTableView tableView;
}
-(void)drawRect:(CGRect)r
{
// This draws a nice rounded view to put stuff inside
[[CPColor whiteColor] setFill]
var path = [CPBezierPath bezierPath];
[path appendBezierPathWithRoundedRect:CGRectMake(5, 0, CGRectGetWidth([self bounds]) - 10.0, CGRectGetHeight([self bounds])) xRadius:10 yRadius:10];
[path fill];
}
@end
@implementation CICellView : CPView
{
CPTextField label1;
CPTextField label2;
CPImageView image;
}
-(id)init
{
label1 = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
// [label1 setCenter:[contentView center]];
// [label1 setAlignment:CPCenterTextAlignment];
label2 = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
// [label2 setCenter:[contentView center]];
// [label2 setAlignment:CPCenterTextAlignment];
[self addSubview:label1];
}
-(void)setObjectValue:(id)aVal
{
// [label setStringValue:aVal];
}
- (id)initWithCoder:(CPCoder)aCoder
{
self = [super initWithCoder:aCoder];
if (self)
{
label1 = [aCoder decodeObjectWithKey:@"textField1"];
label2 = [aCoder decodeObjectWithKey:@"textField2"];
image = [aCoder decodeObjectWithKey:@"image"];
}
return self;
}
- (void)encodeWithCoder:(CPCover)aCoder
{
[aCoder encodeObject:label1 forKey:@"textField1"];
[aCoder encodeObject:label2 forKey:@"textField2"];
[aCoder encodeObject:image forKey:@"image"]
}
@end
@implementation AppController : CPObject
{
CPTextField label;
CPMutableArray rosterList;
}
- (void)awakeFromCib
{
// This is called when the cib is done loading.
// You can implement this method on any object instantiated from a Cib.
// It's a useful hook for setting up current UI values, and other things.
}
- (id)init
{
[super init];
// var baseUrl = "http://example.org/"
// var url = baseUrl;
// var request = [CPURLRequest requestWithURL: url];
// var data = [CPURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
// var str = [data string];
// var dict = [[CPDictinary alloc] initWithObjectsAndKeys:@"hi", @"textField1", @"helo", @"textField2", nil, @"image"]
// var d = [CPDictionary dictionaryWithJSObject:{textField1:"hi", textField2:"helo",image:"nil"}]
rosterList = [{textField1:"hi", textField2:"helo", image:nil}];
return self;
}
-(CPPanel)initInfoWindow
{
var width = 300
var height = 550
var infoWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(20,80,width+20,height+80) styleMask:CPHUDBackgroundWindowMask|CPResizableWindowMask];
[infoWindow setFloatingPanel:YES];
var _infoContent = [infoWindow contentView];
var _iconImage = [[CPImage alloc] initWithContentsOfFile:"Resources/icons/Contact_128x128.png" size:CPSizeMake(59, 60)];
var _iconView = [[CPImageView alloc] initWithFrame:CGRectMake(125,0,59,60)];
[_iconView setImage:_iconImage];
[_infoContent addSubview:_iconView];
var _infoView = [[CISimpleWindowView alloc] initWithFrame:CGRectMake(0,65,width+20,height-5)];
[_infoView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(10,5,width,height-15)];
[scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
tableView = [[CPTableView alloc] initWithFrame:[scrollView bounds]];
[tableView setUsesAlternatingRowBackgroundColors:YES];
[tableView setRowHeight:48]
var column = [[CPTableColumn alloc] init];
[column setWidth:width-15];
var label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
var tableCell = [[CICellView alloc] initWithFrame:CGRectMakeZero()];
// [tableCell setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
[column setDataView:tableCell];
[tableView addTableColumn:column];
[scrollView setDocumentView:tableView];
[tableView setDataSource:self];
[tableView setDelegate:self];
[_infoView addSubview:scrollView];
[_infoContent addSubview:_infoView];
return infoWindow;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
[theWindow setBackgroundColor:[CPColor grayColor]];
label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
// [label setStringValue:@"Hello World!"];
// [label setFont:[CPFont boldSystemFontOfSize:24.0]];
//
// [label sizeToFit];
//
// [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
// [label setCenter:[contentView center]];
// [label setAlignment:CPCenterTextAlignment];
[contentView addSubview:label];
[theWindow orderFront:self];
var infoWindow = [self initInfoWindow];
[infoWindow orderFront:self];
// Uncomment the following line to turn on the standard menu bar.
[CPMenu setMenuBarVisible:YES];
}
- (int)numberOfRowsInTableView:(CPTableView)tableView
{
return [rosterList count];
}
- (id)tableView:(CPTableView)tableView objectValueForTableColumn:(CPTableColumn)tableColumn row:(int)row
{
return [rosterList objectAtIndex:row];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment