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