Skip to content

Instantly share code, notes, and snippets.

Created March 1, 2010 03:10
Show Gist options
  • Save anonymous/318050 to your computer and use it in GitHub Desktop.
Save anonymous/318050 to your computer and use it in GitHub Desktop.
@import <AppKit/CPImage.j>
@import <AppKit/CPImageView.j>
@import "Photo.j"
@implementation PhotoListElement : CPView
{
CPImage _tagButtonImage;
CPImage _previewButtonImage;
CPImage _downloadButtonImage;
CPView _highlight;
CPView _toolBar;
CPButton _tag;
CPButton _preview;
CPButton _download;
CPImageView _imageView;
Photo _photo;
}
- (void)initWithFrame:(CGRect)aFrame
{
self = [super initWithFrame:aFrame];
if(self != null)
{
_imageView = [[CPImageView alloc] initWithFrame:
CGRectMake(5, 5, CGRectGetWidth(aFrame) - 10, CGRectGetHeight(aFrame) - 25)];
[_imageView setImageScaling:CPScaleProportionally];
[_imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
_tag = [[CPButton alloc] initWithFrame:CGRectMake(4, 0, 16, 16)];
[_tag setBordered:NO];
[_tag setImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_tag.png" size:CGSizeMake(16, 16)]];
[_tag setAlternateImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_tag_alt.png" size:CGSizeMake(16, 16)]];
_preview = [[CPButton alloc] initWithFrame:CGRectMake(28, 0, 16, 16)];
[_preview setBordered:NO];
[_preview setImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_preview.png" size:CGSizeMake(16, 16)]];
[_preview setAlternateImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_preview_alt.png" size:CGSizeMake(16, 16)]];
_download = [[CPButton alloc] initWithFrame:CGRectMake(52, 0, 16, 16)];
[_download setBordered:NO];
[_download setImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_download.png" size:CGSizeMake(16, 16)]];
[_download setAlternateImage:[[CPImage alloc]
initWithContentsOfFile:"resources/bt_download_alt.png" size:CGSizeMake(16, 16)]];
_toolBar = [[CPView alloc] initWithFrame:CGRectMake(
(CGRectGetWidth(aFrame) / 2) - 36, CGRectGetHeight(aFrame) - 20,
72, 20)];
[_toolBar addSubview:_tag];
[_toolBar addSubview:_preview];
[_toolBar addSubview:_download];
[_toolBar setAutoresizingMask: CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin];
_highlight = [[CPView alloc] initWithFrame:[self bounds]];
[_highlight setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
[_highlight setAutoresizingMask:CPViewWidthSizable|CPViewHeightSizable];
[self addSubview:_imageView];
}
return self;
}
- (void)setSelected:(BOOL)isSelected
{
CPLog.trace([self]);
CPLog.trace([self _photo]);
if(isSelected)
{
[_highlight setFrame:[self bounds]];
[self addSubview:_highlight positioned:CPWindowBelow relativeTo:_imageView];
[self addSubview:_toolBar];
}
else
{
[_highlight removeFromSuperview];
[_toolBar removeFromSuperview];
}
}
- (void)setRepresentedObject:(JSObject)anObject
{
CPLog.trace([anObject _id]);
_photo = anObject;
_imagePreview = [_photo _imagePreview];
[_imagePreview setDelegate:self];
[_tag setTarget:_photo];
[_tag setAction:@selector(tag)];
[_preview setTarget:_photo];
[_preview setAction:@selector(preview)];
[_download setTarget:_photo];
[_download setAction:@selector(download)];
if([_imagePreviewloadStatus] == CPImageLoadStatusCompleted)
[_imageView setImage:_imagePreview];
else
[_imageView setImage:nil];
}
- (void)imageDidLoad:(CPImage)anImage
{
[_imageView setImage:anImage];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment