001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.gui.progress;
003
004import java.awt.Component;
005
006/**
007 * The progress of a sub task
008 */
009public class ChildProgress extends AbstractProgressMonitor {
010
011    private final AbstractProgressMonitor parent;
012    private final boolean internal;
013
014    /**
015     * Creates a new {@link ChildProgress}
016     * @param parent The parent task that creates this progress
017     * @param cancelHandler The cancel handler to notify when this task is canceled
018     * @param internal this is an internal task that will not modify the text that is displayed to the user
019     */
020    public ChildProgress(AbstractProgressMonitor parent, CancelHandler cancelHandler, boolean internal) {
021        super(cancelHandler);
022        this.parent = parent;
023        this.internal = internal;
024    }
025
026    /**
027     * Gets the parent task
028     * @return The parent task
029     */
030    public final AbstractProgressMonitor getParent() {
031        return parent;
032    }
033
034    /**
035     * See if this is an internal task
036     * @return True if this task should not modify the text that is displayed to the user
037     */
038    public final boolean isInternal() {
039        return internal;
040    }
041
042    @Override
043    protected void updateProgress(double value) {
044        parent.childSetProgress(this, value);
045    }
046
047    @Override
048    protected void doBeginTask() {
049        // Do nothing
050    }
051
052    @Override
053    protected void doSetCustomText(String title) {
054        if (!internal) {
055            parent.childSetCustomText(this, title);
056        }
057    }
058
059    @Override
060    protected void doSetTitle(String title) {
061        if (!internal) {
062            parent.childSetTitle(this, title);
063        }
064    }
065
066    @Override
067    protected void doSetIntermediate(boolean value) {
068        if (!internal) {
069            parent.childSetIntermediate(this, value);
070        }
071    }
072
073    @Override
074    protected void doFinishTask() {
075        parent.childFinished(this);
076    }
077
078    @Override
079    public void setProgressTaskId(ProgressTaskId taskId) {
080        parent.setProgressTaskId(taskId);
081    }
082
083    @Override
084    public ProgressTaskId getProgressTaskId() {
085        return parent.getProgressTaskId();
086    }
087
088    @Override
089    public Component getWindowParent() {
090        return parent.getWindowParent();
091    }
092}