@implementation ArticleCell : CPView
{
    CPImage image;
    CPImageView imageView;
    CPTextField textField;

	CPDictionary dictionary @accessors;
}

- (void)setRepresentedObject:(id)anObject
{
	// Associate the dictionary with the CategoryCell instance
	dictionary = anObject;
	var articleImageUrl = [dictionary objectForKey:@"articleImageUrl"];
	var articleTitle = [dictionary objectForKey:@"articleTitle"];
		
    if (!imageView)
    {
        imageView = [[CPImageView alloc] initWithFrame:CGRectMake(5.0, 5.0, 40.0, 40.0)];
        [imageView setImageScaling:CPScaleProportionally];
        [self addSubview:imageView];
    }
    
    if (!textField)
    {
        textField = [[CPTextField alloc] initWithFrame:CGRectMake(50.0, 15.0, 145.0, 20.0)];
        [textField setFont:[CPFont boldSystemFontOfSize:12.0]];
        [self addSubview:textField];
    }
    
    [textField setStringValue:articleTitle];

	// For first use of this method, image == nil, so the message is discarded.
	// For second use of this methode, image != nil, we remove the delegate for this old image. 
    [image setDelegate:nil];
    
	// Load the image
    image = [[CPImage alloc] initWithContentsOfFile:articleImageUrl];
    [image setDelegate:self];
    
	// Verify that the image is loaded. 
	// If it is not, it will be associated with the imageView by the image delegate method imageDidLoad:
    if([image loadStatus] == CPImageLoadStatusCompleted)
        [imageView setImage:image];
    else
        [imageView setImage:nil];
}

// Called since we have marked ouself to be the image delegate
- (void)imageDidLoad:(CPImage)anImage
{
	//debugger;
    [imageView setImage:anImage];
}

- (void)setSelected:(BOOL)isSelected
{
    [self setBackgroundColor:isSelected ? [CPColor blueColor] : nil];
    [textField setTextColor:isSelected ? [CPColor whiteColor] : [CPColor blackColor]];
}

@end