-
Notifications
You must be signed in to change notification settings - Fork 0
/
PopUpController.m
executable file
·92 lines (76 loc) · 1.75 KB
/
PopUpController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// PopUpController.m
// LabStatus
//
// Created by Christian Pape on 07.10.08.
// Copyright 2008 cc-productions. All rights reserved.
//
#import "PopUpController.h"
@implementation PopUpController
- (id)init
{
if (![super initWithWindowNibName:@"PopUpPanel"])
return nil;
return self;
}
- (void)awakeFromNib
{
}
- (void)windowWillClose:(NSNotification *)notification
{
[popUpPanel fadeOut];
}
- (void)showNextMessage
{
NSString* message = [popUpMessages objectAtIndex:0];
[popUpMessages removeObjectAtIndex:0];
[popUpTextField setStringValue:message];
}
- (void)addMessage:(NSString*)message
{
if (!popUpMessages)
popUpMessages = [[NSMutableArray alloc] init];
[popUpMessages addObject:message];
if (![popUpPanel isOpen]) {
[self showNextMessage];
[popUpPanel fadeIn];
} else {
if (!popUpTimer) {
[self showNextMessage];
}
}
if (!popUpTimer)
[self startTimer];
}
- (void)startTimer
{
popUpTimer = [NSTimer scheduledTimerWithTimeInterval: 2.0
target: self
selector: @selector(fireTimer:)
userInfo: nil
repeats: NO];
}
-(void)fireTimer:(NSTimer*)aTimer
{
if ([popUpPanel isOpen]) {
if ([popUpMessages count]>0) {
[self showNextMessage];
[self startTimer];
} else {
[popUpTimer invalidate];
popUpTimer = nil;
[popUpPanel fadeOut];
}
} else {
if ([popUpMessages count]>0) {
[self showNextMessage];
[popUpPanel fadeIn];
[self startTimer];
} else {
[popUpTimer invalidate];
popUpTimer = nil;
[popUpPanel fadeOut];
}
}
}
@end