- Timestamp:
- 10/10/17 14:30:37 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.