46 |
45 |
47 /** |
46 /** |
48 * Incremental updating constant. |
47 * Incremental updating constant. |
49 */ |
48 */ |
50 public static final int INCREMENTAL_UPDATING = 3; |
49 public static final int INCREMENTAL_UPDATING = 3; |
|
50 |
|
51 /** |
|
52 * If Gauge is changed, reasons for Re-layouting. |
|
53 */ |
|
54 static final int UPDATE_MAXVALUE = UPDATE_ITEM_MAX << 1; |
|
55 static final int UPDATE_VALUE = UPDATE_ITEM_MAX << 2; |
|
56 |
51 |
57 |
52 private int maxValue; |
58 private int maxValue; |
53 private int value; |
59 private int value; |
54 private boolean interactive; |
60 private boolean interactive; |
|
61 private boolean isGaugeCreation; |
55 |
62 |
56 /** |
63 /** |
57 * Constructor. |
64 * Constructor. |
58 * |
65 * |
59 * @param name the label. |
66 * @param name the label. |
62 * @param initVal the initial value. |
69 * @param initVal the initial value. |
63 */ |
70 */ |
64 public Gauge(String name, boolean interactive, int maxVal, int initVal) |
71 public Gauge(String name, boolean interactive, int maxVal, int initVal) |
65 { |
72 { |
66 setLabel(name); |
73 setLabel(name); |
|
74 isGaugeCreation = true; |
67 this.interactive = interactive; |
75 this.interactive = interactive; |
68 setMaxValue(maxVal); |
76 setMaxValue(maxVal); |
69 setValue(initVal); |
77 setValue(initVal); |
|
78 isGaugeCreation = false; |
70 } |
79 } |
71 |
80 |
72 /** |
81 /** |
73 * Check value validity. |
82 * Check value validity. |
74 * |
83 * |
75 * @param value the value. |
84 * @param value the value. |
76 * @param maxVal the maximum value. |
85 * @param maxVal the maximum value. |
77 * @return validated value. |
86 * @return validated value. |
78 */ |
87 */ |
79 private static int checkValue(int value, int maxVal) |
88 private int checkValue(int value, int maxVal) |
80 { |
89 { |
81 if(maxVal == INDEFINITE) |
90 if(maxVal == INDEFINITE) |
82 { |
91 { |
83 switch(value) |
92 if(isGaugeCreation) |
84 { |
93 { |
85 case CONTINUOUS_IDLE: |
94 switch(value) |
86 case INCREMENTAL_IDLE: |
95 { |
87 case CONTINUOUS_RUNNING: |
96 case CONTINUOUS_IDLE: |
88 case INCREMENTAL_UPDATING: |
97 case INCREMENTAL_IDLE: |
89 break; |
98 case CONTINUOUS_RUNNING: |
90 default: |
99 case INCREMENTAL_UPDATING: |
91 throw new IllegalArgumentException( |
100 break; |
92 MsgRepository.GAUGE_EXCEPTION_INVALID_VALUE); |
101 default: |
|
102 throw new IllegalArgumentException( |
|
103 MsgRepository.GAUGE_EXCEPTION_INVALID_VALUE); |
|
104 } |
|
105 |
|
106 return value; |
93 } |
107 } |
94 return value; |
108 else |
|
109 { |
|
110 return CONTINUOUS_IDLE; |
|
111 } |
95 } |
112 } |
96 else |
113 else |
97 { |
114 { |
98 // make sure the value is in [0, maxValue] range |
115 // make sure the value is in [0, maxValue] range |
99 value = (value < 0 ? 0 : value); |
116 value = (value < 0 ? 0 : value); |
109 * @param interactive is interactive. |
126 * @param interactive is interactive. |
110 * @return validated maximum value. |
127 * @return validated maximum value. |
111 */ |
128 */ |
112 private static int checkMaxValue(int maxVal, boolean interactive) |
129 private static int checkMaxValue(int maxVal, boolean interactive) |
113 { |
130 { |
114 if(!interactive) |
131 if(interactive) |
115 { |
132 { |
116 if(maxVal == INDEFINITE) |
133 if(maxVal <= 0) |
117 { |
134 { |
118 return maxVal; |
135 throw new IllegalArgumentException( |
|
136 MsgRepository.GAUGE_EXCEPTION_INVALID_MAXVALUE); |
119 } |
137 } |
120 } |
|
121 if(maxVal <= 0) |
|
122 { |
|
123 throw new IllegalArgumentException( |
|
124 MsgRepository.GAUGE_EXCEPTION_INVALID_MAXVALUE); |
|
125 } |
138 } |
126 return maxVal; |
139 return maxVal; |
127 } |
140 } |
128 |
141 |
129 /** |
142 /** |
138 * if Gauge state is incremental-updating and it is non-interactive and |
151 * if Gauge state is incremental-updating and it is non-interactive and |
139 * indefinite, we should update Gauge when this method is called, but |
152 * indefinite, we should update Gauge when this method is called, but |
140 * that requires eSWT extension. |
153 * that requires eSWT extension. |
141 */ |
154 */ |
142 this.value = checkValue(value, this.maxValue); |
155 this.value = checkValue(value, this.maxValue); |
143 updateParent(UPDATE_CONTENT); |
156 updateParent(UPDATE_VALUE); |
144 } |
157 } |
145 |
158 |
146 /** |
159 /** |
147 * Get value. |
160 * Get value. |
148 * |
161 * |
160 */ |
173 */ |
161 public void setMaxValue(int maxValue) |
174 public void setMaxValue(int maxValue) |
162 { |
175 { |
163 this.maxValue = checkMaxValue(maxValue, interactive); |
176 this.maxValue = checkMaxValue(maxValue, interactive); |
164 this.value = checkValue(getValue(), this.maxValue); |
177 this.value = checkValue(getValue(), this.maxValue); |
165 updateParent(UPDATE_CONTENT); |
178 updateParent(UPDATE_MAXVALUE); |
166 } |
179 } |
167 |
180 |
168 /** |
181 /** |
169 * Get maximum value. |
182 * Get maximum value. |
170 * |
183 * |
255 */ |
268 */ |
256 boolean isSuitableForAlert() |
269 boolean isSuitableForAlert() |
257 { |
270 { |
258 return (!isInteractive() |
271 return (!isInteractive() |
259 && getParent() == null |
272 && getParent() == null |
260 && !hasLabel() |
273 && getLabel() == null |
261 && getLayout() == Item.LAYOUT_DEFAULT |
274 && getLayout() == Item.LAYOUT_DEFAULT |
262 && !isSizeLocked() |
275 && !isSizeLocked() |
263 && getNumCommands() == 0 |
276 && getNumCommands() == 0 |
264 && getItemCommandListener() == null); |
277 && getItemCommandListener() == null); |
265 } |
278 } |