Skip to content

Instantly share code, notes, and snippets.

@angerman
Created March 6, 2009 05:24
Show Gist options
  • Save angerman/74771 to your computer and use it in GitHub Desktop.
Save angerman/74771 to your computer and use it in GitHub Desktop.
/*
* AppController.j
*
* Created by __Me__ on __Date__.
* Copyright 2008 __MyCompanyName__. All rights reserved.
*/
@import <Foundation/CPObject.j>
@import "StarRatingView.j"
var values = [ @"No selection",
@"Failed",
@"Not good",
@"Average",
@"Good",
@"Very good",
@"Excellent" ];
@implementation AppController : CPObject
{
CPTextField indicator;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
contentView = [theWindow contentView];
// use our custom control
var rater = [[StarRatingView alloc] initWithFrame:CGRectMakeZero()];
[rater sizeToFit];
[rater setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
[rater setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds])
- CGRectGetWidth([rater frame])) / 2.0,
(CGRectGetHeight([contentView bounds])
- CGRectGetHeight([rater frame])) / 2.0)];
[rater setTarget:self];
[rater setAction:@selector(starClick:)];
var indicator = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[indicator setPlaceholderString:values[0]];
[indicator sizeToFit];
var bounds = [indicator bounds],
height = bounds.size.height;
[indicator setFrameSize:CGSizeMake(100,height)];
[indicator setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds])
+ CGRectGetWidth([rater frame]))/ 2.0,
(CGRectGetHeight([contentView bounds])
- height) / 2.0)];
// add our rater to the window
[contentView addSubview:rater];
[contentView addSubview:indicator];
[theWindow orderFront:self];
}
- (void)starClick:(id)sender
{
[indicator setStringValue:values[[sender intValue]]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment