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

/Tests/Manual/TableTest/GroupRowTest/AppController.j

http://github.com/cacaodev/cappuccino
Unknown | 126 lines | 89 code | 37 blank | 0 comment | 0 complexity | fbc983794870c1206a732d689670407c MD5 | raw file
  1/*
  2 * AppController.j
  3 * GroupRowTest
  4 *
  5 * Created by You on August 27, 2010.
  6 * Copyright 2010, Your Company All rights reserved.
  7 */
  8
  9@import <Foundation/CPObject.j>
 10
 11
 12@implementation AppController : CPObject
 13{
 14    CPImage iconImage;
 15}
 16
 17- (void)applicationDidFinishLaunching:(CPNotification)aNotification
 18{
 19    var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
 20        contentView = [theWindow contentView],
 21
 22        tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)];
 23
 24    [tableView setAllowsMultipleSelection:YES];
 25    [tableView setAllowsColumnSelection:YES];
 26    [tableView setUsesAlternatingRowBackgroundColors:YES];
 27
 28    [tableView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
 29    [tableView setDelegate:self];
 30    [tableView setDataSource:self];
 31
 32    var iconView = [[CPImageView alloc] initWithFrame:CGRectMake(16, 16, 0, 0)];
 33    [iconView setImageScaling:CPImageScaleNone];
 34    var iconColumn = [[CPTableColumn alloc] initWithIdentifier:"icons"];
 35    [iconColumn setWidth:32.0];
 36    [iconColumn setMinWidth:32.0];
 37    [iconColumn setDataView:iconView];
 38    [tableView addTableColumn:iconColumn];
 39
 40    iconImage = [[CPImage alloc] initWithContentsOfFile:"http://www.cappuccino-project.org/img/favicon.ico" size:CGSizeMake(16, 16)];
 41
 42
 43    for (var i = 1; i <= 5; i++)
 44    {
 45        var column = [[CPTableColumn alloc] initWithIdentifier:String(i)];
 46
 47        [[column headerView] setStringValue:"Number " + i];
 48
 49        [column setMaxWidth:500.0];
 50        [column setWidth:200.0];
 51
 52        [tableView addTableColumn:column];
 53    }
 54
 55    var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth([contentView bounds]), CGRectGetHeight([contentView bounds]) / 2)];
 56
 57    [scrollView setDocumentView:tableView];
 58    [scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
 59
 60    [contentView addSubview:scrollView];
 61
 62    tableView = [[CPTableView alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 400.0)];
 63
 64    [tableView setAllowsMultipleSelection:YES];
 65    [tableView setAllowsColumnSelection:YES];
 66
 67    [tableView setColumnAutoresizingStyle:CPTableViewLastColumnOnlyAutoresizingStyle];
 68    [tableView setSelectionHighlightStyle:CPTableViewSelectionHighlightStyleSourceList];
 69    [tableView setDelegate:self];
 70    [tableView setDataSource:self];
 71
 72    var iconView = [[CPImageView alloc] initWithFrame:CGRectMake(16, 16, 0, 0)];
 73    [iconView setImageScaling:CPImageScaleNone];
 74    var iconColumn = [[CPTableColumn alloc] initWithIdentifier:"icons"];
 75    [iconColumn setWidth:32.0];
 76    [iconColumn setMinWidth:32.0];
 77    [iconColumn setDataView:iconView];
 78    [tableView addTableColumn:iconColumn];
 79
 80    for (var i = 1; i <= 5; i++)
 81    {
 82        var column = [[CPTableColumn alloc] initWithIdentifier:String(i)];
 83
 84        [[column headerView] setStringValue:"Number " + i];
 85
 86        [column setMaxWidth:500.0];
 87        [column setWidth:200.0];
 88
 89        [tableView addTableColumn:column];
 90    }
 91
 92    var scrollView = [[CPScrollView alloc] initWithFrame:CGRectMake(0, CGRectGetHeight([contentView bounds]) / 2, CGRectGetWidth([contentView bounds]), CGRectGetHeight([contentView bounds]) / 2)];
 93
 94    [scrollView setDocumentView:tableView];
 95    [scrollView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
 96
 97    [contentView addSubview:scrollView];
 98
 99    [theWindow orderFront:self];
100
101}
102
103- (int)numberOfRowsInTableView:(CPTableView)atableView
104{
105    return 500;
106}
107
108- (id)tableView:(CPTableView)aTableView objectValueForTableColumn:(CPTableColumn)aColumn row:(CPInteger)aRow
109{
110    if ([aColumn identifier] === "icons")
111        return iconImage;
112
113    return aRow;
114}
115
116- (BOOL)tableView:(CPTableView)aTableView isGroupRow:(CPInteger)aRow
117{
118    var groups = [];
119
120    for (var i = 0; i < 100; i += 5)
121        groups.push(i);
122
123    return [groups containsObject:aRow];
124}
125
126@end