Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. import com.google.gwt.i18n.client.NumberFormat;
  2. import com.google.gwt.user.client.DOM;
  3. import com.google.gwt.user.client.Element;
  4. import com.google.gwt.user.client.ui.Widget;
  5.  
  6. public class ProgressBar extends Widget {
  7. private static final String PERCENT_PATTERN = "#,##0%";
  8. private static final NumberFormat percentFormat = NumberFormat.getFormat(PERCENT_PATTERN);
  9.  
  10. private final Element progress;
  11. private final Element percentageLabel;
  12. private double percentage;
  13. private final double max;
  14.  
  15. public ProgressBar(double value, double max) {
  16. assert max != 0;
  17. this.max = max;
  18.  
  19. progress = DOM.createElement("progress");
  20. progress.setAttribute("max", Double.toString(max));
  21. progress.setAttribute("value", Double.toString(value));
  22.  
  23. percentageLabel = DOM.createElement("span");
  24. percentage = value / max;
  25. percentageLabel.setInnerHTML(percentFormat.format(percentage));
  26. progress.insertFirst(percentageLabel);
  27.  
  28. setElement(progress);
  29. }
  30.  
  31. public void setProgress(double value) {
  32. progress.setAttribute("value", Double.toString(value));
  33. percentage = value / max;
  34. percentageLabel.setInnerHTML(percentFormat.format(percentage));
  35. }
  36.  
  37. }
  38.  
  39. <progress id="bar" value="0" max="100">
  40. <span id="fallback">
  41. <p>Your browser does not support progress tag.</p>
  42. </span>
  43. </progress>
  44.  
  45. <script>
  46. window.onload = function() {
  47.  
  48. var bar = document.getElementById("bar"),
  49. loaded = 0;
  50.  
  51. var load = function() {
  52. loaded += 10;
  53. bar.value = loaded;
  54.  
  55. if(loaded == 100) {
  56. clearInterval(dummyLoad);
  57. }
  58. };
  59.  
  60. var dummyLoad = setInterval(function() {
  61. load();
  62. } ,1000);
  63. }
  64. </script>
  65.  
  66. <progress ui:field="loadingProgress" style="width:100%" value="0" max="100"></progress>
  67.  
  68. @UiField Element loadingProgress;
  69.  
  70. loadingProgress.setPropertyInt("value", 50);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement