Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

progress bar for GWT

Tags:

gwt

Is there a progress bar widget that I can use with GWT or do I have to make it myself? I've tried to use the progress bars in google-web-toolkit-incubator, gwtupload and upload4gwt without any luck.

like image 803
eggbert Avatar asked Dec 28 '22 05:12

eggbert


2 Answers

I don't know your requirements but HTML5 supports a progressbar tag. Here is a simple example:

Here is the html:

<progress id="bar" value="0" max="100">
    <span id="fallback">
        <p>Your browser does not support progress tag.</p>
    </span>
</progress>

and the script to see how it loads

<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>

Additional information: http://www.w3.org/wiki/HTML/Elements/progress Source: http://www.onlywebpro.com/2011/09/09/html5-progress-bar/

like image 32
Stefan Avatar answered Jan 02 '23 16:01

Stefan


Some code:

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));
    }

}
like image 132
Italo Borssatto Avatar answered Jan 02 '23 14:01

Italo Borssatto