PageRenderTime 41ms CodeModel.GetById 36ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/AppController.j

http://github.com/primalmotion/MessageBoard-Example
Unknown | 126 lines | 96 code | 30 blank | 0 comment | 0 complexity | f8127a458cfbc981d32c903276509c60 MD5 | raw file
  1/*
  2 * AppController.j
  3 * StackView
  4 *
  5 * Created by You on September 24, 2010.
  6 * Copyright 2010, Your Company All rights reserved.
  7 */
  8
  9@import <Foundation/CPObject.j>
 10@import <MessageBoard/MessageBoard.j>
 11
 12@implementation AppController : CPObject
 13{
 14    CPView      _stackView;
 15    CPArray     _stackDatasource;
 16    CPTextField _textFieldPadding;
 17    CPTextField _textFieldWidth;
 18}
 19
 20- (void)applicationDidFinishLaunching:(CPNotification)aNotification
 21{
 22    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask];
 23    var contentView = [theWindow contentView];
 24    
 25    
 26    
 27    // stack view    
 28    _stackDatasource =    [
 29                    [self generateDummyView:"toto" height:30 color:[CPColor greenColor]], 
 30                    [self generateDummyView:@"titi" height:60 color:[CPColor yellowColor]], 
 31                    [self generateDummyView:@"tutu" height:50 color:[CPColor redColor]]
 32                ];
 33    
 34    
 35    _stackView = [[TNStackView alloc] initWithFrame:CGRectMake(10, 50, 300, 600)];
 36    
 37    [_stackView setBackgroundColor:[CPColor colorWithHexString:@"c7c7c7"]];
 38    [_stackView setDataSource:_stackDatasource];
 39    [_stackView reload];
 40    [contentView addSubview:_stackView];
 41    
 42    
 43    // controls
 44    var buttonAdd = [[CPButton alloc] initWithFrame:CGRectMake(10, 10, 100, 24)];
 45    [buttonAdd setTitle:@"Add dummy"];
 46    [buttonAdd setTarget:self];
 47    [buttonAdd setAction:@selector(addDummy:)];
 48    [contentView addSubview:buttonAdd];    
 49
 50    var _textFieldPadding = [CPTextField textFieldWithStringValue:@"1" placeholder:@"padding" width:100];
 51    [_textFieldPadding setFrame:CGRectMake(150, 6, 100, 30)];
 52    [_textFieldPadding setFloatValue:[_stackView padding]];
 53    [_textFieldPadding setTarget:self];
 54    [_textFieldPadding setAction:@selector(setPadding:)];
 55    [contentView addSubview:_textFieldPadding];
 56    
 57    var buttonPadding = [[CPButton alloc] initWithFrame:CGRectMake(250, 10, 100, 24)];
 58    [buttonPadding setTitle:@"Set padding"];
 59    [buttonPadding setTarget:self];
 60    [buttonPadding setAction:@selector(setPadding:)];
 61    [contentView addSubview:buttonPadding];
 62    
 63    
 64    var _textFieldWidth = [CPTextField textFieldWithStringValue:@"100" placeholder:@"width" width:100];
 65    [_textFieldWidth setFrame:CGRectMake(370, 6, 100, 30)];
 66    [_textFieldWidth setTarget:self];
 67    [_textFieldWidth setAction:@selector(setWidth:)];
 68    [_textFieldWidth setFloatValue:[_stackView frameSize].width];
 69    [contentView addSubview:_textFieldWidth];
 70    
 71    var buttonWidth = [[CPButton alloc] initWithFrame:CGRectMake(470, 10, 100, 24)];
 72    [buttonWidth setTitle:@"Set width"];
 73    [buttonWidth setTarget:self];
 74    [buttonWidth setAction:@selector(setWidth:)];
 75    [contentView addSubview:buttonWidth];
 76    
 77    
 78    var buttonReverse = [[CPButton alloc] initWithFrame:CGRectMake(600, 10, 100, 24)];
 79    [buttonReverse setTitle:@"Reverse"];
 80    [buttonReverse setTarget:self];
 81    [buttonReverse setAction:@selector(reverse:)];
 82    [contentView addSubview:buttonReverse];
 83    
 84    [theWindow orderFront:self];
 85}
 86
 87
 88- (CPView)generateDummyView:(CPString)aLabel height:(int)aHeight color:(CPColor)aColor
 89{
 90    var dummy = [[CPView alloc] initWithFrame:CGRectMake(0,0,100, aHeight)];
 91    var label = [[CPTextField alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
 92    
 93    [dummy setBackgroundColor:aColor];
 94    [label setStringValue:aLabel];
 95    
 96    [dummy addSubview:label];
 97    
 98    return dummy;
 99    
100}
101
102- (IBAction)addDummy:(id)sender
103{
104    [_stackDatasource addObject:[self generateDummyView:@"generated!" height:30 color:[CPColor grayColor]]];
105    [_stackView reload];
106}
107
108- (IBAction)setPadding:(id)sender
109{
110    [_stackView setPadding:[_textFieldPadding floatValue]];
111    [_stackView reload];
112}
113
114- (IBAction)setWidth:(id)sender
115{
116    var size = [_stackView frameSize];
117    size.width = [_textFieldWidth floatValue];
118    
119    [_stackView setFrameSize:size];
120}
121
122- (IBAction)reverse:(id)sender
123{
124    [_stackView reverse:sender];
125}
126@end