162 eswtUpdateProgressbar(comp, false, false); |
167 eswtUpdateProgressbar(comp, false, false); |
163 |
168 |
164 return comp; |
169 return comp; |
165 } |
170 } |
166 |
171 |
167 int eswtGetPreferredContentHeight() { |
172 int eswtGetPreferredContentHeight() |
|
173 { |
168 int ret = getContentComp().computeSize(SWT.DEFAULT, SWT.DEFAULT).y; |
174 int ret = getContentComp().computeSize(SWT.DEFAULT, SWT.DEFAULT).y; |
169 |
175 |
170 // Point imgSize = (eswtImgLabel != null |
176 // Point imgSize = (eswtImgLabel != null |
171 // ? eswtImgLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT) : new Point(0, 0)); |
177 // ? eswtImgLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT) : new Point(0, 0)); |
172 // int ret = Math.max( |
178 // int ret = Math.max( |
173 // Math.min( |
179 // Math.min( |
174 // eswtScrolledText.computeSize(topShell.getClientArea().width - imgSize.x, SWT.DEFAULT).y, |
180 // eswtScrolledText.computeSize(topShell.getClientArea().width - imgSize.x, SWT.DEFAULT).y, |
175 // topShell.getClientArea().height / 2), |
181 // topShell.getClientArea().height / 2), |
176 // imgSize.y); |
182 // imgSize.y); |
177 |
183 |
178 if (eswtProgressBar != null && eswtProgressBar.isVisible()) { |
184 if(eswtProgressBar != null && eswtProgressBar.isVisible()) |
|
185 { |
179 ret += eswtProgressBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; |
186 ret += eswtProgressBar.computeSize(SWT.DEFAULT, SWT.DEFAULT).y; |
180 } |
187 } |
181 return ret; |
188 return ret; |
182 } |
189 } |
183 |
190 |
190 * @param indeterminate |
197 * @param indeterminate |
191 * @param visible |
198 * @param visible |
192 */ |
199 */ |
193 void eswtUpdateProgressbar(Composite parent, |
200 void eswtUpdateProgressbar(Composite parent, |
194 boolean indeterminate, |
201 boolean indeterminate, |
195 boolean visible) { |
202 boolean visible) |
|
203 { |
196 // Only dispose old ProgressBar if it has wrong style |
204 // Only dispose old ProgressBar if it has wrong style |
197 if (eswtProgressBar != null) { |
205 if(eswtProgressBar != null) |
|
206 { |
198 boolean isIndeterminate = |
207 boolean isIndeterminate = |
199 (eswtProgressBar.getStyle() & SWT.INDETERMINATE) != 0; |
208 (eswtProgressBar.getStyle() & SWT.INDETERMINATE) != 0; |
200 if (indeterminate != isIndeterminate) { |
209 if(indeterminate != isIndeterminate) |
|
210 { |
201 eswtProgressBar.setLayoutData(null); |
211 eswtProgressBar.setLayoutData(null); |
202 eswtProgressBar.dispose(); |
212 eswtProgressBar.dispose(); |
203 eswtProgressBar = null; |
213 eswtProgressBar = null; |
204 } |
214 } |
205 } |
215 } |
206 // create new ProgressBar |
216 // create new ProgressBar |
207 if (eswtProgressBar == null) { |
217 if(eswtProgressBar == null) |
|
218 { |
208 int newStyle = indeterminate ? SWT.INDETERMINATE : SWT.NONE; |
219 int newStyle = indeterminate ? SWT.INDETERMINATE : SWT.NONE; |
209 eswtProgressBar = new ProgressBar(parent, newStyle); |
220 eswtProgressBar = new ProgressBar(parent, newStyle); |
210 eswtProgressBar.setLayoutData(eswtProgbarLD); |
221 eswtProgressBar.setLayoutData(eswtProgbarLD); |
211 // update ScrolledText's layoutdata |
222 // update ScrolledText's layoutdata |
212 FormData imageLD = (FormData) eswtImgLabel.getLayoutData(); |
223 FormData imageLD = (FormData) eswtImgLabel.getLayoutData(); |
213 imageLD.bottom = new FormAttachment(eswtProgressBar); |
224 imageLD.bottom = new FormAttachment(eswtProgressBar); |
214 } |
225 } |
215 // set Progressbar visibility |
226 // set Progressbar visibility |
216 if (eswtProgressBar != null) { |
227 if(eswtProgressBar != null) |
|
228 { |
217 eswtProgbarLD.top = (visible ? null : new FormAttachment(100)); |
229 eswtProgbarLD.top = (visible ? null : new FormAttachment(100)); |
218 eswtProgressBar.setVisible(visible); |
230 eswtProgressBar.setVisible(visible); |
219 } |
231 } |
220 } |
232 } |
221 |
233 |
224 * |
236 * |
225 * @param minValue the minimum value |
237 * @param minValue the minimum value |
226 * @param maxValue the maximum value |
238 * @param maxValue the maximum value |
227 * @param selValue the value |
239 * @param selValue the value |
228 */ |
240 */ |
229 void eswtSetProgressbarValues(int minValue, int maxValue, int selValue) { |
241 void eswtSetProgressbarValues(int minValue, int maxValue, int selValue) |
230 if (eswtProgressBar != null) { |
242 { |
|
243 if(eswtProgressBar != null) |
|
244 { |
231 eswtProgressBar.setMinimum(minValue); |
245 eswtProgressBar.setMinimum(minValue); |
232 eswtProgressBar.setMaximum(maxValue); |
246 eswtProgressBar.setMaximum(maxValue); |
233 eswtProgressBar.setSelection(selValue); |
247 eswtProgressBar.setSelection(selValue); |
234 } |
248 } |
235 } |
249 } |
236 |
250 |
237 /* (non-Javadoc) |
251 /* (non-Javadoc) |
238 * @see javax.microedition.lcdui.Displayable#handleShowEvent() |
252 * @see javax.microedition.lcdui.Displayable#handleShowEvent() |
239 */ |
253 */ |
240 void eswtHandleShowCurrentEvent() { |
254 void eswtHandleShowCurrentEvent() |
|
255 { |
241 super.eswtHandleShowCurrentEvent(); |
256 super.eswtHandleShowCurrentEvent(); |
242 topShell.addListener(SWT.Resize, resizeListener); |
257 topShell.addListener(SWT.Resize, resizeListener); |
243 |
258 |
244 // add key filter for scrollable text composite |
259 // add key filter for scrollable text composite |
245 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
260 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
246 SWT.KeyDown, keyListener); |
261 SWT.KeyDown, keyListener); |
247 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
262 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
248 SWT.Traverse, keyListener); |
263 SWT.Traverse, keyListener); |
249 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
264 org.eclipse.swt.widgets.Display.getCurrent().addFilter( |
250 SWT.MouseUp, keyListener); |
265 SWT.MouseUp, keyListener); |
251 resetTimerTask(true); |
266 resetTimerTask(true); |
252 } |
267 } |
253 |
268 |
254 /* (non-Javadoc) |
269 /* (non-Javadoc) |
255 * @see javax.microedition.lcdui.Displayable#handleHideEvent() |
270 * @see javax.microedition.lcdui.Displayable#handleHideEvent() |
256 */ |
271 */ |
257 void eswtHandleHideCurrentEvent() { |
272 void eswtHandleHideCurrentEvent() |
|
273 { |
258 super.eswtHandleHideCurrentEvent(); |
274 super.eswtHandleHideCurrentEvent(); |
259 topShell.removeListener(SWT.Resize, resizeListener); |
275 topShell.removeListener(SWT.Resize, resizeListener); |
260 |
276 |
261 nextDisplayable = null; |
277 nextDisplayable = null; |
262 resetTimerTask(false); |
278 resetTimerTask(false); |
263 |
279 |
264 // remove key filter for scrollable text composite |
280 // remove key filter for scrollable text composite |
265 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
281 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
266 SWT.KeyDown, keyListener); |
282 SWT.KeyDown, keyListener); |
267 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
283 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
268 SWT.Traverse, keyListener); |
284 SWT.Traverse, keyListener); |
269 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
285 org.eclipse.swt.widgets.Display.getCurrent().removeFilter( |
270 SWT.MouseUp, keyListener); |
286 SWT.MouseUp, keyListener); |
271 } |
287 } |
272 |
288 |
273 |
289 |
274 /** |
290 /** |
275 * Set the next displayable to be shown. |
291 * Set the next displayable to be shown. |
276 * |
292 * |
277 * @param next next displayable |
293 * @param next next displayable |
278 */ |
294 */ |
279 void setNextDisplayable(Displayable next) { |
295 void setNextDisplayable(Displayable next) |
|
296 { |
280 nextDisplayable = next; |
297 nextDisplayable = next; |
281 } |
298 } |
282 |
299 |
283 /** |
300 /** |
284 * Gets the default Alert image based on the type. |
301 * Gets the default Alert image based on the type. |
285 * |
302 * |
286 * @param type the alert type |
303 * @param type the alert type |
287 * @return the default image based on the type or null if the type is null |
304 * @return the default image based on the type or null if the type is null |
288 */ |
305 */ |
289 private static int getDefaultImageType(final AlertType type) { |
306 private static int getDefaultImageType(final AlertType type) |
290 if (type == AlertType.ERROR) { |
307 { |
291 return LabelExtension.STANDARDICON_ERROR; |
308 if(type == AlertType.ERROR) |
292 } |
309 { |
293 else if (type == AlertType.WARNING) { |
310 return LabelExtension.STANDARDICON_ERROR; |
294 return LabelExtension.STANDARDICON_WARNING; |
311 } |
295 } |
312 else if(type == AlertType.WARNING) |
296 else if (type == AlertType.INFO) { |
313 { |
297 return LabelExtension.STANDARDICON_INFO; |
314 return LabelExtension.STANDARDICON_WARNING; |
298 } |
315 } |
299 else if (type == AlertType.CONFIRMATION) { |
316 else if(type == AlertType.INFO) |
300 return LabelExtension.STANDARDICON_CONFIRMATION; |
317 { |
301 } |
318 return LabelExtension.STANDARDICON_INFO; |
302 else if (type == AlertType.ALARM) { |
319 } |
303 return LabelExtension.STANDARDICON_ALARM; |
320 else if(type == AlertType.CONFIRMATION) |
304 } |
321 { |
305 else { |
322 return LabelExtension.STANDARDICON_CONFIRMATION; |
|
323 } |
|
324 else if(type == AlertType.ALARM) |
|
325 { |
|
326 return LabelExtension.STANDARDICON_ALARM; |
|
327 } |
|
328 else |
|
329 { |
306 return LabelExtension.STANDARDICON_ALARM; |
330 return LabelExtension.STANDARDICON_ALARM; |
307 } |
331 } |
308 |
332 |
309 } |
333 } |
310 |
334 |
312 * Gets the default Alert text based on the type. |
336 * Gets the default Alert text based on the type. |
313 * |
337 * |
314 * @param type the alert type |
338 * @param type the alert type |
315 * @return the default text based on the type |
339 * @return the default text based on the type |
316 */ |
340 */ |
317 private static String getDefaultText(final AlertType type) { |
341 private static String getDefaultText(final AlertType type) |
318 if (type == AlertType.ERROR) { |
342 { |
|
343 if(type == AlertType.ERROR) |
|
344 { |
319 return MsgRepository.ALERT_DEFAULT_TEXT_ERROR; |
345 return MsgRepository.ALERT_DEFAULT_TEXT_ERROR; |
320 } |
346 } |
321 else if (type == AlertType.WARNING) { |
347 else if(type == AlertType.WARNING) |
|
348 { |
322 return MsgRepository.ALERT_DEFAULT_TEXT_WARNING; |
349 return MsgRepository.ALERT_DEFAULT_TEXT_WARNING; |
323 } |
350 } |
324 else if (type == AlertType.INFO) { |
351 else if(type == AlertType.INFO) |
|
352 { |
325 return MsgRepository.ALERT_DEFAULT_TEXT_INFO; |
353 return MsgRepository.ALERT_DEFAULT_TEXT_INFO; |
326 } |
354 } |
327 else if (type == AlertType.CONFIRMATION) { |
355 else if(type == AlertType.CONFIRMATION) |
|
356 { |
328 return MsgRepository.ALERT_DEFAULT_TEXT_CONFIRMATION; |
357 return MsgRepository.ALERT_DEFAULT_TEXT_CONFIRMATION; |
329 } |
358 } |
330 else if (type == AlertType.ALARM) { |
359 else if(type == AlertType.ALARM) |
|
360 { |
331 return MsgRepository.ALERT_DEFAULT_TEXT_ALARM; |
361 return MsgRepository.ALERT_DEFAULT_TEXT_ALARM; |
332 } |
362 } |
333 else { |
363 else |
|
364 { |
334 return MsgRepository.ALERT_DEFAULT_TEXT_ALERT; |
365 return MsgRepository.ALERT_DEFAULT_TEXT_ALERT; |
335 } |
366 } |
336 } |
367 } |
337 |
368 |
338 /** |
369 /** |
339 * Returns if the Alert is modal. |
370 * Returns if the Alert is modal. |
340 */ |
371 */ |
341 private boolean isModal() { |
372 private boolean isModal() |
|
373 { |
342 return ((timeout == FOREVER) |
374 return ((timeout == FOREVER) |
343 || (getNumCommands() > 1) |
375 || (getNumCommands() > 1) |
344 || isTextScrolling()); |
376 || isTextScrolling()); |
345 } |
377 } |
346 |
378 |
348 * Set the time for the Alert to be shown. |
380 * Set the time for the Alert to be shown. |
349 * |
381 * |
350 * @param timeout the timeout value in milliseconds or FOREVER |
382 * @param timeout the timeout value in milliseconds or FOREVER |
351 * @throws IllegalArgumentException if time is not positive nor FOREVER. |
383 * @throws IllegalArgumentException if time is not positive nor FOREVER. |
352 */ |
384 */ |
353 public void setTimeout(int timeout) { |
385 public void setTimeout(int timeout) |
354 if (timeout > 0 || timeout == FOREVER) { |
386 { |
|
387 if(timeout > 0 || timeout == FOREVER) |
|
388 { |
355 this.timeout = timeout; |
389 this.timeout = timeout; |
356 setCommandsVisibility(isModal()); |
390 setCommandsVisibility(isModal()); |
357 } |
391 } |
358 else { |
392 else |
|
393 { |
359 throw new IllegalArgumentException( |
394 throw new IllegalArgumentException( |
360 MsgRepository.ALERT_EXCEPTION_INVALID_TIMEOUT); |
395 MsgRepository.ALERT_EXCEPTION_INVALID_TIMEOUT); |
361 } |
396 } |
362 } |
397 } |
363 |
398 |
364 /** |
399 /** |
365 * Get the time the Alert is shown. |
400 * Get the time the Alert is shown. |
366 * |
401 * |
367 * @return timeout in milliseconds, or FOREVER |
402 * @return timeout in milliseconds, or FOREVER |
368 */ |
403 */ |
369 public int getTimeout() { |
404 public int getTimeout() |
370 if (isModal()) { |
405 { |
|
406 if(isModal()) |
|
407 { |
371 return FOREVER; |
408 return FOREVER; |
372 } |
409 } |
373 else { |
410 else |
|
411 { |
374 return timeout; |
412 return timeout; |
375 } |
413 } |
376 } |
414 } |
377 |
415 |
378 /** |
416 /** |
379 * Get the default time for showing an Alert. |
417 * Get the default time for showing an Alert. |
380 * |
418 * |
381 * @return default timeout in milliseconds |
419 * @return default timeout in milliseconds |
382 */ |
420 */ |
383 public int getDefaultTimeout() { |
421 public int getDefaultTimeout() |
|
422 { |
384 return Config.ALERT_DEFAULT_TIMEOUT; |
423 return Config.ALERT_DEFAULT_TIMEOUT; |
385 } |
424 } |
386 |
425 |
387 /** |
426 /** |
388 * Sets the type of the Alert. |
427 * Sets the type of the Alert. |
389 * |
428 * |
390 * @param type an AlertType or null if it doesn't have a specific type |
429 * @param type an AlertType or null if it doesn't have a specific type |
391 */ |
430 */ |
392 public void setType(AlertType type) { |
431 public void setType(AlertType type) |
|
432 { |
393 this.type = type; |
433 this.type = type; |
394 if (text == null) { |
434 if(text == null) |
|
435 { |
395 // show default text |
436 // show default text |
396 setString(text); |
437 setString(text); |
397 } |
438 } |
398 if (image == null) { |
439 if(image == null) |
|
440 { |
399 // show default image |
441 // show default image |
400 setImage(image); |
442 setImage(image); |
401 } |
443 } |
402 } |
444 } |
403 |
445 |
404 /** |
446 /** |
405 * Gets the type of the Alert. |
447 * Gets the type of the Alert. |
406 * |
448 * |
407 * @return an AlertType or null if it doesn't have a specific type |
449 * @return an AlertType or null if it doesn't have a specific type |
408 */ |
450 */ |
409 public AlertType getType() { |
451 public AlertType getType() |
|
452 { |
410 return type; |
453 return type; |
411 } |
454 } |
412 |
455 |
413 /** |
456 /** |
414 * Sets the image of this Alert. |
457 * Sets the image of this Alert. |
415 * |
458 * |
416 * @param newImage an Image, or null if there is no image |
459 * @param newImage an Image, or null if there is no image |
417 */ |
460 */ |
418 public void setImage(Image newImage) { |
461 public void setImage(Image newImage) |
|
462 { |
419 image = newImage; |
463 image = newImage; |
420 ESWTUIThreadRunner.syncExec(new Runnable() { |
464 ESWTUIThreadRunner.syncExec(new Runnable() |
421 public void run() { |
465 { |
|
466 public void run() |
|
467 { |
422 Image temp = (image != null) ? image : null; |
468 Image temp = (image != null) ? image : null; |
423 //Get the image size from QT Style for scaling |
469 //Get the image size from QT Style for scaling |
424 int scaleToSize = Style.pixelMetric(Style.QSTYLE_PM_MESSAGEBOXICONSIZE); |
470 int scaleToSize = Style.pixelMetric(Style.QSTYLE_PM_MESSAGEBOXICONSIZE); |
425 |
471 |
426 if (temp != null) { |
472 if(temp != null) |
|
473 { |
427 |
474 |
428 //calculate the aspect ratio |
475 //calculate the aspect ratio |
429 float aspectRatio = (float)temp.getHeight()/temp.getWidth(); |
476 float aspectRatio = (float)temp.getHeight()/temp.getWidth(); |
430 |
477 |
431 //check the image size |
478 //check the image size |
432 if ( ( temp.getWidth() > scaleToSize ) || |
479 if((temp.getWidth() > scaleToSize) || |
433 ( temp.getHeight() > scaleToSize ) ) |
480 (temp.getHeight() > scaleToSize)) |
434 { |
481 { |
435 // we need to scale down the image |
482 // we need to scale down the image |
436 if( temp.getWidth() > scaleToSize ) |
483 if(temp.getWidth() > scaleToSize) |
437 { |
484 { |
438 //Width is greater |
485 //Width is greater |
439 Image wScaled = Image.createImage(temp, |
486 Image wScaled = Image.createImage(temp, |
440 scaleToSize, |
487 scaleToSize, |
441 (int)(scaleToSize*aspectRatio)); |
488 (int)(scaleToSize*aspectRatio)); |
442 |
489 |
443 //now check the new dimension against height |
490 //now check the new dimension against height |
444 if(wScaled.getHeight() > scaleToSize ) |
491 if(wScaled.getHeight() > scaleToSize) |
445 { |
492 { |
446 //scale the image again |
493 //scale the image again |
447 Image whScaled = Image.createImage(temp, |
494 Image whScaled = Image.createImage(temp, |
448 scaleToSize, |
495 scaleToSize, |
449 scaleToSize ); |
496 scaleToSize); |
450 eswtImgLabel.setImage(Image.getESWTImage(whScaled)); |
497 eswtImgLabel.setImage(Image.getESWTImage(whScaled)); |
451 } |
498 } |
452 else { |
499 else |
|
500 { |
453 //height was ok after scaling on width |
501 //height was ok after scaling on width |
454 eswtImgLabel.setImage(Image.getESWTImage(wScaled)); |
502 eswtImgLabel.setImage(Image.getESWTImage(wScaled)); |
455 } |
503 } |
456 } |
504 } |
457 else if( temp.getHeight() > scaleToSize ) |
505 else if(temp.getHeight() > scaleToSize) |
458 { |
506 { |
459 //Height is greater |
507 //Height is greater |
460 Image hScaled = Image.createImage(temp, |
508 Image hScaled = Image.createImage(temp, |
461 (int)(scaleToSize/aspectRatio), |
509 (int)(scaleToSize/aspectRatio), |
462 scaleToSize ); |
510 scaleToSize); |
463 |
511 |
464 //now check the new dimension against width |
512 //now check the new dimension against width |
465 if(hScaled.getWidth()> scaleToSize ) |
513 if(hScaled.getWidth()> scaleToSize) |
466 { |
514 { |
467 //scale the image again |
515 //scale the image again |
468 Image hwScaled = Image.createImage(temp, |
516 Image hwScaled = Image.createImage(temp, |
469 scaleToSize, |
517 scaleToSize, |
470 scaleToSize ); |
518 scaleToSize); |
471 eswtImgLabel.setImage(Image.getESWTImage(hwScaled)); |
519 eswtImgLabel.setImage(Image.getESWTImage(hwScaled)); |
472 } |
520 } |
473 else { |
521 else |
|
522 { |
474 //widh was ok after scaling using height |
523 //widh was ok after scaling using height |
475 eswtImgLabel.setImage(Image.getESWTImage(hScaled)); |
524 eswtImgLabel.setImage(Image.getESWTImage(hScaled)); |
476 } |
525 } |
477 } |
526 } |
478 |
527 |
479 } |
528 } |
480 else { |
529 else |
|
530 { |
481 // image is right size |
531 // image is right size |
482 eswtImgLabel.setImage(Image.getESWTImage(temp)); |
532 eswtImgLabel.setImage(Image.getESWTImage(temp)); |
483 } |
533 } |
484 } |
534 } |
485 else { |
535 else |
|
536 { |
486 // no image |
537 // no image |
487 if(type != null) |
538 if(type != null) |
488 { |
539 { |
489 //display the default image |
540 //display the default image |
490 eswtImgLabel.setStandardIcon(getDefaultImageType(type),scaleToSize,scaleToSize); |
541 eswtImgLabel.setStandardIcon(getDefaultImageType(type),scaleToSize,scaleToSize); |
553 * @param newIndicator the activity indicator for this Alert, or null if |
612 * @param newIndicator the activity indicator for this Alert, or null if |
554 * there is none |
613 * there is none |
555 * @throws IllegalArgumentException if indicator does not meet the |
614 * @throws IllegalArgumentException if indicator does not meet the |
556 * restrictions for its use in an Alert |
615 * restrictions for its use in an Alert |
557 */ |
616 */ |
558 public void setIndicator(Gauge newIndicator) { |
617 public void setIndicator(Gauge newIndicator) |
559 if (newIndicator != null && !newIndicator.isSuitableForAlert()) { |
618 { |
|
619 if(newIndicator != null && !newIndicator.isSuitableForAlert()) |
|
620 { |
560 throw new IllegalArgumentException( |
621 throw new IllegalArgumentException( |
561 MsgRepository.ALERT_EXCEPTION_INVALID_INDICATOR); |
622 MsgRepository.ALERT_EXCEPTION_INVALID_INDICATOR); |
562 } |
623 } |
563 // remove old Gauge parent |
624 // remove old Gauge parent |
564 if (indicator != null) { |
625 if(indicator != null) |
|
626 { |
565 indicator.setParent(null); |
627 indicator.setParent(null); |
566 } |
628 } |
567 // store the indicator |
629 // store the indicator |
568 indicator = newIndicator; |
630 indicator = newIndicator; |
569 // set new Gauge parent |
631 // set new Gauge parent |
570 if (indicator != null) { |
632 if(indicator != null) |
|
633 { |
571 indicator.setParent(this); |
634 indicator.setParent(this); |
572 } |
635 } |
573 updateIndicator(); |
636 updateIndicator(); |
574 } |
637 } |
575 |
638 |
576 /** |
639 /** |
577 * Gets the activity indicator of this Alert. |
640 * Gets the activity indicator of this Alert. |
578 * |
641 * |
579 * @return the activity indicator of this Alert, or null if there is none |
642 * @return the activity indicator of this Alert, or null if there is none |
580 */ |
643 */ |
581 public Gauge getIndicator() { |
644 public Gauge getIndicator() |
|
645 { |
582 return indicator; |
646 return indicator; |
583 } |
647 } |
584 |
648 |
585 /** |
649 /** |
586 * Update indicator if it changed. |
650 * Update indicator if it changed. |
587 */ |
651 */ |
588 void updateIndicator() { |
652 void updateIndicator() |
589 ESWTUIThreadRunner.syncExec(new Runnable() { |
653 { |
590 public void run() { |
654 ESWTUIThreadRunner.syncExec(new Runnable() |
591 if (indicator != null) { |
655 { |
|
656 public void run() |
|
657 { |
|
658 if(indicator != null) |
|
659 { |
592 // show ProgressBar |
660 // show ProgressBar |
593 if (indicator.isIndefinite()) { |
661 if(indicator.isIndefinite()) |
|
662 { |
594 // indefinite ProgressBar |
663 // indefinite ProgressBar |
595 switch (indicator.getValue()) { |
664 switch(indicator.getValue()) |
596 case Gauge.CONTINUOUS_IDLE: |
665 { |
597 case Gauge.INCREMENTAL_IDLE: |
666 case Gauge.CONTINUOUS_IDLE: |
598 // currently these are mapped to full progress bar |
667 case Gauge.INCREMENTAL_IDLE: |
599 // TODO: eSWT support required |
668 // currently these are mapped to full progress bar |
600 eswtUpdateProgressbar(getContentComp(), false, true); |
669 // TODO: eSWT support required |
|
670 eswtUpdateProgressbar(getContentComp(), false, true); |
|
671 eswtSetProgressbarValues(0, 1, 1); |
|
672 break; |
|
673 case Gauge.CONTINUOUS_RUNNING: |
|
674 eswtUpdateProgressbar(getContentComp(), true, true); |
|
675 break; |
|
676 case Gauge.INCREMENTAL_UPDATING: |
|
677 // currently this are mapped to blinking |
|
678 // empty and full progress bar |
|
679 // TODO: eSWT support required |
|
680 eswtUpdateProgressbar(getContentComp(), false, true); |
|
681 if(eswtProgressBar.getSelection() > 0) |
|
682 { |
|
683 eswtSetProgressbarValues(0, 1, 0); |
|
684 } |
|
685 else |
|
686 { |
601 eswtSetProgressbarValues(0, 1, 1); |
687 eswtSetProgressbarValues(0, 1, 1); |
602 break; |
688 } |
603 case Gauge.CONTINUOUS_RUNNING: |
689 break; |
604 eswtUpdateProgressbar(getContentComp(), true, true); |
690 default: |
605 break; |
691 break; |
606 case Gauge.INCREMENTAL_UPDATING: |
|
607 // currently this are mapped to blinking |
|
608 // empty and full progress bar |
|
609 // TODO: eSWT support required |
|
610 eswtUpdateProgressbar(getContentComp(), false, true); |
|
611 if (eswtProgressBar.getSelection() > 0) { |
|
612 eswtSetProgressbarValues(0, 1, 0); |
|
613 } |
|
614 else { |
|
615 eswtSetProgressbarValues(0, 1, 1); |
|
616 } |
|
617 break; |
|
618 default: |
|
619 break; |
|
620 } |
692 } |
621 } |
693 } |
622 else { |
694 else |
|
695 { |
623 // definite ProgressBar |
696 // definite ProgressBar |
624 eswtUpdateProgressbar(getContentComp(), false, true); |
697 eswtUpdateProgressbar(getContentComp(), false, true); |
625 eswtSetProgressbarValues(0, indicator.getMaxValue(), |
698 eswtSetProgressbarValues(0, indicator.getMaxValue(), |
626 indicator.getValue()); |
699 indicator.getValue()); |
627 } |
700 } |
628 } |
701 } |
629 else { |
702 else |
|
703 { |
630 // hide ProgressBar |
704 // hide ProgressBar |
631 eswtUpdateProgressbar(getContentComp(), false, false); |
705 eswtUpdateProgressbar(getContentComp(), false, false); |
632 } |
706 } |
633 eswtSetPreferredContentSize(-1, eswtGetPreferredContentHeight()); |
707 eswtSetPreferredContentSize(-1, eswtGetPreferredContentHeight()); |
634 getContentComp().layout(); |
708 getContentComp().layout(); |
637 } |
711 } |
638 |
712 |
639 /* (non-Javadoc) |
713 /* (non-Javadoc) |
640 * @see Displayable#addCommand(Command) |
714 * @see Displayable#addCommand(Command) |
641 */ |
715 */ |
642 public void addCommand(Command command) { |
716 public void addCommand(Command command) |
643 if (command != DISMISS_COMMAND) { |
717 { |
|
718 if(command != DISMISS_COMMAND) |
|
719 { |
644 super.addCommand(command); |
720 super.addCommand(command); |
645 super.removeCommand(DISMISS_COMMAND); |
721 super.removeCommand(DISMISS_COMMAND); |
646 setCommandsVisibility(isModal()); |
722 setCommandsVisibility(isModal()); |
647 } |
723 } |
648 } |
724 } |
649 |
725 |
650 /* (non-Javadoc) |
726 /* (non-Javadoc) |
651 * @see Displayable#removeCommand(Command) |
727 * @see Displayable#removeCommand(Command) |
652 */ |
728 */ |
653 public void removeCommand(Command command) { |
729 public void removeCommand(Command command) |
654 if (command != DISMISS_COMMAND) { |
730 { |
|
731 if(command != DISMISS_COMMAND) |
|
732 { |
655 super.removeCommand(command); |
733 super.removeCommand(command); |
656 if (getNumCommands() == 0) { |
734 if(getNumCommands() == 0) |
|
735 { |
657 super.addCommand(DISMISS_COMMAND); |
736 super.addCommand(DISMISS_COMMAND); |
658 } |
737 } |
659 setCommandsVisibility(isModal()); |
738 setCommandsVisibility(isModal()); |
660 } |
739 } |
661 } |
740 } |
662 |
741 |
663 /* (non-Javadoc) |
742 /* (non-Javadoc) |
664 * @see Displayable#setCommandListener(CommandListener) |
743 * @see Displayable#setCommandListener(CommandListener) |
665 */ |
744 */ |
666 public void setCommandListener(CommandListener listener) { |
745 public void setCommandListener(CommandListener listener) |
667 if (listener == null) { |
746 { |
|
747 if(listener == null) |
|
748 { |
668 listener = implicitListener; |
749 listener = implicitListener; |
669 } |
750 } |
670 super.setCommandListener(listener); |
751 super.setCommandListener(listener); |
671 } |
752 } |
672 |
753 |
673 void resetTimerTask(boolean reset) { |
754 void resetTimerTask(boolean reset) |
674 if (timerTask != null) { |
755 { |
|
756 if(timerTask != null) |
|
757 { |
675 timerTask.cancel(); |
758 timerTask.cancel(); |
676 timerTask = null; |
759 timerTask = null; |
677 } |
760 } |
678 if (reset && !isModal()) { |
761 if(reset && !isModal()) |
|
762 { |
679 // if not modal schedule new timer |
763 // if not modal schedule new timer |
680 timerTask = new AlertTimerTask(); |
764 timerTask = new AlertTimerTask(); |
681 timer.schedule(timerTask, timeout); |
765 timer.schedule(timerTask, timeout); |
682 } |
766 } |
683 } |
767 } |
684 |
768 |
685 /** |
769 /** |
686 * Alert Timer task. Triggers the first command on the Alert. |
770 * Alert Timer task. Triggers the first command on the Alert. |
687 */ |
771 */ |
688 class AlertTimerTask extends TimerTask { |
772 class AlertTimerTask extends TimerTask |
689 |
773 { |
690 public void run() { |
774 |
|
775 public void run() |
|
776 { |
691 // trigger the first available command on the listener |
777 // trigger the first available command on the listener |
692 if (!isModal()) { |
778 if(!isModal()) |
|
779 { |
693 callCommandAction(getCommand(0)); |
780 callCommandAction(getCommand(0)); |
694 } |
781 } |
695 } |
782 } |
696 |
783 |
697 } |
784 } |
698 |
785 |
699 /** |
786 /** |
700 * Default (implicit) command listener. Any Commands close the Alert. |
787 * Default (implicit) command listener. Any Commands close the Alert. |
701 */ |
788 */ |
702 class AlertCommandListener implements CommandListener { |
789 class AlertCommandListener implements CommandListener |
703 |
790 { |
704 public void commandAction(Command aCommand, Displayable aSource) { |
791 |
|
792 public void commandAction(Command aCommand, Displayable aSource) |
|
793 { |
705 final Alert alert = (Alert) aSource; |
794 final Alert alert = (Alert) aSource; |
706 Display.getDisplay().setCurrent(alert.nextDisplayable); |
795 Display.getDisplay().setCurrent(alert.nextDisplayable); |
707 } |
796 } |
708 |
797 |
709 } |
798 } |
710 |
799 |
711 /** |
800 /** |
712 * Key listener. Also handles scrolling of text composite. |
801 * Key listener. Also handles scrolling of text composite. |
713 */ |
802 */ |
714 class KeyListener implements Listener { |
803 class KeyListener implements Listener |
715 |
804 { |
716 public void handleEvent(Event e) { |
805 |
717 if (e.type == SWT.Traverse) { |
806 public void handleEvent(Event e) |
|
807 { |
|
808 if(e.type == SWT.Traverse) |
|
809 { |
718 e.doit = false; |
810 e.doit = false; |
719 } |
811 } |
720 else if (e.type == SWT.KeyDown) { |
812 else if(e.type == SWT.KeyDown) |
721 if (!isModal()) { |
813 { |
|
814 if(!isModal()) |
|
815 { |
722 resetTimerTask(false); |
816 resetTimerTask(false); |
723 callCommandAction(getCommand(0)); |
817 callCommandAction(getCommand(0)); |
724 } |
818 } |
725 else if (e.keyCode == SWT.ARROW_DOWN) { |
819 else if(e.keyCode == SWT.ARROW_DOWN) |
|
820 { |
726 Point p = eswtScrolledText.getOrigin(); |
821 Point p = eswtScrolledText.getOrigin(); |
727 eswtScrolledText.setOrigin(p.x, p.y |
822 eswtScrolledText.setOrigin(p.x, p.y |
728 + Config.ALERT_TEXT_SCROLLING_DELTA); |
823 + Config.ALERT_TEXT_SCROLLING_DELTA); |
729 } |
824 } |
730 else if (e.keyCode == SWT.ARROW_UP) { |
825 else if(e.keyCode == SWT.ARROW_UP) |
|
826 { |
731 Point p = eswtScrolledText.getOrigin(); |
827 Point p = eswtScrolledText.getOrigin(); |
732 eswtScrolledText.setOrigin(p.x, p.y |
828 eswtScrolledText.setOrigin(p.x, p.y |
733 - Config.ALERT_TEXT_SCROLLING_DELTA); |
829 - Config.ALERT_TEXT_SCROLLING_DELTA); |
734 } |
830 } |
735 } |
831 } |
736 else if (e.type == SWT.MouseUp) { |
832 else if(e.type == SWT.MouseUp) |
737 if (!isModal()) { |
833 { |
|
834 if(!isModal()) |
|
835 { |
738 resetTimerTask(false); |
836 resetTimerTask(false); |
739 callCommandAction(getCommand(0)); |
837 callCommandAction(getCommand(0)); |
740 } |
838 } |
741 } |
839 } |
742 } |
840 } |