1 package fr.ifremer.adagio.synchro.type;
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 import java.beans.PropertyChangeSupport;
27
28
29
30
31
32
33
34 public class ProgressionModel extends PropertyChangeSupport {
35
36 private static final long serialVersionUID = 1L;
37
38 public static final String PROPERTY_TOTAL = "total";
39
40 public static final String PROPERTY_CURRENT = "current";
41
42 public static final String PROPERTY_RATE = "rate";
43
44 public static final String PROPERTY_MESSAGE = "message";
45
46 protected int total;
47
48 protected int current;
49
50 protected float rate;
51
52 protected String message;
53
54
55
56
57
58
59
60 public ProgressionModel(Object sourceBean) {
61 super(sourceBean);
62 }
63
64 public int getTotal() {
65 return total;
66 }
67
68 public void setTotal(int total) {
69 Object oldValue = getTotal();
70 this.total = total;
71 firePropertyChange(PROPERTY_TOTAL, oldValue, total);
72 setCurrent(0);
73 }
74
75 public void adaptTotal(int total) {
76 int current = getCurrent();
77 setTotal(total);
78 increments(current);
79 Object oldValue = getTotal();
80 this.total = total;
81 firePropertyChange(PROPERTY_TOTAL, oldValue, total);
82 setCurrent(current);
83 }
84
85 public int getCurrent() {
86 return current;
87 }
88
89 public void setCurrent(int current) {
90 Object oldValue = getCurrent();
91 this.current = current;
92 firePropertyChange(PROPERTY_CURRENT, oldValue, current);
93 }
94
95 public void increments(int nb) {
96 setCurrent(current + nb);
97 setRate(getCurrent() / getTotal());
98 }
99
100 public float getRate() {
101 return rate;
102 }
103
104 public void setRate(float rate) {
105 Object oldValue = getRate();
106 this.rate = rate;
107 firePropertyChange(PROPERTY_RATE, oldValue, rate);
108 }
109
110 public String getMessage() {
111 return message;
112 }
113
114 public void increments(String message) {
115 increments(1);
116 setMessage(message);
117 }
118
119 public void setMessage(String message) {
120 Object oldValue = getMessage();
121 this.message = message;
122 firePropertyChange(PROPERTY_MESSAGE, oldValue, message);
123 }
124 }