/*******************************************************************************
 Copyright (c) 2005-2006 Jordy Rose
 
 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:
 
 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.
 
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 SOFTWARE.
 
 Except as contained in this notice, the name(s) of the above copyright holders
 shall not be used in advertising or otherwise to promote the sale, use or other
 dealings in this Software without prior authorization.
*******************************************************************************/

//
//  DockItemInfoShortFormatter.m
//  Dockyard
//

#import "DockItemInfoShortFormatter.h"

/*!
 * Formats instances of DockItemInfo into strings by printing out their label.
 * If the item being passed in is not an instance of DockItemInfo, its
 * <code>description</code> will be printed in grey. The reverse method
 * merely returns the string inputted by the user - other formatting may be 
 * done further along to make this useful.
 */
@implementation DockItemInfoShortFormatter
- (NSString *)stringForObjectValue:(id)dockItemInfo
{
	if (![dockItemInfo isKindOfClass:[DockItemInfo class]]) return [dockItemInfo description];
	
	return [dockItemInfo label];
}

- (NSAttributedString *)attributedStringForObjectValue:(id)dockItemInfo withDefaultAttributes:(NSDictionary *)atts
{
	if ([dockItemInfo isKindOfClass:[DockItemInfo class]]) {
		return [[[NSAttributedString alloc] initWithString:[self stringForObjectValue:dockItemInfo] attributes:atts] autorelease];
		
	} else {
		atts = [atts mutableCopy];
		[(NSMutableDictionary *)atts setObject:[NSColor grayColor] forKey:NSForegroundColorAttributeName];
		return [[[NSAttributedString alloc] initWithString:[dockItemInfo description] attributes:[atts autorelease]] autorelease];
	}
}

- (BOOL)getObjectValue:(id *)obj forString:(NSString *)str errorDescription:(NSString **)error
{
	*obj	= str;
	*error	= @"DockItemInfo can not be created from a label! No reverse conversion allowed!";
	return YES;
}
@end
