Class AbstractProgressMonitor
- java.lang.Object
-
- org.openstreetmap.josm.gui.progress.AbstractProgressMonitor
-
- All Implemented Interfaces:
ProgressMonitor
- Direct Known Subclasses:
ChildProgress,CLIProgressMonitor,PleaseWaitProgressMonitor,SwingRenderingProgressMonitor
public abstract class AbstractProgressMonitor extends java.lang.Object implements ProgressMonitor
This class contains the progress logic required to implement aProgressMonitor.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classAbstractProgressMonitor.Requeststatic classAbstractProgressMonitor.StateProgress monitor state-
Nested classes/interfaces inherited from interface org.openstreetmap.josm.gui.progress.ProgressMonitor
ProgressMonitor.CancelListener
-
-
Field Summary
Fields Modifier and Type Field Description private CancelHandlercancelHandlerprivate intchildTicksprivate AbstractProgressMonitorcurrentChildprivate java.lang.StringcustomTextprivate java.lang.StringextraTextprivate booleanintermediateTaskprivate AbstractProgressMonitor.RequestrequestedStateprivate java.util.Queue<AbstractProgressMonitor.Request>requestsprivate java.lang.StringshownCustomTextprivate java.lang.StringshownTitleprotected AbstractProgressMonitor.Statestateprivate java.lang.StringtaskTitleprivate intticksprivate intticksCount-
Fields inherited from interface org.openstreetmap.josm.gui.progress.ProgressMonitor
ALL_TICKS, DEFAULT_TICKS
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractProgressMonitor(CancelHandler cancelHandler)Create a newAbstractProgressMonitor
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddCancelListener(ProgressMonitor.CancelListener listener)Add listener for user abort actionvoidappendLogMessage(java.lang.String message)Default implementation is empty.private voidapplyChildRequest(AbstractProgressMonitor.Request request)private voidapplyThisRequest(AbstractProgressMonitor.Request request)voidbeginTask(java.lang.String title)Starts this progress monitor.voidbeginTask(java.lang.String title, int ticks)Starts this progress monitor.voidcancel()Abort current operation, usually called when user somehow requested an abortprotected voidcheckState(AbstractProgressMonitor.State... expectedStates)protected voidchildFinished(AbstractProgressMonitor child)protected voidchildSetCustomText(AbstractProgressMonitor child, java.lang.String customText)protected voidchildSetIntermediate(AbstractProgressMonitor child, boolean value)protected voidchildSetProgress(AbstractProgressMonitor child, double value)protected voidchildSetTitle(AbstractProgressMonitor child, java.lang.String title)ProgressMonitorcreateSubTaskMonitor(int ticks, boolean internal)Creates subtasks monitor.protected abstract voiddoBeginTask()protected abstract voiddoFinishTask()protected abstract voiddoSetCustomText(java.lang.String title)protected abstract voiddoSetIntermediate(boolean value)protected abstract voiddoSetTitle(java.lang.String title)voidfinishTask()Finish this progress monitor, close the dialog or inform the parent progress monitor that it can continue with other tasks.private AbstractProgressMonitor.RequestgetRequest(AbstractProgressMonitor child)intgetTicks()Get the current number of work unitsintgetTicksCount()Get the total number of work unitsvoidindeterminateSubTask(java.lang.String title)Subtask that will show progress running back and forthprivate voidinternalUpdateProgress(double childProgress)voidinvalidate()Can be used if method receives ProgressMonitor, but it's not interested progress monitoring.booleanisCanceled()Returns the state of user abortsvoidremoveCancelListener(ProgressMonitor.CancelListener listener)Remove listener for user abort actionprivate voidresetState()voidsetCustomText(java.lang.String text)Shows additional textvoidsetExtraText(java.lang.String text)Show extra text after normal task title.voidsetTicks(int ticks)Set the current number of work unitsvoidsetTicksCount(int ticks)Set the total number of work unitsvoidsubTask(java.lang.String title)Normal subtaskprotected abstract voidupdateProgress(double value)Update progress messagevoidworked(int ticks)Increase number of already done work units by ticks-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openstreetmap.josm.gui.progress.ProgressMonitor
getProgressTaskId, getWindowParent, setProgressTaskId
-
-
-
-
Field Detail
-
cancelHandler
private final CancelHandler cancelHandler
-
state
protected AbstractProgressMonitor.State state
-
ticksCount
private int ticksCount
-
ticks
private int ticks
-
childTicks
private int childTicks
-
taskTitle
private java.lang.String taskTitle
-
customText
private java.lang.String customText
-
extraText
private java.lang.String extraText
-
shownTitle
private java.lang.String shownTitle
-
shownCustomText
private java.lang.String shownCustomText
-
intermediateTask
private boolean intermediateTask
-
requests
private final java.util.Queue<AbstractProgressMonitor.Request> requests
-
currentChild
private AbstractProgressMonitor currentChild
-
requestedState
private AbstractProgressMonitor.Request requestedState
-
-
Constructor Detail
-
AbstractProgressMonitor
protected AbstractProgressMonitor(CancelHandler cancelHandler)
Create a newAbstractProgressMonitor- Parameters:
cancelHandler- The handler that gets notified when the process is canceled.
-
-
Method Detail
-
doBeginTask
protected abstract void doBeginTask()
-
doFinishTask
protected abstract void doFinishTask()
-
doSetIntermediate
protected abstract void doSetIntermediate(boolean value)
-
doSetTitle
protected abstract void doSetTitle(java.lang.String title)
-
doSetCustomText
protected abstract void doSetCustomText(java.lang.String title)
-
checkState
protected void checkState(AbstractProgressMonitor.State... expectedStates)
-
beginTask
public void beginTask(java.lang.String title)
Description copied from interface:ProgressMonitorStarts this progress monitor. Must be called exactly once Ticks count is set to default value- Specified by:
beginTaskin interfaceProgressMonitor- Parameters:
title- title text of the task
-
beginTask
public void beginTask(java.lang.String title, int ticks)
Description copied from interface:ProgressMonitorStarts this progress monitor. Must be called exactly once- Specified by:
beginTaskin interfaceProgressMonitor- Parameters:
title- title text of the taskticks- number of work units (seeProgressMonitor.setTicksCount(int ticks))
-
finishTask
public void finishTask()
Description copied from interface:ProgressMonitorFinish this progress monitor, close the dialog or inform the parent progress monitor that it can continue with other tasks. Must be called at least once (if called multiply times then further calls are ignored)- Specified by:
finishTaskin interfaceProgressMonitor
-
invalidate
public void invalidate()
Description copied from interface:ProgressMonitorCan be used if method receives ProgressMonitor, but it's not interested progress monitoring. Basically replacesProgressMonitor.beginTask(String)andProgressMonitor.finishTask()This method can be also used in finally section if method expects that some exceptions might prevent it from passing progressMonitor away. IfProgressMonitor.beginTask(String)was already called then this method does nothing.- Specified by:
invalidatein interfaceProgressMonitor
-
subTask
public void subTask(java.lang.String title)
Description copied from interface:ProgressMonitorNormal subtask- Specified by:
subTaskin interfaceProgressMonitor- Parameters:
title- Can benull, in that case task title is not changed
-
indeterminateSubTask
public void indeterminateSubTask(java.lang.String title)
Description copied from interface:ProgressMonitorSubtask that will show progress running back and forth- Specified by:
indeterminateSubTaskin interfaceProgressMonitor- Parameters:
title- Can benull, in that case task title is not changed
-
setCustomText
public void setCustomText(java.lang.String text)
Description copied from interface:ProgressMonitorShows additional text- Specified by:
setCustomTextin interfaceProgressMonitor- Parameters:
text- custom text
-
setExtraText
public void setExtraText(java.lang.String text)
Description copied from interface:ProgressMonitorShow extra text after normal task title. Hack for ProgressInputStream to show number of kB already downloaded- Specified by:
setExtraTextin interfaceProgressMonitor- Parameters:
text- extra text
-
appendLogMessage
public void appendLogMessage(java.lang.String message)
Default implementation is empty. Override in subclasses to display the log messages.- Specified by:
appendLogMessagein interfaceProgressMonitor- Parameters:
message- the log message. Ignored if null or white space only.
-
resetState
private void resetState()
-
cancel
public void cancel()
Description copied from interface:ProgressMonitorAbort current operation, usually called when user somehow requested an abort- Specified by:
cancelin interfaceProgressMonitor
-
isCanceled
public boolean isCanceled()
Description copied from interface:ProgressMonitorReturns the state of user aborts- Specified by:
isCanceledin interfaceProgressMonitor- Returns:
trueif user aborted operation
-
addCancelListener
public void addCancelListener(ProgressMonitor.CancelListener listener)
Description copied from interface:ProgressMonitorAdd listener for user abort action- Specified by:
addCancelListenerin interfaceProgressMonitor- Parameters:
listener- the listener for cancel operation
-
removeCancelListener
public void removeCancelListener(ProgressMonitor.CancelListener listener)
Description copied from interface:ProgressMonitorRemove listener for user abort action- Specified by:
removeCancelListenerin interfaceProgressMonitor- Parameters:
listener- the listener for cancel operation
-
updateProgress
protected abstract void updateProgress(double value)
Update progress message- Parameters:
value- The percentage of completion (this and child progress)
-
setTicks
public void setTicks(int ticks)
Description copied from interface:ProgressMonitorSet the current number of work units- Specified by:
setTicksin interfaceProgressMonitor- Parameters:
ticks- Number of work units already done
-
setTicksCount
public void setTicksCount(int ticks)
Description copied from interface:ProgressMonitorSet the total number of work units- Specified by:
setTicksCountin interfaceProgressMonitor- Parameters:
ticks- Number of total work units
-
worked
public void worked(int ticks)
Description copied from interface:ProgressMonitorIncrease number of already done work units by ticks- Specified by:
workedin interfaceProgressMonitor- Parameters:
ticks- number of ticks to add
-
internalUpdateProgress
private void internalUpdateProgress(double childProgress)
-
getTicks
public int getTicks()
Description copied from interface:ProgressMonitorGet the current number of work units- Specified by:
getTicksin interfaceProgressMonitor- Returns:
- Number of work units already done
-
getTicksCount
public int getTicksCount()
Description copied from interface:ProgressMonitorGet the total number of work units- Specified by:
getTicksCountin interfaceProgressMonitor- Returns:
- Number of total work units
-
createSubTaskMonitor
public ProgressMonitor createSubTaskMonitor(int ticks, boolean internal)
Description copied from interface:ProgressMonitorCreates subtasks monitor.- Specified by:
createSubTaskMonitorin interfaceProgressMonitor- Parameters:
ticks- Number of work units that should be done when subtask finishesinternal- If true then subtask can't modify task title/custom text- Returns:
- subtasks monitor
-
applyChildRequest
private void applyChildRequest(AbstractProgressMonitor.Request request)
-
applyThisRequest
private void applyThisRequest(AbstractProgressMonitor.Request request)
-
childFinished
protected void childFinished(AbstractProgressMonitor child)
-
getRequest
private AbstractProgressMonitor.Request getRequest(AbstractProgressMonitor child)
-
childSetProgress
protected void childSetProgress(AbstractProgressMonitor child, double value)
-
childSetTitle
protected void childSetTitle(AbstractProgressMonitor child, java.lang.String title)
-
childSetCustomText
protected void childSetCustomText(AbstractProgressMonitor child, java.lang.String customText)
-
childSetIntermediate
protected void childSetIntermediate(AbstractProgressMonitor child, boolean value)
-
-