Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/boucher/Frothy
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pollak committed Sep 4, 2009
2 parents cc2092e + 4b97cdb commit 5e0d4cb
Showing 1 changed file with 94 additions and 80 deletions.
174 changes: 94 additions & 80 deletions src/main/webapp/AppController.j
Expand Up @@ -11,116 +11,130 @@


@implementation AppController : CPObject @implementation AppController : CPObject
{ {
CPTextField label; MessageView messageView;
CPTextField input; CPTextField input;
CPTextField clock; CPTextField clock;
+ AppController controllerInstance; // + AppController controllerInstance;
} }


- (void)applicationDidFinishLaunching:(CPNotification)aNotification - (void)applicationDidFinishLaunching:(CPNotification)aNotification
{ {
AppController.controllerInstance = self; AppController.controllerInstance = self;
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView]; var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],

contentView = [theWindow contentView],
label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; bounds = [contentView bounds];


[label setStringValue:@"Hello World!"]; [contentView setBackgroundColor:[CPColor colorWithWhite:0.85 alpha:1.0]];
[label setFont:[CPFont boldSystemFontOfSize:24.0]];
[label setAlignment:CPCenterTextAlignment]; var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - 40)];
[label sizeToFit];

[scrollView setHasHorizontalScroller:NO];
[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[label setCenter:[contentView center]]; messageView = [[MessageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds), 0)];


[contentView addSubview:label]; [messageView setAutoresizingMask:CPViewWidthSizable];

[scrollView setDocumentView:messageView];

[scrollView setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];

[contentView addSubview:scrollView];


[scrollView setBackgroundColor:[CPColor whiteColor]];
[messageView setBackgroundColor:[CPColor whiteColor]];


label = [CPTextField labelWithTitle:@"Hello World!"];

[label setAlignment:CPCenterTextAlignment];

[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[label setCenter:[contentView center]];


input = [[CPTextField alloc] initWithFrame: CGRectMake( input = [CPTextField roundedTextFieldWithStringValue:@"" placeholder:@"Send a message to the server..." width:CGRectGetWidth(bounds) - 145];
CGRectGetWidth([contentView bounds])/2.0 - 350,
CGRectGetMaxY([label frame]) + 10,
80, 24
)];

[input setStringValue:@"Send me to the server"];
[input setFont:[CPFont boldSystemFontOfSize:18.0]];


[input sizeToFit]; [input setFrameOrigin:CGPointMake(10, CGRectGetHeight(bounds) - CGRectGetHeight([input bounds]) - 4)];
[input setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];


[input setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; [input setTarget:self];
[input setEditable: YES]; [input setAction:@selector(send:)];
[input setBezeled: YES];
[contentView addSubview:input];


[contentView addSubview:input]; var button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - 125, CGRectGetHeight(bounds) - 31, 110, 24)];

var button = [[CPButton alloc] initWithFrame: CGRectMake(
CGRectGetWidth([contentView bounds])/2.0 - 40,
CGRectGetMaxY([label frame]) + 10,
80, 24
)];


[button setAutoresizingMask:CPViewMinXMargin | [button setAutoresizingMask:CPViewMinXMargin | CPViewMinYMargin];
CPViewMaxXMargin | [button setTitle:"Send"];
CPViewMinYMargin |
CPViewMaxYMargin];

[button setTitle:"Click Me"];


[button setTarget:self]; [button setTarget:self];
[button setAction:@selector(swap:)]; [button setAction:@selector(send:)];


[contentView addSubview:button]; [contentView addSubview:button];

clock = [[CPTextField alloc] initWithFrame:CGRectMake(
CGRectGetWidth([contentView bounds])/2.0 - 100,
CGRectGetMaxY([label frame]) + 40,
80, 24
)];


[clock setStringValue:@""]; [theWindow setDefaultButton:button];
[clock setFont:[CPFont boldSystemFontOfSize:24.0]];


[clock sizeToFit]; clock = [[CPTextField alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - 250 - [CPScroller scrollerWidth], 0, 250, 22)];


[clock setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; [clock setFont:[CPFont systemFontOfSize:14.0]];
[clock setAlignment:CPCenterTextAlignment]; [clock setBackgroundColor:[CPColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:0.3]];
[contentView addSubview:clock]; [clock setAutoresizingMask:CPViewMinXMargin];
[clock setAlignment:CPCenterTextAlignment];


[contentView addSubview:clock];

[theWindow orderFront:self];
}


[theWindow orderFront:self]; - (void)send:(id)sender

{
// Uncomment the following line to turn on the standard menu bar. performAjaxCall([input stringValue]);
// [CPMenu setMenuBarVisible:YES]; [input setStringValue:""];
} }


- (void)swap:(id)sender - (id)buttonCallback:(id)what
{ {
performAjaxCall([input stringValue]); [messageView addMessage:what];
[input setStringValue: ""]; [messageView scrollPoint:CGPointMake(0, [messageView frame].size.height)];

return self;
}


if ([label stringValue] == "Hello World!") - (id)clockCallback:(id)what
[label setStringValue:"Goodbye!"]; {
else [clock setStringValue:what];
[label setStringValue:"Hello World!"]; return self;
} }


- (id)buttonCallback:(id)what { @end
[label setStringValue:what];
[label sizeToFit]; @implementation MessageView : CPView
return self; {
CPArray messages;
} }


- (id)clockCallback:(id)what { - (void)addMessage:(CPString)aMessage
[clock setStringValue:what]; {
[clock sizeToFit]; [messages addObject:aMessage];
return self;
var size = [self frame].size;
[self setFrameSize:CGSizeMake(size.width, size.height + 30)];

var label = [[CPTextField alloc] initWithFrame:CGRectMake(5, size.height + 5, size.width - 10, 20)];
[label setAutoresizingMask:CPViewWidthSizable];

[label setStringValue:aMessage];

[self addSubview:label];
} }


@end @end


function ajaxCallback(what) { function ajaxCallback(what) {
[AppController.controllerInstance buttonCallback: what]; [AppController.controllerInstance buttonCallback:what];
} }


function clockCallback(time) { function clockCallback(time) {
[AppController.controllerInstance clockCallback: time]; [AppController.controllerInstance clockCallback:time];
} }

0 comments on commit 5e0d4cb

Please sign in to comment.