接口 ProgressIndicator


public interface ProgressIndicator
An object accompanying a computation, usually in a background thread. It allows to display process status to the user (setText(java.lang.String), setText2(java.lang.String), setFraction(double), setIndeterminate(boolean)) and interrupt if the computation is canceled (#checkCanceled()).

There are many implementations which may implement only parts of the functionality in this interface. Some indicators are invisible, not showing any status to the user, but still tracking cancellation.

To run a task with a visible progress indicator, modal or displayed in the status bar, please use ProgressManager#run methods.

To associate a thread with a progress, use ProgressManager#runProcess methods. This is mostly used with invisible progress indicators for cancellation handling. A common case is to take a read action that's interrupted by a write action about to occur in the UI thread, to avoid UI freezes (see fleet.com.intellij.openapi.application.ReadAction#nonBlocking(Runnable)). Another common case is wrapping main thread's to parallelize the associated computation by forking additional threads.

Current thread's progress indicator, visible or not, can be retrieved with ProgressManager#getGlobalProgressIndicator().

Here are some commonly used implementations:

  • EmptyProgressIndicator: invisible (ignores text/fraction-related methods), used only for cancellation tracking. Remembers its creation modality state.
  • fleet.com.intellij.openapi.progress.util.ProgressIndicatorBase: invisible, but can be made visible by subclassing: remembers text/fraction inside and allows to retrieve them and possibly show in the UI. Non-modal by default.
  • fleet.com.intellij.openapi.progress.util.ProgressWindow: visible progress, either modal or background. Usually not created directly, instantiated internally inside ProgressManager#run.
  • fleet.com.intellij.openapi.progress.util.ProgressWrapper: wraps an existing progress indicator, usually to fork another thread with the same cancellation policy. Use fleet.com.intellij.concurrency.SensitiveProgressWrapper to allow that separate thread's indicator to be canceled independently from the main thread.
  • 方法概要

    修饰符和类型
    方法
    说明
    void
    Cancels the current process.
    default void
    已过时。
    double
     
     
     
    boolean
     
    boolean
     
    boolean
     
    boolean
    Usually invoked in the thread associated with this indicator, used to check if the computation performed by this thread has been canceled, and, if yes, stop it immediately (by throwing an exception).
    boolean
     
    boolean
     
    void
     
    void
     
    void
    setFraction(double fraction)
    Sets the fraction: a number between 0.0 and 1.0 reflecting the ratio of work that has already be done (0.0 for nothing, 1.0 for all).
    void
    setIndeterminate(boolean indeterminate)
    Marks the progress indeterminate (for processes that can't estimate the amount of work to be done) or determinate (for processes that can display the fraction of the work done using setFraction(double)).
    void
    setModalityProgress(@Nullable ProgressIndicator modalityProgress)
    In many implementations, grants to this progress indicator its own modality state.
    void
    Sets text above the progress bar
    void
    Sets text under the progress bar
    void
    Marks the process as started.
    default void
    已过时。
    void
    Marks the process as finished.
  • 方法详细资料

    • start

      void start()
      Marks the process as started. Invoked by ProgressManager internals, shouldn't be called from client code unless you know what you're doing.
    • stop

      void stop()
      Marks the process as finished. Invoked by ProgressManager internals, shouldn't be called from client code unless you know what you're doing.
    • isRunning

      boolean isRunning()
      返回:
      whether the computation associated with this progress indicator is currently running: started, not yet finished, but possibly already canceled.
    • cancel

      void cancel()
      Cancels the current process. Is usually invoked not by the process itself, but by some external activity: e.g. a handler for a "Cancel" button pressed by the user (for visible processes), or by some other event handler which recognizes that the process makes no sense.
    • isCanceled

      boolean isCanceled()
      返回:
      whether the process has been canceled. Usually #checkCanceled() is called instead.
      另请参阅:
    • setText

      void setText(String text)
      Sets text above the progress bar
      参数:
      text - Text to set
      另请参阅:
    • getText

      String getText()
      返回:
      text above the progress bar, set by setText(String)
    • setText2

      void setText2(String text)
      Sets text under the progress bar
      参数:
      text - Text to set
      另请参阅:
    • getText2

      String getText2()
      返回:
      text under the progress bar, set by setText2(String)
    • getFraction

      double getFraction()
      返回:
      current fraction, set by setFraction(double)
    • setFraction

      void setFraction(double fraction)
      Sets the fraction: a number between 0.0 and 1.0 reflecting the ratio of work that has already be done (0.0 for nothing, 1.0 for all). Only works for determinate indicator. The fraction should provide the user with rough estimation of the time left. If that's impossible, consider making the progress indeterminate.
      另请参阅:
    • pushState

      void pushState()
    • popState

      void popState()
    • startNonCancelableSection

      @Deprecated default void startNonCancelableSection()
      已过时。
      use ProgressManager#executeNonCancelableSection(Runnable) instead
    • finishNonCancelableSection

      @Deprecated default void finishNonCancelableSection()
      已过时。
      use ProgressManager#executeNonCancelableSection(Runnable) instead
    • isModal

      boolean isModal()
      返回:
      whether this process blocks user activities while active, probably displaying a modal dialog.
      另请参阅:
    • setModalityProgress

      void setModalityProgress(@Nullable @Nullable ProgressIndicator modalityProgress)
      In many implementations, grants to this progress indicator its own modality state. Don't call unless you know what you're doing. Passing a non-null value can make this indicator modal (as in isModal(), which, if not accompanied by showing a modal dialog, might affect the whole IDE adversely: e.g. actions won't be executed, editor typing won't work, and all that with no visible indication.
    • isIndeterminate

      boolean isIndeterminate()
      返回:
      whether the progress is indeterminate and displays no fractions
    • setIndeterminate

      void setIndeterminate(boolean indeterminate)
      Marks the progress indeterminate (for processes that can't estimate the amount of work to be done) or determinate (for processes that can display the fraction of the work done using setFraction(double)).
    • isPopupWasShown

      boolean isPopupWasShown()
      Usually invoked in the thread associated with this indicator, used to check if the computation performed by this thread has been canceled, and, if yes, stop it immediately (by throwing an exception). Threads should call this frequently to allow for prompt cancellation. Failure to do this can cause UI freezes.

      You might also want to use ProgressManager.checkCanceled() where you don't need to know current indicator and pass it around.
      抛出:
      ProcessCanceledException - if this progress has been canceled, i.e. isCanceled() returns true.
    • isShowing

      boolean isShowing()