Gridarta Editor
src
utils
src
main
java
net
sf
gridarta
utils
DelayedChangeManager.java
Go to the documentation of this file.
1
/*
2
* Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3
* Copyright (C) 2000-2023 The Gridarta Developers.
4
*
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License along
16
* with this program; if not, write to the Free Software Foundation, Inc.,
17
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
*/
19
20
package
net.sf.gridarta.utils;
21
22
import
java.util.Timer;
23
import
java.util.TimerTask;
24
import
org.jetbrains.annotations.NotNull;
25
32
public
class
DelayedChangeManager
{
33
39
private
final
int
initialDelay
;
40
45
private
final
int
notificationDelay
;
46
50
@NotNull
51
private
final
DelayedChangeListener
delayedChangeListener
;
52
56
@NotNull
57
private
final
Timer
timer
=
new
Timer();
58
63
private
class
TimeoutTimerTask
extends
TimerTask {
64
65
@Override
66
public
void
run
() {
67
state
=
state
.
timeout
();
68
}
69
70
}
71
75
private
interface
State
{
76
81
@NotNull
82
State
change
();
83
88
@NotNull
89
State
finish
();
90
95
@NotNull
96
State
timeout
();
97
98
}
99
103
@NotNull
104
private
final
State
idle
=
new
State
() {
105
106
@NotNull
107
@Override
108
public
State
change
() {
109
timer
.schedule(
new
TimeoutTimerTask
(),
initialDelay
);
110
return
pending
;
111
}
112
113
@NotNull
114
@Override
115
public
State
finish
() {
116
return
idle
;
117
}
118
119
@NotNull
120
@Override
121
public
State
timeout() {
122
assert
false
;
123
return
idle
;
124
}
125
126
};
127
131
@NotNull
132
private
final
State
pending
=
new
State
() {
133
134
@NotNull
135
@Override
136
public
State
change
() {
137
return
pending
;
138
}
139
140
@NotNull
141
@Override
142
public
State
finish
() {
143
delayedChangeListener
.
change
();
144
return
wait
;
145
}
146
147
@NotNull
148
@Override
149
public
State
timeout() {
150
timer
.schedule(
new
TimeoutTimerTask
(),
notificationDelay
);
151
delayedChangeListener
.
change
();
152
return
wait
;
153
}
154
155
};
156
160
@NotNull
161
private
final
State
wait
=
new
State
() {
162
163
@NotNull
164
@Override
165
public
State
change
() {
166
return
pending
;
167
}
168
169
@NotNull
170
@Override
171
public
State
finish
() {
172
return
wait
;
173
}
174
175
@NotNull
176
@Override
177
public
State
timeout() {
178
return
idle
;
179
180
}
181
182
};
183
187
@NotNull
188
private
State
state
=
idle
;
189
199
public
DelayedChangeManager
(
final
int
initialDelay
,
final
int
notificationDelay
, @NotNull
final
DelayedChangeListener
delayedChangeListener
) {
200
this.initialDelay =
initialDelay
;
201
this.notificationDelay =
notificationDelay
;
202
this.delayedChangeListener =
delayedChangeListener
;
203
}
204
208
public
void
change
() {
209
state
=
state
.
change
();
210
}
211
218
public
void
finish
() {
219
state
=
state
.
finish
();
220
}
221
222
}
net.sf.gridarta.utils.DelayedChangeManager.pending
final State pending
Definition:
DelayedChangeManager.java:132
net.sf.gridarta.utils.DelayedChangeManager.DelayedChangeManager
DelayedChangeManager(final int initialDelay, final int notificationDelay, @NotNull final DelayedChangeListener delayedChangeListener)
Definition:
DelayedChangeManager.java:199
net.sf.gridarta.utils.DelayedChangeListener
Definition:
DelayedChangeListener.java:26
net.sf.gridarta.utils.DelayedChangeManager.State
Definition:
DelayedChangeManager.java:75
net.sf.gridarta.utils.DelayedChangeManager.delayedChangeListener
final DelayedChangeListener delayedChangeListener
Definition:
DelayedChangeManager.java:51
net.sf.gridarta.utils.DelayedChangeManager.TimeoutTimerTask
Definition:
DelayedChangeManager.java:63
net.sf.gridarta.utils.DelayedChangeManager.state
State state
Definition:
DelayedChangeManager.java:188
net.sf.gridarta.utils.DelayedChangeManager.finish
void finish()
Definition:
DelayedChangeManager.java:218
net.sf.gridarta.utils.DelayedChangeManager.idle
final State idle
Definition:
DelayedChangeManager.java:104
net.sf.gridarta.utils.DelayedChangeManager
Definition:
DelayedChangeManager.java:32
net.sf.gridarta.utils.DelayedChangeManager.timer
final Timer timer
Definition:
DelayedChangeManager.java:57
net.sf.gridarta.utils.DelayedChangeManager.initialDelay
final int initialDelay
Definition:
DelayedChangeManager.java:39
net.sf.gridarta.utils.DelayedChangeManager.notificationDelay
final int notificationDelay
Definition:
DelayedChangeManager.java:45
net.sf.gridarta.utils.DelayedChangeManager.State.finish
State finish()
net.sf.gridarta.utils.DelayedChangeManager.wait
final State wait
Definition:
DelayedChangeManager.java:161
net.sf.gridarta.utils.DelayedChangeManager.TimeoutTimerTask.run
void run()
Definition:
DelayedChangeManager.java:66
net.sf.gridarta.utils.DelayedChangeManager.State.timeout
State timeout()
net.sf.gridarta.utils.DelayedChangeListener.change
void change()
net.sf.gridarta.utils.DelayedChangeManager.State.change
State change()
net.sf.gridarta.utils.DelayedChangeManager.change
void change()
Definition:
DelayedChangeManager.java:208
Generated by
1.8.17