Permalink
Browse files

Basics finally working

  • Loading branch information...
1 parent 85f2620 commit 59ae329907cfcf77e456131ff91a734523a025ea @hlship committed Sep 9, 2009
@@ -36,49 +36,45 @@ var
{
self = [super init];
- if (self)
- {
- _panel = [[CPPanel alloc] initWithContentRect:CGRectMake(20, 30, 184, 184)
- styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask];
-
- _contentView = [_panel contentView];
+ _panel = [[CPPanel alloc] initWithContentRect:CGRectMake(20, 30, 184, 184)
+ styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask];
+
+ _contentView = [_panel contentView];
- [_panel setTitle:"Calculator"];
-
+ [_panel setTitle:"Calculator"];
- _display = [CPTextField labelWithTitle:""];
- [_display setAlignment:CPRightTextAlignment];
- [_display setFrame:CGRectMake(1, 5, 183, 30)]
- [_display setBezeled:YES];
+ _display = [CPTextField labelWithTitle:""];
+ [_display setAlignment:CPRightTextAlignment];
+ [_display setFrame:CGRectMake(1, 5, 183, 30)]
+ [_display setBezeled:YES];
- [self add:_display];
-
- [self makeButton:"C" atX:0 y:0 action:@selector(clear:)];
+ [self add:_display];
- [self makeButton:"/" atX:3 y:0 action:@selector(div:)];
- [self makeButton:"*" atX:3 y:1 action:@selector(mult:)];
- [self makeButton:"-" atX:3 y:2 action:@selector(minus:)];
- [self makeButton:"+" atX:3 y:3 action:@selector(plus:)];
+ [self makeButton:"C" atX:0 y:0 action:@selector(clear:)];
-
- [self makeDigit:7 atX:0 y:1];
- [self makeDigit:8 atX:1 y:1];
- [self makeDigit:9 atX:2 y:1];
+ [self makeButton:"/" atX:3 y:0 action:@selector(div:)];
+ [self makeButton:"*" atX:3 y:1 action:@selector(mult:)];
+ [self makeButton:"-" atX:3 y:2 action:@selector(minus:)];
+ [self makeButton:"+" atX:3 y:3 action:@selector(plus:)];
- [self makeDigit:4 atX:0 y:2];
- [self makeDigit:5 atX:1 y:2];
- [self makeDigit:6 atX:2 y:2];
- [self makeDigit:1 atX:0 y:3];
- [self makeDigit:2 atX:1 y:3];
- [self makeDigit:3 atX:2 y:3];
+ [self makeDigit:7 atX:0 y:1];
+ [self makeDigit:8 atX:1 y:1];
+ [self makeDigit:9 atX:2 y:1];
- [[self makeDigit:0 atX:0 y:4] setFrameSize:CPSizeMake(85, 24)];
- _dot = [self makeButton:"." atX:2 y:4 action:@selector(dot:)];
- [[self makeButton:"=" atX:3 y:4 action:@selector(compute:)] setDefaultButton:YES];
+ [self makeDigit:4 atX:0 y:2];
+ [self makeDigit:5 atX:1 y:2];
+ [self makeDigit:6 atX:2 y:2];
- [self reset];
- }
+ [self makeDigit:1 atX:0 y:3];
+ [self makeDigit:2 atX:1 y:3];
+ [self makeDigit:3 atX:2 y:3];
+
+ [[self makeDigit:0 atX:0 y:4] setFrameSize:CPSizeMake(85, 24)];
+ _dot = [self makeButton:"." atX:2 y:4 action:@selector(dot:)];
+ [[self makeButton:"=" atX:3 y:4 action:@selector(compute:)] setDefaultButton:YES];
+
+ [self reset];
return self;
}
@@ -0,0 +1,36 @@
+@import <AppKit/CPView.j>
+@import <AppKit/CPTextField.j>
+
+@implementation TwitView : CPView
+{
+ CPTextField _label;
+}
+
+- (void) setRepresentedObject:(JSONObject)obj
+{
+ CPLog.debug("Adding status: " + obj.text);
+
+ if (!_label)
+ {
+ _label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
+ [_label setFont:[CPFont systemFontOfSize:12]];
+ [_label setTextColor:[CPColor whiteColor]];
+ [self addSubview:_label];
+ }
+
+ [_label setStringValue:obj.text];
+
+ [_label setFrameSize:CGSizeMake(600, 60)];
+ [_label setFrameOrigin:CGPointMake(10, 0)];
+
+ [_label setLineBreakMode:CPLineBreakByWordWrapping];
+}
+
+- (void)setSelected:(BOOL)isSelected
+{
+ var color = isSelected ? [CPColor blueColor] : nil;
+
+ [self setBackgroundColor:color];
+}
+
+@end
@@ -3,51 +3,69 @@
@import <AppKit/CPTextField.j>
@import <AppKit/CPColor.j>
@import <AppKit/CPScrollView.j>
+@import "TwitView.j"
@implementation TwitterController : CPObject
{
CPPanel _panel;
CPTextField _field;
- CPView _scrollViewContent;
+ CPCollectionView _timelineView;
}
- (id)init
{
self = [super init];
- if (self)
- {
- _panel = [[CPPanel alloc] initWithContentRect:CGRectMake(20, 30, 245, 184)
- styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask | CPResizableWindowMask];
-
- [_panel setTitle:@"Twitter"];
- [_panel setMinSize:CGSizeMake(245, 184)];
-
- var label = [CPTextField labelWithTitle:"User:"];
- [label setFrame:CGRectMake(3, 7, 50, 24)];
- [label setTextColor:[CPColor whiteColor]];
-
- _field = [CPTextField textFieldWithStringValue:"" placeholder:"Twitter User" width:200];
+ _panel = [[CPPanel alloc] initWithContentRect:CGRectMake(20, 30, 245, 184)
+ styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask | CPResizableWindowMask];
+
+ [_panel setTitle:@"Twitter"];
+ [_panel setMinSize:CGSizeMake(245, 184)];
+
+ var content = [_panel contentView];
- [_field setFrame:CGRectMake(40, 0, 200, 28)];
- [_field setTarget:self];
- [_field setAction:@selector(startSearch:)];
- [_field setAutoresizingMask:CPViewWidthSizable];
-
- var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 32, 245, 160)];
-
- [scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
-
- [scrollView setAutohidesScrollers:YES];
- [scrollView setBackgroundColor:[CPColor whiteColor]];
-
- var content = [_panel contentView];
-
- [content addSubview:label];
- [content addSubview:_field];
- [content addSubview:scrollView];
- }
+ var label = [CPTextField labelWithTitle:"User:"];
+ [label setFrame:CGRectMake(3, 7, 50, 24)];
+ [label setTextColor:[CPColor whiteColor]];
+
+ _field = [CPTextField textFieldWithStringValue:"" placeholder:"Twitter User" width:200];
+
+ [_field setFrame:CGRectMake(40, 0, 200, 28)];
+ [_field setTarget:self];
+ [_field setAction:@selector(startSearch:)];
+ [_field setAutoresizingMask:CPViewWidthSizable];
+
+ var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(3, 40,
+ CGRectGetWidth([content bounds]) - 10,
+ CGRectGetHeight([content bounds]) - 50)];
+ [scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
+ [scrollView setAutohidesScrollers:YES];
+ [scrollView setBackgroundColor:[CPColor greenColor]]; // TEMP
+
+ var scrollViewBounds = [[scrollView contentView] bounds];
+
+ var itemPrototype = [[CPCollectionViewItem alloc] init];
+ [itemPrototype setView:[[TwitView alloc] initWithFrame:CGRectMakeZero()]];
+
+ _timelineView = [[CPCollectionView alloc] initWithFrame:CGRectMake(0, 0,
+ CGRectGetWidth(scrollViewBounds), 60)];
+ [_timelineView setItemPrototype:itemPrototype];
+ [_timelineView setDelegate:self];
+ [_timelineView setMaxNumberOfColumns:1];
+
+ [_timelineView setBackgroundColor:[CPColor darkGrayColor]]; // TEMP
+
+ [_timelineView setMinItemSize:CGSizeMake(100, 60)];
+ [_timelineView setMaxItemSize:CGSizeMake(1000, 60)];
+ [_timelineView setAutoresizingMask:CPViewWidthSizable];
+
+ [scrollView setDocumentView:_timelineView];
+
+ [content addSubview:label];
+ [content addSubview:_field];
+ [content addSubview:scrollView];
+
return self;
}
@@ -59,7 +77,26 @@
- (void)startSearch:(id)sender
{
+ // Simulate the call to twitter.com, using a cached copy of the response.
+ // Because of single-source policy, we'll need to implement a servlet at /twitter
+ // than can get the content from the real site and pass it to the browser.
+ var url = "twitter/statuses/user_timeline/" + [_field stringValue] + ".json";
+
+ var request = [CPURLRequest requestWithURL:url];
+ [CPURLConnection connectionWithRequest:request delegate:self];
+}
+- (void)connection:(CPURLConnection)connection didReceiveData:(CPString)data
+{
+ var timeline = JSON.parse(data);
+
+ [_timelineView setContent:timeline];
+}
+
+
+- (void)connection:(CPURLConnection)connection didFailWithError:(CPString)error
+{
+ CPLog.error(error);
}
@end
@@ -14,5 +14,7 @@
function main(args, namedArgs)
{
- CPApplicationMain(args, namedArgs);
+ CPLogRegister(CPLogConsole);
+
+ CPApplicationMain(args, namedArgs);
}

Large diffs are not rendered by default.

Oops, something went wrong.

0 comments on commit 59ae329

Please sign in to comment.