Search in sources :

Example 61 with Button

use of org.apache.pivot.wtk.Button in project pivot by apache.

the class Meters method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    meter = (Meter) namespace.get("meter");
    progressButton = (PushButton) namespace.get("progressButton");
    progressButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            if (sampleTask == null) {
                // Create and start the simulated task; wrap it in a
                // task adapter so the result handlers are called on the
                // UI thread
                sampleTask = new SampleTask();
                sampleTask.execute(new TaskAdapter<>(new TaskListener<Void>() {

                    @Override
                    public void taskExecuted(Task<Void> task) {
                        reset();
                    }

                    @Override
                    public void executeFailed(Task<Void> task) {
                        reset();
                    }

                    private void reset() {
                        // Reset the meter and button
                        sampleTask = null;
                        meter.setPercentage(0);
                        updateProgressButton();
                    }
                }));
            } else {
                // Cancel the task
                sampleTask.abort();
            }
            updateProgressButton();
        }
    });
    updateProgressButton();
}
Also used : ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TaskAdapter(org.apache.pivot.wtk.TaskAdapter)

Aggregations

Button (org.apache.pivot.wtk.Button)61 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)43 PushButton (org.apache.pivot.wtk.PushButton)40 Component (org.apache.pivot.wtk.Component)15 ListButton (org.apache.pivot.wtk.ListButton)12 IOException (java.io.IOException)11 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)11 File (java.io.File)9 BoxPane (org.apache.pivot.wtk.BoxPane)9 Sheet (org.apache.pivot.wtk.Sheet)9 ListView (org.apache.pivot.wtk.ListView)8 SheetCloseListener (org.apache.pivot.wtk.SheetCloseListener)8 ButtonStateListener (org.apache.pivot.wtk.ButtonStateListener)7 List (org.apache.pivot.collections.List)6 Sequence (org.apache.pivot.collections.Sequence)6 FileBrowserSheet (org.apache.pivot.wtk.FileBrowserSheet)6 Point (org.apache.pivot.wtk.Point)6 Span (org.apache.pivot.wtk.Span)6 GradientPaint (java.awt.GradientPaint)5 SerializationException (org.apache.pivot.serialization.SerializationException)5