Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.gwt.i18n.client.NumberFormat;
- import com.google.gwt.user.client.DOM;
- import com.google.gwt.user.client.Element;
- import com.google.gwt.user.client.ui.Widget;
- public class ProgressBar extends Widget {
- private static final String PERCENT_PATTERN = "#,##0%";
- private static final NumberFormat percentFormat = NumberFormat.getFormat(PERCENT_PATTERN);
- private final Element progress;
- private final Element percentageLabel;
- private double percentage;
- private final double max;
- public ProgressBar(double value, double max) {
- assert max != 0;
- this.max = max;
- progress = DOM.createElement("progress");
- progress.setAttribute("max", Double.toString(max));
- progress.setAttribute("value", Double.toString(value));
- percentageLabel = DOM.createElement("span");
- percentage = value / max;
- percentageLabel.setInnerHTML(percentFormat.format(percentage));
- progress.insertFirst(percentageLabel);
- setElement(progress);
- }
- public void setProgress(double value) {
- progress.setAttribute("value", Double.toString(value));
- percentage = value / max;
- percentageLabel.setInnerHTML(percentFormat.format(percentage));
- }
- }
- <progress id="bar" value="0" max="100">
- <span id="fallback">
- <p>Your browser does not support progress tag.</p>
- </span>
- </progress>
- <script>
- window.onload = function() {
- var bar = document.getElementById("bar"),
- loaded = 0;
- var load = function() {
- loaded += 10;
- bar.value = loaded;
- if(loaded == 100) {
- clearInterval(dummyLoad);
- }
- };
- var dummyLoad = setInterval(function() {
- load();
- } ,1000);
- }
- </script>
- <progress ui:field="loadingProgress" style="width:100%" value="0" max="100"></progress>
- @UiField Element loadingProgress;
- loadingProgress.setPropertyInt("value", 50);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement