Skip to content
Browse files

Merge branch 'master' of git://github.com/boucher/Frothy

  • Loading branch information...
2 parents cc2092e + 4b97cdb commit 5e0d4cb9304691e9d4555e0bcf67395aa60a4a49 David Pollak committed Sep 3, 2009
Showing with 94 additions and 80 deletions.
  1. +94 −80 src/main/webapp/AppController.j
View
174 src/main/webapp/AppController.j
@@ -11,116 +11,130 @@
@implementation AppController : CPObject
{
- CPTextField label;
- CPTextField input;
- CPTextField clock;
- + AppController controllerInstance;
+ MessageView messageView;
+ CPTextField input;
+ CPTextField clock;
+ // + AppController controllerInstance;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
- AppController.controllerInstance = self;
- var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
- contentView = [theWindow contentView];
-
- label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
-
- [label setStringValue:@"Hello World!"];
- [label setFont:[CPFont boldSystemFontOfSize:24.0]];
- [label setAlignment:CPCenterTextAlignment];
- [label sizeToFit];
-
- [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
- [label setCenter:[contentView center]];
-
- [contentView addSubview:label];
+ AppController.controllerInstance = self;
+
+ var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
+ contentView = [theWindow contentView],
+ bounds = [contentView bounds];
+
+ [contentView setBackgroundColor:[CPColor colorWithWhite:0.85 alpha:1.0]];
+
+ var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds), CGRectGetHeight(bounds) - 40)];
+
+ [scrollView setHasHorizontalScroller:NO];
+
+ messageView = [[MessageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(bounds), 0)];
+
+ [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(
- 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 = [CPTextField roundedTextFieldWithStringValue:@"" placeholder:@"Send a message to the server..." width:CGRectGetWidth(bounds) - 145];
- [input sizeToFit];
+ [input setFrameOrigin:CGPointMake(10, CGRectGetHeight(bounds) - CGRectGetHeight([input bounds]) - 4)];
+ [input setAutoresizingMask:CPViewWidthSizable | CPViewMinYMargin];
- [input setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
- [input setEditable: YES];
- [input setBezeled: YES];
+ [input setTarget:self];
+ [input setAction:@selector(send:)];
+
+ [contentView addSubview:input];
- [contentView addSubview:input];
-
- var button = [[CPButton alloc] initWithFrame: CGRectMake(
- CGRectGetWidth([contentView bounds])/2.0 - 40,
- CGRectGetMaxY([label frame]) + 10,
- 80, 24
- )];
+ var button = [[CPButton alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - 125, CGRectGetHeight(bounds) - 31, 110, 24)];
- [button setAutoresizingMask:CPViewMinXMargin |
- CPViewMaxXMargin |
- CPViewMinYMargin |
- CPViewMaxYMargin];
-
- [button setTitle:"Click Me"];
+ [button setAutoresizingMask:CPViewMinXMargin | CPViewMinYMargin];
+ [button setTitle:"Send"];
- [button setTarget:self];
- [button setAction:@selector(swap:)];
+ [button setTarget:self];
+ [button setAction:@selector(send:)];
- [contentView addSubview:button];
-
- clock = [[CPTextField alloc] initWithFrame:CGRectMake(
- CGRectGetWidth([contentView bounds])/2.0 - 100,
- CGRectGetMaxY([label frame]) + 40,
- 80, 24
- )];
+ [contentView addSubview:button];
- [clock setStringValue:@""];
- [clock setFont:[CPFont boldSystemFontOfSize:24.0]];
+ [theWindow setDefaultButton:button];
- [clock sizeToFit];
+ clock = [[CPTextField alloc] initWithFrame:CGRectMake(CGRectGetWidth(bounds) - 250 - [CPScroller scrollerWidth], 0, 250, 22)];
- [clock setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
- [clock setAlignment:CPCenterTextAlignment];
- [contentView addSubview:clock];
+ [clock setFont:[CPFont systemFontOfSize:14.0]];
+ [clock setBackgroundColor:[CPColor colorWithRed:1.0 green:1.0 blue:0.0 alpha:0.3]];
+ [clock setAutoresizingMask:CPViewMinXMargin];
+ [clock setAlignment:CPCenterTextAlignment];
+ [contentView addSubview:clock];
+
+ [theWindow orderFront:self];
+}
- [theWindow orderFront:self];
-
- // Uncomment the following line to turn on the standard menu bar.
- // [CPMenu setMenuBarVisible:YES];
+- (void)send:(id)sender
+{
+ performAjaxCall([input stringValue]);
+ [input setStringValue:""];
}
-- (void)swap:(id)sender
+- (id)buttonCallback:(id)what
{
- performAjaxCall([input stringValue]);
- [input setStringValue: ""];
+ [messageView addMessage:what];
+ [messageView scrollPoint:CGPointMake(0, [messageView frame].size.height)];
+
+ return self;
+}
- if ([label stringValue] == "Hello World!")
- [label setStringValue:"Goodbye!"];
- else
- [label setStringValue:"Hello World!"];
+- (id)clockCallback:(id)what
+{
+ [clock setStringValue:what];
+ return self;
}
-- (id)buttonCallback:(id)what {
- [label setStringValue:what];
- [label sizeToFit];
- return self;
+@end
+
+@implementation MessageView : CPView
+{
+ CPArray messages;
}
-- (id)clockCallback:(id)what {
- [clock setStringValue:what];
- [clock sizeToFit];
- return self;
+- (void)addMessage:(CPString)aMessage
+{
+ [messages addObject:aMessage];
+
+ 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
function ajaxCallback(what) {
- [AppController.controllerInstance buttonCallback: what];
+ [AppController.controllerInstance buttonCallback:what];
}
function clockCallback(time) {
- [AppController.controllerInstance clockCallback: time];
+ [AppController.controllerInstance clockCallback:time];
}

0 comments on commit 5e0d4cb

Please sign in to comment.
Something went wrong with that request. Please try again.