Skip to content

Instantly share code, notes, and snippets.

@bonede
Forked from anonymous/gist:66200
Created February 18, 2009 06:43
Show Gist options
  • Save bonede/66231 to your computer and use it in GitHub Desktop.
Save bonede/66231 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
CPView m_windowContentView;
CPView m_panelContentView;
CPView m_jobsPanel;
CPCollectionView m_jobsView;
id m_statusstrings;
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
m_windowContentView = [theWindow contentView];
[m_windowContentView setBackgroundColor:[CPColor blackColor]];
[theWindow orderFront:self];
// add button now to change collectiion view data
var button = [[CPButton alloc] initWithFrame: CGRectMake( 15, 15, 200, 18 )];
[button setAutoresizingMask:CPViewMinXMargin |
CPViewMaxXMargin |
CPViewMinYMargin |
CPViewMaxYMargin];
[button setTitle:"Update collection view data"];
[button setTarget:self];
[button setAction:@selector(swap:)];
[m_windowContentView addSubview:button];
// var m_jobsPanel = [[CPView alloc] initWithFrame:CGRectMake(0, 60, 600, 400)];
var m_jobsPanel = [[CPPanel alloc] initWithContentRect:CGRectMake(0, 60, 600, 300)
styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask |
CPResizableWindowMask];
m_panelContentView = [m_jobsPanel contentView];
[m_jobsPanel setTitle:"Collection View Test"];
[m_jobsPanel setFloatingPanel:YES];
[m_jobsPanel orderFront:self];
bounds = [m_panelContentView bounds];
bounds.size.height -= 20.0;
var jobviewitem = [[CPCollectionViewItem alloc] init];
var jobCellView = [[jobCell alloc] initWithFrame: CGRectMakeZero()];
[jobviewitem setView: jobCellView];
var m_jobsView = [[CPCollectionView alloc]
initWithFrame: CGRectMake(0,0,1000,40)];
[m_jobsView setDelegate: self];
[m_jobsView setItemPrototype: jobviewitem];
[m_jobsView setMinItemSize:CGSizeMake(20, 35)];
[m_jobsView setMaxItemSize:CGSizeMake(1000, 150)];
[m_jobsView setMaxNumberOfColumns: 1];
[m_jobsView setVerticalMargin: 0];
[m_jobsView setAutoresizingMask: CPViewWidthSizable];
var scroller = [[CPScrollView alloc] initWithFrame:bounds];
[scroller setDocumentView: m_jobsView];
[scroller setHasHorizontalScroller: NO];
[scroller setAutoresizingMask: CPViewWidthSizable|CPViewHeightSizable];
[scroller setAutohidesScrollers: YES];
[m_panelContentView addSubview: scroller];
m_statusstrings = [ "string 1", "string2", "string3", "string4", "string5", "string6", "string7", "string8", "string9" ];
[m_jobsView setContent:m_statusstrings];
}
- (void) swap: (id) sender
{
CPLog.debug("swap was picked");
[m_jobsPanel setTitle:"Collection View Test (edited)"];
m_statusstrings[3] = "this should now change this one string";
[m_jobsView setContent:m_statusstrings];
[m_jobsView setNeedsDisplay: YES];
CPLog.debug("returned from setting content for collection view");
// another approach
var cviewItem = [m_jobsView newItemForRepresentedObject:m_statusstrings[3]];
[m_jobsView setContent:m_statusstrings];
[m_jobsView setNeedsDisplay: YES];
}
@end
/*--------------------------------------------------------------------*/
@implementation jobCell : CPView
{
CPTextField m_label;
CPView m_hilite;
}
- (void) setSelected: (BOOL) flag
{
CPLog.debug("cell:setSelected");
if(!m_hilite)
{
m_hilite = [[CPView alloc] initWithFrame:
CGRectCreateCopy([self bounds])];
[m_hilite setBackgroundColor: [CPColor darkGrayColor]];
}
if(flag)
{
[self addSubview: m_hilite
positioned: CPWindowBelow
relativeTo: m_label];
[m_label setTextColor: [CPColor whiteColor]];
}
else
{
[m_hilite removeFromSuperview];
[m_label setTextColor: [CPColor grayColor]];
}
}
- (void) setLabel:data
{
CPLog.debug("setLabel: " + data);
if (!m_label)
{
m_label = [[CPTextField alloc] initWithFrame: CGRectMake(4,4, 1000, 25)];
[m_label setTextColor: [CPColor grayColor]];
[self addSubview: m_label];
}
[m_label setStringValue: data];
}
- (void) setRepresentedObject: status
{
CPLog.debug("setRepresentedObject: " + status);
[self setLabel: status];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment