Changeset 4423 for branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/ProgressView.cs
- Timestamp:
- 09/17/10 10:26:55 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3-Hive/sources/HeuristicLab.Hive/HeuristicLab.Hive.Experiment.Views/3.3/ProgressView.cs
r4368 r4423 12 12 namespace HeuristicLab.Hive.Experiment.Views { 13 13 public partial class ProgressView : HeuristicLab.MainForm.WindowsForms.View { 14 private ContentView parentView = null; 15 private bool simulateProgress = false; 14 private ContentView parentView; 15 private IProgress progress; 16 public IProgress Progress { 17 get { 18 return this.progress; 19 } 20 set { 21 if (this.progress != value) { 22 if (this.progress != null) { 23 DeregisterProgressEvents(); 24 } 25 this.progress = value; 26 RegisterProgressEvents(); 27 OnProgressChanged(); 28 } 29 } 30 } 16 31 17 32 public bool CancelEnabled { … … 28 43 } 29 44 30 private string status;31 public string Status {32 get { return status; }33 set {34 if (InvokeRequired) {35 Invoke(new Action<string>((s) => { Status = s;}), value);36 } else {37 status = value;38 statusLabel.Text = status;39 }40 41 }42 }43 44 public ProgressView(ContentView parentView)45 : this(parentView, "", false, true) {46 }47 48 public ProgressView(ContentView parentView, string initialStatus)49 : this(parentView, initialStatus, false, true) {50 }51 52 public ProgressView(ContentView parentView, string initialStatus, bool simulateProgress)53 : this(parentView, initialStatus, simulateProgress, true) {54 }55 56 45 /// <param name="parentView">This is the View which will be locked if lockParentView is true</param> 57 /// <param name="initialStatus">Status message</param> 58 /// <param name="simulateProgress">If true, the progress will be simulated by a timer which addes some progress every second</param> 59 /// <param name="lockParentView">if true parentView will be locked</param> 60 public ProgressView(ContentView parentView, string initialStatus, bool simulateProgress, bool lockParentView) { 46 public ProgressView(ContentView parentView, IProgress progress) { 61 47 InitializeComponent(); 62 48 this.parentView = parentView; 49 this.Progress = progress; 50 63 51 this.CancelEnabled = false; 64 this.Status = initialStatus;65 this.simulateProgress = simulateProgress;66 52 67 if (simulateProgress) { 68 Timer progressSimulator = new Timer(); 69 progressSimulator.Interval = 2000; 70 progressSimulator.Tick += new EventHandler(progressSimulator_Tick); 71 progressSimulator.Start(); 72 } 53 progressBar.Style = ProgressBarStyle.Marquee; 73 54 74 55 this.Left = (parentView.ClientRectangle.Width / 2) - (this.Width / 2); … … 76 57 this.Anchor = AnchorStyles.Left | AnchorStyles.Top; 77 58 78 if (lockParentView) 79 LockBackground(); 59 LockBackground(); 80 60 81 61 parentView.Controls.Add(this); … … 83 63 } 84 64 85 private void progressSimulator_Tick(object sender, EventArgs e) { 86 progressBar.Value = Math.Min(progressBar.Value + (progressBar.Maximum - progressBar.Value) / 10 + 1, progressBar.Maximum - 1); 65 private void RegisterProgressEvents() { 66 progress.Finished += new EventHandler(progress_Finished); 67 progress.StatusChanged += new EventHandler(progress_StatusChanged); 68 progress.ProgressValueChanged += new EventHandler(progress_ProgressChanged); 69 } 70 71 private void DeregisterProgressEvents() { 72 progress.Finished -= new EventHandler(progress_Finished); 73 progress.StatusChanged -= new EventHandler(progress_StatusChanged); 74 progress.ProgressValueChanged -= new EventHandler(progress_ProgressChanged); 75 } 76 77 void progress_Finished(object sender, EventArgs e) { 78 Finish(); 79 } 80 81 void progress_ProgressChanged(object sender, EventArgs e) { 82 if (InvokeRequired) { 83 Invoke(new EventHandler(progress_ProgressChanged), sender, e); 84 } else { 85 progressBar.Style = ProgressBarStyle.Blocks; 86 this.progressBar.Value = Math.Min(this.progressBar.Maximum, (int)(progress.ProgressValue * progressBar.Maximum)); 87 } 88 } 89 90 void progress_StatusChanged(object sender, EventArgs e) { 91 if (InvokeRequired) { 92 Invoke(new EventHandler(progress_StatusChanged), sender, e); 93 } else { 94 statusLabel.Text = progress.Status; 95 } 87 96 } 88 97 89 98 private void LockBackground() { 90 this.parentView.Locked = true;91 foreach (Control c in this.parentView.Controls) {92 c.Enabled = false;93 }94 this.Enabled = true;95 this.ReadOnly = false;96 }97 98 public void SetProgress(double progress) {99 99 if (InvokeRequired) { 100 Invoke(new Action <double>(SetProgress), progress);100 Invoke(new Action(LockBackground)); 101 101 } else { 102 this.progressBar.Value = Math.Max(this.progressBar.Value, (int)(progress * progressBar.Maximum)); 102 this.parentView.Locked = true; 103 foreach (Control c in this.parentView.Controls) { 104 c.Enabled = false; 105 } 106 this.Enabled = true; 107 this.ReadOnly = false; 103 108 } 104 109 } … … 122 127 } 123 128 129 private void OnProgressChanged() { 130 progress_StatusChanged(this, EventArgs.Empty); 131 progress_ProgressChanged(this, EventArgs.Empty); 132 } 133 124 134 public event EventHandler Canceled; 125 135 protected virtual void OnCanceled() {
Note: See TracChangeset
for help on using the changeset viewer.