Free cookie consent management tool by TermsFeed Policy Generator

Changeset 15417


Ignore:
Timestamp:
10/11/17 10:00:34 (7 years ago)
Author:
pfleck
Message:

#2845 Removed Visible property and hide on "Finished".

Location:
branches/EnhancedProgress
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.cs

    r15415 r15417  
    4848      this.content = content;
    4949
    50       UpdateButtonsState();
    51       if (content.Visible) ShowProgress();
     50      if (content.ProgressState != ProgressState.Finished)
     51        ShowProgress();
    5252      RegisterContentEvents();
    5353    }
    5454
    55     /// <summary>
    56     /// Clean up any resources being used.
    57     /// </summary>
    58     /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    5955    protected override void Dispose(bool disposing) {
    6056      DeregisterContentEvents();
     
    7268      content.ProgressBarModeChanged += new EventHandler(Content_ProgressBarModeChanged);
    7369      content.ProgressValueChanged += new EventHandler(Content_ProgressValueChanged);
    74       content.VisibleChanged += new EventHandler(Content_VisibleChanged);
    7570      content.CanBeStoppedChanged += new EventHandler(Content_CanBeStoppedChanged);
    7671      content.CanBeCanceledChanged += new EventHandler(Content_CanBeCanceledChanged);
     
    8176      content.ProgressBarModeChanged -= new EventHandler(Content_ProgressBarModeChanged);
    8277      content.ProgressValueChanged -= new EventHandler(Content_ProgressValueChanged);
    83       content.VisibleChanged -= new EventHandler(Content_VisibleChanged);
    8478      content.CanBeStoppedChanged -= new EventHandler(Content_CanBeStoppedChanged);
    8579      content.CanBeCanceledChanged -= new EventHandler(Content_CanBeCanceledChanged);
     
    10296    }
    10397
    104     private void Content_VisibleChanged(object sender, EventArgs e) {
    105       if (content.Visible)
     98    private void Content_CanBeStoppedChanged(object sender, EventArgs e) {
     99      UpdateButtonsState();
     100    }
     101    private void Content_CanBeCanceledChanged(object sender, EventArgs e) {
     102      UpdateButtonsState();
     103    }
     104
     105    private void ShowProgress() {
     106      if (control.InvokeRequired) {
     107        control.Invoke((Action)ShowProgress);
     108        return;
     109      }
     110      if (Parent != null) return;
     111
     112      int height = (content.CanBeStopped || content.CanBeCanceled) ? Height : collapsedControlHeight;
     113      Left = (control.ClientRectangle.Width / 2) - (Width / 2);
     114      Top = (control.ClientRectangle.Height / 2) - (height / 2);
     115      Anchor = AnchorStyles.None;
     116
     117      UpdateProgressMessage();
     118      UpdateProgressValue();
     119      UpdateButtonsState();
     120
     121      control.Enabled = false;
     122      Parent = control.Parent;
     123      BringToFront();
     124      Visible = true;
     125    }
     126
     127    private void HideProgress() {
     128      if (control.InvokeRequired) {
     129        control.Invoke((Action)HideProgress);
     130        return;
     131      }
     132      if (Parent == null) return;
     133
     134      Visible = false;
     135      control.Enabled = true;
     136      Parent = null;
     137    }
     138
     139    private void UpdateProgressState() {
     140      if (control.InvokeRequired) {
     141        control.Invoke((Action)UpdateProgressState);
     142        return;
     143      }
     144
     145      if (content.ProgressState != ProgressState.Finished)
    106146        ShowProgress();
    107147      else
    108148        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 
    118     private void ShowProgress() {
    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);
    128       Anchor = AnchorStyles.None;
    129 
    130       control.Enabled = false;
    131       Parent = control.Parent;
    132       BringToFront();
    133 
    134       UpdateProgressValue();
    135       UpdateProgressMessage();
    136       UpdateButtonsState();
    137       Visible = true;
    138     }
    139 
    140     private void HideProgress() {
    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       }
    156149
    157150      switch (content.ProgressState) {
    158151        case ProgressState.Started:
     152        case ProgressState.Finished:
    159153          progressBar.SetState(ProgressBarState.Normal);
    160154          break;
    161         case ProgressState.Finished:
    162           HideProgress();
    163           progressBar.SetState(ProgressBarState.Normal);
    164           break;
    165         case ProgressState.Stopped:
     155        case ProgressState.StopRequested:
    166156          progressBar.SetState(ProgressBarState.Warning);
    167157          break;
    168         case ProgressState.Canceled:
     158        case ProgressState.CancelRequested:
    169159          progressBar.SetState(ProgressBarState.Error);
    170160          break;
     
    211201
    212202      stopButton.Visible = content.CanBeStopped;
    213       stopButton.Enabled = content.ProgressState == ProgressState.Started && content.CanBeStopped;
     203      stopButton.Enabled = content.CanBeStopped && content.ProgressState == ProgressState.Started;
    214204
    215205      cancelButton.Visible = content.CanBeCanceled;
    216       cancelButton.Enabled = content.ProgressState == ProgressState.Started && content.CanBeCanceled;
     206      cancelButton.Enabled = content.CanBeCanceled && content.ProgressState == ProgressState.Started;
    217207
    218208      if (content.CanBeStopped || content.CanBeCanceled) {
  • branches/EnhancedProgress/HeuristicLab.MainForm.WindowsForms/3.3/Controls/ProgressView.designer.cs

    r15415 r15417  
    103103      // stopButton
    104104      //
    105       this.stopButton.Dock = System.Windows.Forms.DockStyle.Left;
    106105      this.stopButton.Location = new System.Drawing.Point(193, 3);
    107106      this.stopButton.Name = "stopButton";
  • branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Interfaces/IProgress.cs

    r15415 r15417  
    2424
    2525namespace HeuristicLab.MainForm {
    26   public enum ProgressState { Started, Finished, Stopped, Canceled }
     26  public enum ProgressState { Started, Finished, StopRequested, CancelRequested }
    2727  public enum ProgressBarMode { Continuous, Marquee }
    2828
     
    3636    /// </summary>
    3737    double ProgressValue { get; set; }
    38     bool Visible { get; set; }
    3938    bool CanBeStopped { get; }
    4039    bool CanBeCanceled { get; }
     
    5655    event EventHandler ProgressBarModeChanged;
    5756    event EventHandler ProgressValueChanged;
    58     event EventHandler VisibleChanged;
    5957    event EventHandler CanBeStoppedChanged;
    6058    event EventHandler CanBeCanceledChanged;
  • branches/EnhancedProgress/HeuristicLab.MainForm/3.3/Progress.cs

    r15415 r15417  
    7070    }
    7171
    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 
    8372    private bool canBeStopped;
    8473    public bool CanBeStopped {
     
    115104      ProgressBarMode = ProgressBarMode.Marquee;
    116105      Message = message;
    117       Visible = true;
    118106    }
    119107    public void Start(string message, double progressValue) {
     
    122110      ProgressValue = progressValue;
    123111      Message = message;
    124       Visible = true;
    125112    }
    126113
     
    129116        ProgressValue = 1.0;
    130117      ProgressState = ProgressState.Finished;
    131       Visible = false;
    132118    }
    133119
    134120    public void Stop() {
    135121      if (canBeStopped) {
    136         ProgressState = ProgressState.Stopped;
     122        ProgressState = ProgressState.StopRequested;
    137123        OnStopRequested();
    138124      } else throw new NotSupportedException("This progress cannot be stopped.");
     
    140126    public void Cancel() {
    141127      if (canBeCanceled) {
    142         ProgressState = ProgressState.Canceled;
     128        ProgressState = ProgressState.CancelRequested;
    143129        OnCancelRequested();
    144130      } else throw new NotSupportedException("This progress cannot be canceled.");
     
    170156    }
    171157
    172     public event EventHandler VisibleChanged;
    173     private void OnVisibleChanged() {
    174       var handler = VisibleChanged;
    175       if (handler != null) handler(this, EventArgs.Empty);
    176     }
    177 
    178158    public event EventHandler CanBeStoppedChanged;
    179159    private void OnCanBeStoppedChanged() {
  • branches/EnhancedProgress/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r15415 r15417  
    4040    private readonly ISymbolicDataAnalysisSolutionImpactValuesCalculator impactCalculator;
    4141
    42     private readonly IProgress progress = new Progress() { CanBeCanceled = true, CanBeStopped = true };
     42    private readonly Progress progress = new Progress();
    4343
    4444    private enum TreeState { Valid, Invalid }
     
    184184
    185185      progress.Start("Calculate Impact and Replacement Values ...", 0);
     186      progress.CanBeStopped = true;
    186187      var impactAndReplacementValues = await Task.Run(() => CalculateImpactAndReplacementValues(tree));
    187       await Task.Delay(500); // wait for progressbar to finish animation
     188      if (progress.ProgressState != ProgressState.StopRequested)
     189        await Task.Delay(500); // wait for progressbar to finish animation
    188190      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    189191      foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
     
    192194      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    193195      progress.Finish();
     196      progress.CanBeStopped = false;
    194197      PaintNodeImpacts();
    195198    }
     
    198201      var impactAndReplacementValues = new Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>>();
    199202      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     203        if (progress.ProgressState == ProgressState.StopRequested) continue;
    200204        double impactValue, replacementValue, newQualityForImpactsCalculation;
    201205        impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
Note: See TracChangeset for help on using the changeset viewer.