source: trunk/CrypPlugins/Multiplexer/MuxSettings.cs @ 1597

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

shortened license text to boilerplate notice in all source files

File size: 4.1 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;
22using System.ComponentModel;
23using Cryptool.PluginBase.Miscellaneous;
24
25namespace Multiplexer
26{
27  public class MuxSettings : ISettings
28  {
29    public event GuiLogNotificationEventHandler OnGuiLogNotificationOccured;
30
31    public enum DataTypes
32    {
33      CryptoolStream, String, ByteArray, Boolean, Integer
34    }
35
36    private Mux MyMux { get; set; }
37
38    public MuxSettings(Mux mux)
39    {
40      MyMux = mux;
41    }
42
43    #region ISettings Members
44
45    private bool hasChanges;
46    public bool HasChanges
47    {
48      get { return hasChanges; }
49      set 
50      { 
51        hasChanges = value;
52        OnPropertyChanged("HasChanges");
53      }
54    }
55
56    private int defaultValue;
57    [ContextMenu("Default value", "Select the default start value", 0, DisplayLevel.Beginner, ContextMenuControlType.ComboBox, null, "True", "False")]
58    [TaskPane("Default value", "Select the default start value", null, 0, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "True", "False" })]
59    public int DefaultValue
60    {
61      get { return this.defaultValue; }
62      set
63      {
64        if (value != defaultValue)
65        {
66          defaultValue = value;
67          HasChanges = true;
68          OnPropertyChanged("DefaultValue");
69        }
70      }
71    }
72
73    public bool CanChangeProperty { get; set; }
74
75    private DataTypes currentDataType;
76    public DataTypes CurrentDataType
77    {
78      get { return currentDataType; }
79      set 
80      {
81        if (currentDataType != value)
82        {
83          currentDataType = value;
84
85          // Changes must be applied synchronously, because onLoad of save file
86          // the Properties have to be set correctly BEFORE init of restore connections starts.
87          //
88          // The flag CanSendPropertiesChangedEvent will be set to false while loading a save file
89          // right after creating plugin instance. Next this Property will be set by the editor-loading-method.
90          // Here we set the new type without sending an event, because the event could be processed after
91          // the connections have been restored. That would result in an unuseable workspace or throw an exception
92          // while executing the init method.
93          MyMux.CreateInputOutput(MyMux.CanSendPropertiesChangedEvent);
94          // OnPropertyChanged("CurrentDataType");
95        }
96      }
97    }
98   
99    [TaskPane("Type", "Select DataType of plugin.", "", 2, false, DisplayLevel.Beginner, ControlType.ComboBox, new string[] { "CryptoolStream", "string", "byte[]", "boolean", "int" } )]
100    public int DataType
101    {
102      get { return (int)CurrentDataType; }
103      set
104      {
105        if (CanChangeProperty)
106        {
107          if (value != (int)CurrentDataType) HasChanges = true;
108          CurrentDataType = (DataTypes)value;
109        }
110        else EventsHelper.GuiLogMessage(OnGuiLogNotificationOccured, null, new GuiLogEventArgs("Can't change type while plugin is connected.", null, NotificationLevel.Warning));
111        OnPropertyChanged("DataType");
112      }
113    }
114
115    #endregion
116
117    #region INotifyPropertyChanged Members
118
119    public event PropertyChangedEventHandler PropertyChanged;
120
121    public void OnPropertyChanged(string name)
122    {
123      EventsHelper.PropertyChanged(PropertyChanged, this, new PropertyChangedEventArgs(name));
124    }
125
126    #endregion
127  }
128}
Note: See TracBrowser for help on using the repository browser.