source: trunk/CrypPlugins/IncDec/IncDec.cs @ 1941

Last change on this file since 1941 was 1259, checked in by Matthäus Wander, 12 years ago

shortened license text to boilerplate notice in all source files

File size: 4.4 KB
Line 
1/*
2   Copyright 2008 Thomas Schmid, University of Siegen
3
4   Licensed under the Apache License, Version 2.0 (the "License");
5   you may not use this file except in compliance with the License.
6   You may obtain a copy of the License at
7
8       http://www.apache.org/licenses/LICENSE-2.0
9
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15*/
16
17using System;
18using System.Collections.Generic;
19using System.Linq;
20using System.Text;
21using Cryptool.PluginBase.IO;
22using System.Windows.Controls;
23using Cryptool.PluginBase;
24using System.ComponentModel;
25using Cryptool.PluginBase.Miscellaneous;
26
27namespace IncDec
28{
29  [Author("Thomas Schmid", "thomas.schmid@cryptool.org", "Uni Siegen", "http://www.uni-siegen.de")]
30  [PluginInfo(false, "IncDec", "Increment/decrement operation", null, "IncDec/increment.png", "IncDec/decrement.png")]
31  public class IncDec : IThroughput
32  {
33    private IncDecSettings settings = new IncDecSettings();
34    private int input;
35
36    public IncDec()
37    {
38      settings.PropertyChanged += settings_PropertyChanged;
39    }
40
41    void settings_PropertyChanged(object sender, PropertyChangedEventArgs e)
42    {
43      if (e.PropertyName == "ModeSelect")
44      {
45        switch (settings.CurrentMode)
46        {
47          case IncDecSettings.Operator.Increment:
48            EventsHelper.StatusChanged(OnPluginStatusChanged, this, new StatusEventArgs(StatusChangedMode.ImageUpdate, 0));
49            break;
50          case IncDecSettings.Operator.Decrement:
51            EventsHelper.StatusChanged(OnPluginStatusChanged, this, new StatusEventArgs(StatusChangedMode.ImageUpdate, 1));
52            break;
53          default:
54            break;
55        }
56      }
57    }
58
59
60    [PropertyInfo(Direction.InputData, "Input.", "Input to increment or decrement.", null, false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
61    public int Input
62    {
63      get { return input; }
64      set
65      {
66        EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(50, 100));
67        input = value;
68        int returnValue = 0;
69        switch (settings.CurrentMode)
70        {
71          case IncDecSettings.Operator.Increment:
72            returnValue = input + settings.Value;
73            break;
74          case IncDecSettings.Operator.Decrement:
75            returnValue = input - settings.Value;
76            break;
77          default:
78            break;
79        }
80        this.output = returnValue;
81
82        OnPropertyChanged("Input");
83        OnPropertyChanged("Output");
84        EventsHelper.ProgressChanged(OnPluginProgressChanged, this, new PluginProgressEventArgs(100, 100));
85      }
86    }
87
88    private int output;
89    [PropertyInfo(Direction.OutputData, "Output.", "Output.", "", false, false, DisplayLevel.Beginner, QuickWatchFormat.Text, null)]
90    public int Output
91    {
92      get { return output; }
93      set { } // readonly
94    }
95
96
97    #region IPlugin Members
98
99#pragma warning disable 67
100                public event StatusChangedEventHandler OnPluginStatusChanged;
101                public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
102                public event PluginProgressChangedEventHandler OnPluginProgressChanged;
103#pragma warning restore
104
105    public Cryptool.PluginBase.ISettings Settings
106    {
107      get { return settings; }
108    }
109
110    public UserControl Presentation
111    {
112      get { return null; }
113    }
114
115    public UserControl QuickWatchPresentation
116    {
117      get { return null; }
118    }
119
120    public void PreExecution()
121    {     
122    }
123
124    public void Execute()
125    {
126    }
127
128    public void PostExecution()
129    {
130    }
131
132    public void Pause()
133    {
134    }
135
136    public void Stop()
137    {
138    }
139
140    public void Initialize()
141    {
142    }
143
144    public void Dispose()
145    {
146    }
147
148    #endregion
149
150    #region INotifyPropertyChanged Members
151
152    public event PropertyChangedEventHandler PropertyChanged;
153    public void OnPropertyChanged(string name)
154    {
155      if (PropertyChanged != null)
156      {
157        PropertyChanged(this, new PropertyChangedEventArgs(name));
158      }
159    }
160
161    #endregion
162  }
163}
Note: See TracBrowser for help on using the repository browser.