1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Event-based interface to track the progression of an operation.
14 # An operation that is trackable using a `ProgressionListener`.
15 abstract class Trackable
17 # Listen to the progression of the operation.
18 var progression_listeners
: SimpleCollection[ProgressionListener] =
19 new Array[ProgressionListener]
21 # Notice the registered `ProgessionListener` that the operation started.
22 protected fun fire_started
do
23 for l
in progression_listeners
do
29 # Notice the registered `ProgessionListener` that the operation progressed.
33 # * `done_part`: Indicates what is done.
34 # * `total`: Indicates what need to be done, `done_part` included.
35 protected fun fire_progressed
(done_part
: Int, total
: Int) do
36 for l
in progression_listeners
do
37 l
.progressed
(done_part
* l
.progression_max
/ total
)
41 # Notice the registered `ProgessionListener` that the operation is done.
42 protected fun fire_done
do
43 for l
in progression_listeners
do
44 l
.progressed
(l
.progression_max
)
50 # Listens to the progression of a possibly long-running operation.
51 interface ProgressionListener
52 # The number that represents a completed operation.
53 fun progression_max
: Int do return 100
55 # The operation started.
58 # The operation progressed.
62 # * `progression`: Indicator of the progession, between `0` and
64 fun progressed
(progression
: Int) do end
66 # The operation is done.