Changeset 15415 for branches/EnhancedProgress
- Timestamp:
- 10/10/17 14:30:37 (7 years ago)
- Location:
- branches/EnhancedProgress
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/EnhancedProgress/HeuristicLab.Clients.Hive/3.3/HiveClient.cs
r14901 r15415 265 265 266 266 // upload Job 267 refreshableJob.Progress. Status= "Uploading Job...";267 refreshableJob.Progress.Message = "Uploading Job..."; 268 268 refreshableJob.Job.Id = HiveServiceLocator.Instance.CallHiveService((s) => s.AddJob(refreshableJob.Job)); 269 269 refreshableJob.Job = HiveServiceLocator.Instance.CallHiveService((s) => s.GetJob(refreshableJob.Job.Id)); // update owner and permissions … … 275 275 276 276 // upload plugins 277 refreshableJob.Progress. Status= "Uploading plugins...";277 refreshableJob.Progress.Message = "Uploading plugins..."; 278 278 this.OnlinePlugins = HiveServiceLocator.Instance.CallHiveService((s) => s.GetPlugins()); 279 279 this.AlreadyUploadedPlugins = new List<Plugin>(); … … 283 283 284 284 // upload tasks 285 refreshableJob.Progress. Status= "Uploading tasks...";285 refreshableJob.Progress.Message = "Uploading tasks..."; 286 286 287 287 var tasks = new List<TS.Task>(); … … 380 380 lock (jobCountLocker) { 381 381 progress.ProgressValue = (double)taskCount[0] / totalJobCount; 382 progress. Status= string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount);382 progress.Message = string.Format("Uploaded task ({0} of {1})", taskCount[0], totalJobCount); 383 383 } 384 384 … … 416 416 totalJobCount = allTasks.Count(); 417 417 418 refreshableJob.Progress. Status= "Downloading tasks...";418 refreshableJob.Progress.Message = "Downloading tasks..."; 419 419 downloader = new TaskDownloader(allTasks.Select(x => x.Id)); 420 420 downloader.StartAsync(); … … 422 422 while (!downloader.IsFinished) { 423 423 refreshableJob.Progress.ProgressValue = downloader.FinishedCount / (double)totalJobCount; 424 refreshableJob.Progress. Status= string.Format("Downloading/deserializing tasks... ({0}/{1} finished)", downloader.FinishedCount, totalJobCount);424 refreshableJob.Progress.Message = string.Format("Downloading/deserializing tasks... ({0}/{1} finished)", downloader.FinishedCount, totalJobCount); 425 425 Thread.Sleep(500); 426 426 … … 432 432 var parents = allHiveTasks.Values.Where(x => !x.Task.ParentTaskId.HasValue); 433 433 434 refreshableJob.Progress. Status= "Downloading/deserializing complete. Displaying tasks...";434 refreshableJob.Progress.Message = "Downloading/deserializing complete. Displaying tasks..."; 435 435 // build child-task tree 436 436 foreach (HiveTask hiveTask in parents) { -
branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs
r15400 r15415 21 21 22 22 using System; 23 using System.Runtime.InteropServices; 23 24 using System.Windows.Forms; 24 25 … … 40 41 public ProgressView(Control control, IProgress content) 41 42 : base() { 42 if (control == null) throw new ArgumentNullException("control" , "The control is null.");43 if (content == null) throw new ArgumentNullException("content" , "The passed progress is null.");43 if (control == null) throw new ArgumentNullException("control"); 44 if (content == null) throw new ArgumentNullException("content"); 44 45 InitializeComponent(); 45 46 46 47 this.control = control; 47 48 this.content = content; 48 if (content.ProgressState == ProgressState.Started) 49 ShowProgress(); 49 50 UpdateButtonsState(); 51 if (content.Visible) ShowProgress(); 50 52 RegisterContentEvents(); 51 53 } … … 66 68 67 69 private void RegisterContentEvents() { 68 content.StatusChanged += new EventHandler(progress_StatusChanged);69 content.ProgressValueChanged += new EventHandler(progress_ProgressValueChanged);70 70 content.ProgressStateChanged += new EventHandler(Content_ProgressStateChanged); 71 content.MessageChanged += new EventHandler(Content_MessageChanged); 72 content.ProgressBarModeChanged += new EventHandler(Content_ProgressBarModeChanged); 73 content.ProgressValueChanged += new EventHandler(Content_ProgressValueChanged); 74 content.VisibleChanged += new EventHandler(Content_VisibleChanged); 75 content.CanBeStoppedChanged += new EventHandler(Content_CanBeStoppedChanged); 71 76 content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged); 72 77 } 73 78 private void DeregisterContentEvents() { 74 content.StatusChanged -= new EventHandler(progress_StatusChanged);75 content.ProgressValueChanged -= new EventHandler(progress_ProgressValueChanged);76 79 content.ProgressStateChanged -= new EventHandler(Content_ProgressStateChanged); 80 content.MessageChanged -= new EventHandler(Content_MessageChanged); 81 content.ProgressBarModeChanged -= new EventHandler(Content_ProgressBarModeChanged); 82 content.ProgressValueChanged -= new EventHandler(Content_ProgressValueChanged); 83 content.VisibleChanged -= new EventHandler(Content_VisibleChanged); 84 content.CanBeStoppedChanged -= new EventHandler(Content_CanBeStoppedChanged); 77 85 content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged); 78 86 } 79 87 88 private void Content_ProgressStateChanged(object sender, EventArgs e) { 89 UpdateProgressState(); 90 UpdateButtonsState(); 91 } 92 93 private void Content_MessageChanged(object sender, EventArgs e) { 94 UpdateProgressMessage(); 95 } 96 97 private void Content_ProgressBarModeChanged(object sender, EventArgs e) { 98 UpdateProgressValue(); 99 } 100 private void Content_ProgressValueChanged(object sender, EventArgs e) { 101 UpdateProgressValue(); 102 } 103 104 private void Content_VisibleChanged(object sender, EventArgs e) { 105 if (content.Visible) 106 ShowProgress(); 107 else 108 HideProgress(); 109 } 110 111 private void Content_CanBeStoppedChanged(object sender, EventArgs e) { 112 UpdateButtonsState(); 113 } 114 private void Content_CanBeCanceledChanged(object sender, EventArgs e) { 115 UpdateButtonsState(); 116 } 117 80 118 private void ShowProgress() { 81 if (Control.InvokeRequired) { 82 Control.Invoke((Action)ShowProgress); 83 return; 84 } 85 int height = Content.CanBeCanceled ? Height : collapsedControlHeight; 86 87 Left = (Control.ClientRectangle.Width / 2) - (Width / 2); 88 Top = (Control.ClientRectangle.Height / 2) - (height / 2); 119 if (control.InvokeRequired) { 120 control.Invoke((Action)ShowProgress); 121 return; 122 } 123 124 int height = (content.CanBeStopped || content.CanBeCanceled) ? Height : collapsedControlHeight; 125 126 Left = (control.ClientRectangle.Width / 2) - (Width / 2); 127 Top = (control.ClientRectangle.Height / 2) - (height / 2); 89 128 Anchor = AnchorStyles.None; 90 129 91 130 control.Enabled = false; 92 Parent = Control.Parent;131 Parent = control.Parent; 93 132 BringToFront(); 94 133 95 134 UpdateProgressValue(); 96 UpdateProgress Status();97 Update CancelButton();135 UpdateProgressMessage(); 136 UpdateButtonsState(); 98 137 Visible = true; 99 138 } 100 139 101 140 private void HideProgress() { 102 if (InvokeRequired) Invoke((Action)HideProgress); 103 else { 104 control.Enabled = true; 105 Parent = null; 106 Visible = false; 107 } 108 } 109 110 private void progress_StatusChanged(object sender, EventArgs e) { 111 UpdateProgressStatus(); 112 } 113 114 private void progress_ProgressValueChanged(object sender, EventArgs e) { 115 UpdateProgressValue(); 116 } 117 118 private void Content_ProgressStateChanged(object sender, EventArgs e) { 141 if (control.InvokeRequired) { 142 control.Invoke((Action)HideProgress); 143 return; 144 } 145 146 control.Enabled = true; 147 Parent = null; 148 Visible = false; 149 } 150 151 private void UpdateProgressState() { 152 if (control.InvokeRequired) { 153 control.Invoke((Action)UpdateProgressState); 154 return; 155 } 156 119 157 switch (content.ProgressState) { 120 case ProgressState.Finished: HideProgress(); break; 121 case ProgressState.Canceled: HideProgress(); break; 122 case ProgressState.Started: ShowProgress(); break; 158 case ProgressState.Started: 159 progressBar.SetState(ProgressBarState.Normal); 160 break; 161 case ProgressState.Finished: 162 HideProgress(); 163 progressBar.SetState(ProgressBarState.Normal); 164 break; 165 case ProgressState.Stopped: 166 progressBar.SetState(ProgressBarState.Warning); 167 break; 168 case ProgressState.Canceled: 169 progressBar.SetState(ProgressBarState.Error); 170 break; 123 171 default: throw new NotSupportedException("The progress state " + content.ProgressState + " is not supported by the ProgressView."); 124 172 } 125 173 } 126 174 127 private void Content_CanBeCanceledChanged(object sender, EventArgs e) { 128 UpdateCancelButton(); 129 } 130 131 private void UpdateCancelButton() { 132 cancelButton.Visible = content != null && content.CanBeCanceled; 133 cancelButton.Enabled = content != null && content.CanBeCanceled; 134 135 if (content != null && content.CanBeCanceled) { 136 Height = defaultControlHeight; 137 } else if (content != null && !content.CanBeCanceled) { 138 Height = collapsedControlHeight; 139 } 140 } 175 private void UpdateProgressMessage() { 176 if (control.InvokeRequired) { 177 control.Invoke((Action)UpdateProgressMessage); 178 return; 179 } 180 181 messageLabel.Text = content.Message; 182 } 183 141 184 142 185 private void UpdateProgressValue() { … … 146 189 try { 147 190 Invoke((Action)UpdateProgressValue); 148 } 149 catch (InvalidOperationException) { 191 } catch (InvalidOperationException) { 150 192 // swallow ObjectDisposedException 151 193 // which might occur if the invoke call is executed after or while the control is disposing 152 194 } 195 return; 196 } 197 198 if (content.ProgressBarMode == ProgressBarMode.Continuous) { 199 progressBar.Style = ProgressBarStyle.Continuous; 200 progressBar.Value = (int)Math.Round(progressBar.Minimum + content.ProgressValue * (progressBar.Maximum - progressBar.Minimum)); 153 201 } else { 154 if (content != null) { 155 double progressValue = content.ProgressValue; 156 if (progressValue <= 0.0 || progressValue > 1.0) { 157 progressBar.Style = ProgressBarStyle.Marquee; 158 } else { 159 progressBar.Style = ProgressBarStyle.Blocks; 160 progressBar.Value = 161 (int)Math.Round(progressBar.Minimum + progressValue * (progressBar.Maximum - progressBar.Minimum)); 162 } 163 } 164 } 165 } 166 167 private void UpdateProgressStatus() { 168 if (InvokeRequired) Invoke((Action)UpdateProgressStatus); 169 else if (content != null) 170 statusLabel.Text = content.Status; 171 } 172 202 progressBar.Style = ProgressBarStyle.Marquee; 203 } 204 } 205 206 private void UpdateButtonsState() { 207 if (control.InvokeRequired) { 208 control.Invoke((Action)UpdateButtonsState); 209 return; 210 } 211 212 stopButton.Visible = content.CanBeStopped; 213 stopButton.Enabled = content.ProgressState == ProgressState.Started && content.CanBeStopped; 214 215 cancelButton.Visible = content.CanBeCanceled; 216 cancelButton.Enabled = content.ProgressState == ProgressState.Started && content.CanBeCanceled; 217 218 if (content.CanBeStopped || content.CanBeCanceled) { 219 Height = defaultControlHeight; 220 } else { 221 Height = collapsedControlHeight; 222 } 223 } 224 225 private void stopButton_Click(object sender, EventArgs e) { 226 content.Stop(); 227 } 173 228 private void cancelButton_Click(object sender, EventArgs e) { 174 229 content.Cancel(); 175 230 } 176 231 } 232 233 // https://stackoverflow.com/a/9753302 234 internal enum ProgressBarState { 235 Normal = 1, Error = 2, Warning = 3 236 } 237 internal static class ProgressBarStateExtension { 238 [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] 239 private static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr w, IntPtr l); 240 public static void SetState(this ProgressBar pBar, ProgressBarState state) { 241 SendMessage(pBar.Handle, 1040, (IntPtr)state, IntPtr.Zero); 242 } 243 } 177 244 } -
branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.designer.cs
r14185 r15415 27 27 private System.ComponentModel.IContainer components = null; 28 28 29 29 30 30 #region Component Designer generated code 31 31 … … 36 36 private void InitializeComponent() { 37 37 this.progressBar = new System.Windows.Forms.ProgressBar(); 38 this. statusLabel = new System.Windows.Forms.Label();38 this.messageLabel = new System.Windows.Forms.Label(); 39 39 this.cancelButton = new System.Windows.Forms.Button(); 40 40 this.panel = new System.Windows.Forms.Panel(); 41 this.flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel(); 42 this.stopButton = new System.Windows.Forms.Button(); 41 43 this.panel.SuspendLayout(); 44 this.flowLayoutPanel.SuspendLayout(); 42 45 this.SuspendLayout(); 43 46 // … … 52 55 this.progressBar.TabIndex = 0; 53 56 // 54 // statusLabel57 // messageLabel 55 58 // 56 this. statusLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)59 this.messageLabel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 57 60 | System.Windows.Forms.AnchorStyles.Right))); 58 this. statusLabel.Location = new System.Drawing.Point(3, 33);59 this. statusLabel.Name = "statusLabel";60 this. statusLabel.Size = new System.Drawing.Size(352, 17);61 this. statusLabel.TabIndex = 1;61 this.messageLabel.Location = new System.Drawing.Point(3, 33); 62 this.messageLabel.Name = "messageLabel"; 63 this.messageLabel.Size = new System.Drawing.Size(352, 17); 64 this.messageLabel.TabIndex = 1; 62 65 // 63 66 // cancelButton 64 67 // 65 this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 66 this.cancelButton.Location = new System.Drawing.Point(280, 53); 68 this.cancelButton.Location = new System.Drawing.Point(274, 3); 67 69 this.cancelButton.Name = "cancelButton"; 68 70 this.cancelButton.Size = new System.Drawing.Size(75, 23); … … 78 80 | System.Windows.Forms.AnchorStyles.Right))); 79 81 this.panel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 82 this.panel.Controls.Add(this.flowLayoutPanel); 80 83 this.panel.Controls.Add(this.progressBar); 81 this.panel.Controls.Add(this.cancelButton); 82 this.panel.Controls.Add(this.statusLabel); 84 this.panel.Controls.Add(this.messageLabel); 83 85 this.panel.Location = new System.Drawing.Point(0, 0); 84 86 this.panel.Name = "panel"; 85 87 this.panel.Size = new System.Drawing.Size(360, 88); 86 88 this.panel.TabIndex = 3; 89 // 90 // flowLayoutPanel 91 // 92 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 93 | System.Windows.Forms.AnchorStyles.Left) 94 | System.Windows.Forms.AnchorStyles.Right))); 95 this.flowLayoutPanel.Controls.Add(this.cancelButton); 96 this.flowLayoutPanel.Controls.Add(this.stopButton); 97 this.flowLayoutPanel.Location = new System.Drawing.Point(3, 53); 98 this.flowLayoutPanel.Name = "flowLayoutPanel"; 99 this.flowLayoutPanel.RightToLeft = System.Windows.Forms.RightToLeft.Yes; 100 this.flowLayoutPanel.Size = new System.Drawing.Size(352, 30); 101 this.flowLayoutPanel.TabIndex = 3; 102 // 103 // stopButton 104 // 105 this.stopButton.Dock = System.Windows.Forms.DockStyle.Left; 106 this.stopButton.Location = new System.Drawing.Point(193, 3); 107 this.stopButton.Name = "stopButton"; 108 this.stopButton.Size = new System.Drawing.Size(75, 23); 109 this.stopButton.TabIndex = 3; 110 this.stopButton.Text = "Stop"; 111 this.stopButton.UseVisualStyleBackColor = true; 112 this.stopButton.Click += new System.EventHandler(this.stopButton_Click); 87 113 // 88 114 // ProgressView … … 93 119 this.Size = new System.Drawing.Size(360, 88); 94 120 this.panel.ResumeLayout(false); 121 this.flowLayoutPanel.ResumeLayout(false); 95 122 this.ResumeLayout(false); 96 123 … … 100 127 101 128 private System.Windows.Forms.ProgressBar progressBar; 102 private System.Windows.Forms.Label statusLabel;129 private System.Windows.Forms.Label messageLabel; 103 130 private System.Windows.Forms.Button cancelButton; 104 131 private System.Windows.Forms.Panel panel; 132 private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel; 133 private System.Windows.Forms.Button stopButton; 105 134 } 106 135 } -
branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs
r15400 r15415 353 353 /// Adds a <see cref="ProgressView"/> to the <see cref="ContentView"/>s showing the specified content. 354 354 /// </summary> 355 [Obsolete] 355 356 public IProgress AddOperationProgressToContent(IContent content, string progressMessage, bool addToObjectGraphObjects = true) { 356 357 if (InvokeRequired) { … … 371 372 contentViews = contentViews.Where(v => v.Content == content); 372 373 373 var progress = new Progress(progressMessage, ProgressState.Started); 374 var progress = new Progress(); 375 progress.Start(progressMessage); 374 376 foreach (var contentView in contentViews) { 375 377 progressViews.Add(new ProgressView(contentView, progress)); … … 383 385 /// Adds a <see cref="ProgressView"/> to the specified view. 384 386 /// </summary> 387 [Obsolete] 385 388 public IProgress AddOperationProgressToView(Control control, string progressMessage) { 386 var progress = new Progress(progressMessage, ProgressState.Started); 389 var progress = new Progress(); 390 progress.Start(progressMessage); 387 391 AddOperationProgressToView(control, progress); 388 392 return progress; -
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 -
branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r15400 r15415 40 40 private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator; 41 41 42 private readonly IProgress progress = new Progress() ;42 private readonly IProgress progress = new Progress() { CanBeCanceled = true, CanBeStopped = true }; 43 43 44 44 private enum TreeState { Valid, Invalid } … … 183 183 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 184 184 185 progress.Start("Calculate Impact and Replacement Values ..." );185 progress.Start("Calculate Impact and Replacement Values ...", 0); 186 186 var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree)); 187 187 await Task.Delay(500); // wait for progressbar to finish animation … … 298 298 299 299 private async void btnOptimizeConstants_Click(object sender, EventArgs e) { 300 progress.Start("Optimizing Constants ..." );300 progress.Start("Optimizing Constants ...", 0); 301 301 var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone(); 302 302 var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
Note: See TracChangeset
for help on using the changeset viewer.