1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 |
|
---|
24 | namespace HeuristicLab.MainForm {
|
---|
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 | private ProgressState progressState;
|
---|
49 | public ProgressState ProgressState {
|
---|
50 | get { return progressState; }
|
---|
51 | private set {
|
---|
52 | if (progressState != value) {
|
---|
53 | progressState = value;
|
---|
54 | OnProgressStateChanged();
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | private bool canBeCanceled;
|
---|
60 | public bool CanBeCanceled {
|
---|
61 | get { return canBeCanceled; }
|
---|
62 | set {
|
---|
63 | if (canBeCanceled != value) {
|
---|
64 | canBeCanceled = value;
|
---|
65 | OnCanBeCanceledChanged();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public Progress() {
|
---|
71 | progressState = ProgressState.Finished;
|
---|
72 | 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 |
|
---|
84 | public void Cancel() {
|
---|
85 | if (canBeCanceled)
|
---|
86 | 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;
|
---|
102 | }
|
---|
103 |
|
---|
104 | #region Event Handler
|
---|
105 | public event EventHandler StatusChanged;
|
---|
106 | private void OnStatusChanged() {
|
---|
107 | var handler = StatusChanged;
|
---|
108 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
109 | }
|
---|
110 |
|
---|
111 | public event EventHandler ProgressValueChanged;
|
---|
112 | private void OnProgressChanged() {
|
---|
113 | var handler = ProgressValueChanged;
|
---|
114 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
115 | }
|
---|
116 |
|
---|
117 | public event EventHandler ProgressStateChanged;
|
---|
118 | private void OnProgressStateChanged() {
|
---|
119 | var handler = ProgressStateChanged;
|
---|
120 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
121 | }
|
---|
122 |
|
---|
123 | public event EventHandler CanBeCanceledChanged;
|
---|
124 | private void OnCanBeCanceledChanged() {
|
---|
125 | var handler = CanBeCanceledChanged;
|
---|
126 | if (handler != null) handler(this, EventArgs.Empty);
|
---|
127 | }
|
---|
128 |
|
---|
129 | public event EventHandler CancelRequested;
|
---|
130 | private void OnCancelRequested() {
|
---|
131 | var handler = CancelRequested;
|
---|
132 | if (handler != null) throw new NotSupportedException("Cancel request was ignored.");
|
---|
133 | else handler(this, EventArgs.Empty);
|
---|
134 | }
|
---|
135 | #endregion
|
---|
136 | }
|
---|
137 | }
|
---|