2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 #import "AITextColorPreviewView.h"
18 #import <AIUtilities/AIStringUtilities.h>
19 #import <AIUtilities/AIGradient.h>
20 #import <AIUtilities/AIParagraphStyleAdditions.h>
21 #import <AIUtilities/AIApplicationAdditions.h>
23 @interface AITextColorPreviewView (PRIVATE)
24 - (void)_initTextColorPreviewView;
27 @implementation AITextColorPreviewView
29 - (id)initWithCoder:(NSCoder *)aDecoder
31 [super initWithCoder:aDecoder];
32 [self _initTextColorPreviewView];
36 - (id)initWithFrame:(NSRect)frameRect
38 [super initWithFrame:frameRect];
39 [self _initTextColorPreviewView];
43 - (void)_initTextColorPreviewView
45 backColorOverride = nil;
48 - (void)drawRect:(NSRect)rect
50 NSMutableDictionary *attributes;
51 NSAttributedString *sample;
52 NSShadow *shadow = nil;
56 if ([backgroundEnabled state] != NSOffState) {
57 if (backgroundGradientColor) {
58 [[AIGradient gradientWithFirstColor:[backgroundGradientColor color]
59 secondColor:[backgroundColor color]
60 direction:AIVertical] drawInRect:rect];
62 [(backColorOverride ? backColorOverride : [backgroundColor color]) set];
63 [NSBezierPath fillRect:rect];
68 if (([textShadowColorEnabled state] != NSOffState) && [textShadowColor color]) {
69 shadow = [[[NSShadow alloc] init] autorelease];
70 [shadow setShadowOffset:NSMakeSize(0.0, -1.0)];
71 [shadow setShadowBlurRadius:2.0];
72 [shadow setShadowColor:[textShadowColor color]];
76 attributes = [NSMutableDictionary dictionaryWithObjectsAndKeys:
77 [NSFont systemFontOfSize:12], NSFontAttributeName,
78 [NSParagraphStyle styleWithAlignment:NSCenterTextAlignment], NSParagraphStyleAttributeName,
79 [textColor color], NSForegroundColorAttributeName,
80 shadow, NSShadowAttributeName,
83 sample = [[[NSAttributedString alloc] initWithString:AILocalizedString(@"Sample",nil)
84 attributes:attributes] autorelease];
85 sampleSize = [sample size];
87 [sample drawInRect:NSIntegralRect(NSMakeRect(rect.origin.x + ((rect.size.width - sampleSize.width) / 2.0),
88 rect.origin.y + ((rect.size.height - sampleSize.height) / 2.0),
95 [backColorOverride release];
99 //Overrides. pass nil to disable
100 - (void)setBackColorOverride:(NSColor *)inColor
102 if (backColorOverride != inColor) {
103 [backColorOverride release];
104 backColorOverride = [inColor retain];