PageRenderTime 19ms CodeModel.GetById 16ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/Polish/POText.j

http://github.com/polymar/polish
Unknown | 99 lines | 85 code | 14 blank | 0 comment | 0 complexity | 76ccf9b686d4cf5dceef8b1e63b0a876 MD5 | raw file
 1/*
 2 * POText.j
 3 *
 4 * Created by Roberto Gamboni on 02/17/2009.
 5 * Copyright 2008 Roberto Gamboni. All rights reserved.
 6 */
 7
 8@import <AppKit/CPTextField.j>
 9@import "CPViewAdditions.j"
10
11@implementation POText : CPTextField {
12	CPString 	_name;
13	var			_begin_function;
14	var 		_change_function;
15	var			_done_function;
16}
17
18/*
19* Init an editable text field with hmargin and vmargin = 0;
20*/
21- (id) text {
22	self = [super init];
23	if(self) {
24		[self createJSMethods: ['value:', 'name:']];
25		[self setFont:[CPFont systemFontOfSize:14]];
26	    [self setBezelStyle:CPTextFieldSquareBezel];
27	    [self setBezeled:YES];
28	    [self setEditable:YES];
29		[[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(begin_action:) name: "CPControlTextDidBeginEditingNotification" object: nil];
30		[[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(change_action:) name: "CPControlTextDidChangeNotification" object: nil];
31		[[CPNotificationCenter defaultCenter] addObserver: self selector: @selector(done_action:) name: "CPControlTextDidEndEditingNotification" object: nil];
32	}
33	return self;
34}
35
36/*
37* Init a label with hmargin and vmargin = 0
38*/
39- (id) label {
40	self = [super init];
41	if(self) {
42		[self createJSMethods: ['para:', 'name:']];
43		[self setFont:[CPFont systemFontOfSize:14]];
44	    [self setTextColor:[CPColor whiteColor]];
45	    [self sizeToFit];
46		[self setFrame:CGRectMake(0.0, 0.0, CGRectGetWidth([self bounds]), CGRectGetHeight([self bounds]))];
47	}
48	return self;
49}
50
51- (void) on_begin:(Function)aFunction {
52	_begin_function = aFunction;
53}
54
55- (void) on_change:(Function)aFunction {
56	_change_function = aFunction;
57}
58
59- (void) on_done:(Function)aFunction {
60	_done_function = aFunction;
61}
62
63- (void) begin_action:(CPNotification) notification {
64	if(_begin_function != nil)
65		_begin_function.call();
66}
67
68- (void) change_action:(CPNotification) notification {
69	if(_change_function != nil)
70		_change_function.call();
71}
72
73- (void) done_action:(CPNotification) notification {
74	if(_done_function != nil)
75		_done_function.call();
76}
77
78- (CPString) name:(CPString) n {
79	if(n != undefined)
80		_name = n;
81	else 
82		return _name;
83}
84
85- (void) value:(CPString) v {
86	if(v != undefined)
87		[self setStringValue:v];
88	else
89		return [self stringValue];
90}
91
92- (void) para:(CPString) v {
93	if(v != undefined)
94		[self setStringValue:v];
95	else
96		return [self stringValue];
97}
98
99@end