
org.eclipse.jface.dialogs.ProgressIndicator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jface Show documentation
Show all versions of jface Show documentation
JFace is a UI toolkit with classes for handling many common UI programming tasks. JFace is window-system-independent in both its API and implementation, and is designed to work with SWT without hiding it. JFace includes the usual UI toolkit components of image and font registries, text, dialog, preference and wizard frameworks, and progress reporting for long running operations. Two of its more interesting features are actions and viewers. The action mechanism allows user commands to be defined independently from their exact whereabouts in the UI. Viewers are model based adapters for certain SWT widgets, simplifying the presentation of application data structured as lists, tables or trees.
The newest version!
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.jface.dialogs;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.ProgressBar;
/**
* A control for showing progress feedback for a long running operation. This
* control supports both determinate and indeterminate SWT progress bars. For
* indeterminate progress, we don't have to know the total amount of work in
* advance and no worked
method needs to be called.
*/
public class ProgressIndicator extends Composite {
private final static int PROGRESS_MAX = 1000; // value to use for max in
// progress bar
private boolean animated = true;
private StackLayout layout;
private ProgressBar determinateProgressBar;
private ProgressBar indeterminateProgressBar;
private double totalWork;
private double sumWorked;
/**
* Create a ProgressIndicator as a child under the given parent.
*
* @param parent
* The widgets parent
*/
public ProgressIndicator(Composite parent) {
super(parent, SWT.NULL);
determinateProgressBar = new ProgressBar(this, SWT.HORIZONTAL);
indeterminateProgressBar = new ProgressBar(this, SWT.HORIZONTAL
| SWT.INDETERMINATE);
layout = new StackLayout();
setLayout(layout);
}
/**
* Initialize the progress bar to be animated.
*/
public void beginAnimatedTask() {
done();
layout.topControl = indeterminateProgressBar;
layout();
animated = true;
}
/**
* Initialize the progress bar.
*
* @param max
* The maximum value.
*/
public void beginTask(int max) {
done();
this.totalWork = max;
this.sumWorked = 0;
determinateProgressBar.setMinimum(0);
determinateProgressBar.setMaximum(PROGRESS_MAX);
determinateProgressBar.setSelection(0);
layout.topControl = determinateProgressBar;
layout();
animated = false;
}
/**
* Progress is done.
*/
public void done() {
if (!animated) {
determinateProgressBar.setMinimum(0);
determinateProgressBar.setMaximum(0);
determinateProgressBar.setSelection(0);
}
layout.topControl = null;
layout();
}
/**
* Moves the progress indicator to the end.
*/
public void sendRemainingWork() {
worked(totalWork - sumWorked);
}
/**
* Moves the progress indicator by the given amount of work units
* @param work the amount of work to increment by.
*/
public void worked(double work) {
if (work == 0 || animated) {
return;
}
sumWorked += work;
if (sumWorked > totalWork) {
sumWorked = totalWork;
}
if (sumWorked < 0) {
sumWorked = 0;
}
int value = (int) (sumWorked / totalWork * PROGRESS_MAX);
if (determinateProgressBar.getSelection() < value) {
determinateProgressBar.setSelection(value);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy