//
// AboutController.j
// Photo Display
//
// Created by Philippe Laval.
//

@import <Foundation/CPObject.j>

@import <AppKit/CPWindowController.j>

@import "WLURLLabel.j"
@import "WLHTMLTextField.j"


var aboutControllerSharedInstance = nil;

@implementation AboutController : CPWindowController
{
}

+ (AboutController)sharedAboutController
{
	// debugger;
	
    if (aboutControllerSharedInstance == nil)
    {
        aboutControllerSharedInstance = [[AboutController alloc] init];
    }
    
    return aboutControllerSharedInstance;
}

-(void)showAboutWindow:(id)sender
{
    var sharedAboutController = [AboutController sharedAboutController];
    [sharedAboutController showWindow:sender];
}

-(void)hideAboutWindow:(id)sender
{
    var sharedAboutController = [AboutController sharedAboutController];
    [[sharedAboutController window] orderOut:sender];
}

-(void)toggleAboutWindow:(id)sender 
{
	// debugger;
    var sharedAboutController = [AboutController sharedAboutController];
    var aboutWindow = [sharedAboutController window];
    
  	if ([aboutWindow isVisible] == YES) {
    	[aboutWindow orderOut:sender];
  	}
  	else {
    	[sharedAboutController showWindow:sender];
  	}
}

- (id)init
{
	// Create the about window
    var theWindow = [[CPPanel alloc] initWithContentRect:CGRectMake(150,150,300,200) styleMask:CPHUDBackgroundWindowMask | CPClosableWindowMask | CPTitledWindowMask];
    self = [super initWithWindow:theWindow];
    if (self)
    {
		[theWindow setTitle:@"About Photo Display"];
		[theWindow setLevel:CPFloatingWindowLevel];
        
        [theWindow setDelegate:self];

		var contentView = [theWindow contentView];
		
		var titleLabel = [self makeURLLabelWith:@"Philippe Laval" andUrl:@"http://www.nice-panorama.com/" at:CPRectMake(0,0,300,30)];
		[titleLabel setTextColor:[CPColor whiteColor]];
		[titleLabel setFont:[CPFont boldSystemFontOfSize:16.0]];
		[titleLabel setAlignment:CPCenterTextAlignment];
		[contentView addSubview:titleLabel];
		
		var uLabel = [self makeLabelWith:@"Made using" at:CPRectMake(0,30,300,30)];
		[uLabel setTextColor:[CPColor lightGrayColor]];
		[uLabel setFont:[CPFont boldSystemFontOfSize:16.0]];
		[uLabel setAlignment:CPCenterTextAlignment];
		[contentView addSubview:uLabel];
		
		var cLabel = [self makeURLLabelWith:@"Cappuccino" andUrl:@"http://cappuccino.org/" at:CPRectMake(0,60,300,30)];
		[cLabel setTextColor:[CPColor whiteColor]];
		[cLabel setFont:[CPFont boldSystemFontOfSize:16.0]];
		[cLabel setAlignment:CPCenterTextAlignment];
		[contentView addSubview:cLabel];
	}
	
	return self;
}


-(CPTextField)makeLabelWith:(CPString)aString at:(CPRect)aFrame
{
	var field = [[WLHTMLTextField alloc] initWithFrame:aFrame];
	[field setFont:[CPFont boldSystemFontOfSize:12.0]];
	[field setStringValue:aString];
	[field setAutoresizingMask:CPViewWidthSizable];
	return field;
}

-(CPTextField)makeURLLabelWith:(CPString)aString andUrl:(CPString)aURL at:(CPRect)aFrame
{
	var field = [[WLURLLabel alloc] initWithFrame:aFrame];
	[field setUrl:aURL];
	[field setFont:[CPFont boldSystemFontOfSize:12.0]];
	[field setStringValue:aString];
	[field setAutoresizingMask:CPViewWidthSizable];
	return field;
}

- (void)windowWillClose:(id)aSender
{
	// Update the menu state
}

@end
