source: trunk/CrypPlugins/Factorizer/FactorizerSettings.cs @ 2061

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

shortened license text to boilerplate notice in all source files

File size: 3.2 KB
Line 
1/*
2   Copyright 2008 Timo Eckhardt, 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;
22
23namespace Factorizer
24{
25  public class FactorizerSettings:ISettings
26  {
27    private const int BRUTEFORCEMIN = 100;
28    private const int BRUTEFORCEMAX = 100000;
29    private const string ERROR_BFL = "ERROR_BFL";
30    public FactorizerSettings()
31    {
32      m_Errors = new Dictionary<string, string>();
33      BruteForceLimit = 100000;
34    }
35
36    #region Settings
37
38    private IDictionary<string, string> m_Errors;
39    public bool HasErrors
40    {
41      get 
42      {
43        return m_BruteForceLimit < 0;
44      }
45    }
46    private long m_BruteForceLimit;
47
48    [TaskPane("Upper Limit for \nBruteForce Factorization", "Upper Limit for \nBruteForce Factorization", "Brute-Force Factorization", 0, false, DisplayLevel.Beginner, ControlType.TextBox, ValidationType.RangeInteger, 100, 1000000)]
49    public long BruteForceLimit
50    {
51      get { return m_BruteForceLimit; }
52      set {
53        if (value >= BRUTEFORCEMIN && value <= BRUTEFORCEMAX)
54        {
55          m_BruteForceLimit = value;
56          AddError(ERROR_BFL, null);
57          FirePropertyChangedEvent("BruteForceLimit");
58        }
59        else
60        {
61          AddError(ERROR_BFL, "BruteForceLimit has to be greater or equal than 100 and less or equal than 1.000.000.");
62          m_BruteForceLimit = -1;
63        }
64        //HasChanges = true;
65      }
66    }
67
68
69    private void AddError(string key, string message)
70    {
71      if (string.IsNullOrEmpty(message))
72      {
73        if (m_Errors.ContainsKey(key))
74          m_Errors.Remove(key);
75      }
76      else
77      {
78        if (!m_Errors.ContainsKey(key))
79          m_Errors.Add(key, message);
80        else
81          m_Errors[key] = message;
82      }
83    }
84
85    public ICollection<string> Errors
86    {
87      get
88      {
89        return m_Errors.Values;
90      }
91
92    }
93    #endregion
94    #region ISettings Members
95
96    private bool m_HasChanges;
97    public bool HasChanges
98    {
99      get
100      {
101        return true;
102      }
103      set
104      {
105        m_HasChanges = value;
106        FirePropertyChangedEvent("HasChanges");
107      }
108    }
109
110    #endregion
111
112    #region INotifyPropertyChanged Members
113
114    public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
115
116    private void FirePropertyChangedEvent(string propertyName)
117    {
118      if (PropertyChanged != null) PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
119    }
120    #endregion
121  }
122}
Note: See TracBrowser for help on using the repository browser.