Changeset 15415 for branches/EnhancedProgress/HeuristicLab.MainForm
- Timestamp:
- 10/10/17 14:30:37 (7 years ago)
- Location:
- branches/EnhancedProgress/HeuristicLab.MainForm/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs
r15400 r15415 24 24 25 25 namespace HeuristicLab.MainForm { 26 public enum ProgressState { Started = 1, Canceled = 2, Finished = 3 }; 26 public enum ProgressState { Started, Finished, Stopped, Canceled } 27 public enum ProgressBarMode { Continuous, Marquee } 27 28 28 29 public interface IProgress : IContent { 30 ProgressState ProgressState { get; } 31 string Message { get; set; } 32 ProgressBarMode ProgressBarMode { get; set; } 29 33 /// <summary> 30 /// Gets or sets the currently associated status text with the progress. 31 /// </summary> 32 string Status { get; set; } 33 /// <summary> 34 /// Gets or sets the currently associated progress value in the range (0;1]. 35 /// Values outside this range are permitted and need to be handled in some feasible manner. 34 /// Gets or sets the currently associated progress value in the range [0;1] (values outside the range are truncated). 35 /// Changing the ProgressValue when ProgressBarMode is Marquee raises an Exception. 36 36 /// </summary> 37 37 double ProgressValue { get; set; } 38 /// <summary> 39 /// Gets or sets the current state of the progress. Every progress starts in state 40 /// Started and then becomes either Canceled or Finished. 41 /// If it is reused it may be Started again. 42 /// </summary> 43 ProgressState ProgressState { get; } 44 /// <summary> 45 /// Returns whether the operation can be canceled or not. 46 /// This can change during the course of the progress. 47 /// </summary> 38 bool Visible { get; set; } 39 bool CanBeStopped { get; } 48 40 bool CanBeCanceled { get; } 49 41 50 42 /// <summary> 51 /// Requests the operation behind the process to cancel. 52 /// Check the !ProgressState property when the cancellation succeeded. 53 /// The corresponding event will also notify of a success. 43 /// Start (or Restart) a progress with ProgressBarMode Marquee 54 44 /// </summary> 55 /// <exception cref="NotSupportedException">Thrown when cancellation is not supported.</exception> 45 void Start(string message); 46 /// <summary> 47 /// Start (or Restart) a progress with ProgressBarMode Continues 48 /// </summary> 49 void Start(string message, double progressValue); 50 void Finish(); 51 void Stop(); 56 52 void Cancel(); 57 /// <summary>58 /// Sets the ProgressValue to 1 and the ProgressState to Finished.59 /// </summary>60 void Finish();61 53 62 /// <summary> 63 /// Starts or restarts a Progress. 64 /// </summary> 65 void Start(); 66 67 void Start(string status); 68 69 /// <summary> 70 /// The status text changed. 71 /// </summary> 72 event EventHandler StatusChanged; 73 /// <summary> 74 /// The value of the progress changed. This is the (0;1] progress value from starting to finish. Values outside this range are permitted and need to be handled in some feasible manner. 75 /// </summary> 54 event EventHandler ProgressStateChanged; 55 event EventHandler MessageChanged; 56 event EventHandler ProgressBarModeChanged; 76 57 event EventHandler ProgressValueChanged; 77 /// <summary> 78 /// The state of the progress changed. The handler is supposed to query the ProgressState property. 79 /// </summary> 80 event EventHandler ProgressStateChanged; 81 /// <summary> 82 /// The progress' ability to cancel changed. 83 /// </summary> 58 event EventHandler VisibleChanged; 59 event EventHandler CanBeStoppedChanged; 84 60 event EventHandler CanBeCanceledChanged; 85 /// <summary> 86 /// A cancelation is requested. 87 /// </summary> 61 event EventHandler StopRequested; 88 62 event EventHandler CancelRequested; 89 63 } -
branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Progress.cs
r15400 r15415 24 24 namespace HeuristicLab.MainForm { 25 25 public class Progress : IProgress { 26 private string status;27 public string Status {28 get { return status; }29 set {30 if (status != value) {31 status = value;32 OnStatusChanged();33 }34 }35 }36 37 private double progressValue;38 public double ProgressValue {39 get { return progressValue; }40 set {41 if (progressValue != value) {42 progressValue = value;43 OnProgressChanged();44 }45 }46 }47 48 26 private ProgressState progressState; 49 27 public ProgressState ProgressState { … … 57 35 } 58 36 37 private string message; 38 public string Message { 39 get { return message; } 40 set { 41 if (message != value) { 42 message = value; 43 OnMessageChanged(); 44 } 45 } 46 } 47 48 private ProgressBarMode progressBarMode; 49 public ProgressBarMode ProgressBarMode { 50 get { return progressBarMode; } 51 set { 52 if (progressBarMode != value) { 53 progressBarMode = value; 54 OnProgressBarModeChanged(); 55 } 56 } 57 } 58 59 private double progressValue; 60 public double ProgressValue { 61 get { return progressValue; } 62 set { 63 if (progressBarMode == ProgressBarMode.Marquee) 64 throw new InvalidOperationException("Cannot set ProgressValue while ProgressBar is in Marquee-Mode"); 65 if (progressValue != value) { 66 progressValue = Math.Max(Math.Min(value, 1.0), 0.0); 67 OnProgressChanged(); 68 } 69 } 70 } 71 72 private bool visible; 73 public bool Visible { 74 get { return visible; } 75 set { 76 if (visible != value) { 77 visible = value; 78 OnVisibleChanged(); 79 } 80 } 81 } 82 83 private bool canBeStopped; 84 public bool CanBeStopped { 85 get { return canBeStopped; } 86 set { 87 if (canBeStopped != value) { 88 canBeStopped = value; 89 OnCanBeStoppedChanged(); 90 } 91 } 92 } 93 59 94 private bool canBeCanceled; 60 95 public bool CanBeCanceled { … … 70 105 public Progress() { 71 106 progressState = ProgressState.Finished; 107 canBeStopped = false; 72 108 canBeCanceled = false; 73 } 74 public Progress(string status) 75 : this() { 76 this.status = status; 77 } 78 public Progress(string status, ProgressState state) 79 : this() { 80 this.status = status; 81 this.progressState = state; 82 } 83 109 progressBarMode = ProgressBarMode.Marquee; 110 progressValue = 0.0; 111 } 112 113 public void Start(string message) { 114 ProgressState = ProgressState.Started; 115 ProgressBarMode = ProgressBarMode.Marquee; 116 Message = message; 117 Visible = true; 118 } 119 public void Start(string message, double progressValue) { 120 ProgressState = ProgressState.Started; 121 ProgressBarMode = ProgressBarMode.Continuous; 122 ProgressValue = progressValue; 123 Message = message; 124 Visible = true; 125 } 126 127 public void Finish() { 128 if (ProgressBarMode == ProgressBarMode.Continuous && ProgressValue != 1.0) 129 ProgressValue = 1.0; 130 ProgressState = ProgressState.Finished; 131 Visible = false; 132 } 133 134 public void Stop() { 135 if (canBeStopped) { 136 ProgressState = ProgressState.Stopped; 137 OnStopRequested(); 138 } else throw new NotSupportedException("This progress cannot be stopped."); 139 } 84 140 public void Cancel() { 85 if (canBeCanceled) 141 if (canBeCanceled) { 142 ProgressState = ProgressState.Canceled; 86 143 OnCancelRequested(); 87 } 88 89 public void Finish() { 90 if (ProgressValue != 1.0) ProgressValue = 1.0; 91 ProgressState = ProgressState.Finished; 92 } 93 94 public void Start() { 95 ProgressValue = 0.0; 96 ProgressState = ProgressState.Started; 97 } 98 99 public void Start(string status) { 100 Start(); 101 Status = status; 144 } else throw new NotSupportedException("This progress cannot be canceled."); 102 145 } 103 146 104 147 #region Event Handler 105 public event EventHandler StatusChanged; 106 private void OnStatusChanged() { 107 var handler = StatusChanged; 148 public event EventHandler ProgressStateChanged; 149 private void OnProgressStateChanged() { 150 var handler = ProgressStateChanged; 151 if (handler != null) handler(this, EventArgs.Empty); 152 } 153 154 public event EventHandler MessageChanged; 155 private void OnMessageChanged() { 156 var handler = MessageChanged; 157 if (handler != null) handler(this, EventArgs.Empty); 158 } 159 160 public event EventHandler ProgressBarModeChanged; 161 private void OnProgressBarModeChanged() { 162 var handler = ProgressBarModeChanged; 108 163 if (handler != null) handler(this, EventArgs.Empty); 109 164 } … … 115 170 } 116 171 117 public event EventHandler ProgressStateChanged; 118 private void OnProgressStateChanged() { 119 var handler = ProgressStateChanged; 172 public event EventHandler VisibleChanged; 173 private void OnVisibleChanged() { 174 var handler = VisibleChanged; 175 if (handler != null) handler(this, EventArgs.Empty); 176 } 177 178 public event EventHandler CanBeStoppedChanged; 179 private void OnCanBeStoppedChanged() { 180 var handler = CanBeStoppedChanged; 120 181 if (handler != null) handler(this, EventArgs.Empty); 121 182 } … … 127 188 } 128 189 190 public event EventHandler StopRequested; 191 private void OnStopRequested() { 192 var handler = StopRequested; 193 if (handler != null) handler(this, EventArgs.Empty); 194 } 195 129 196 public event EventHandler CancelRequested; 130 197 private void OnCancelRequested() { 131 198 var handler = CancelRequested; 132 if (handler != null) throw new NotSupportedException("Cancel request was ignored."); 133 else handler(this, EventArgs.Empty); 199 if (handler != null) handler(this, EventArgs.Empty); 134 200 } 135 201 #endregion
Note: See TracChangeset
for help on using the changeset viewer.