1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2010 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 | using System.Collections.Generic;
|
---|
24 | using System.ComponentModel;
|
---|
25 | using System.Drawing;
|
---|
26 | using System.Data;
|
---|
27 | using System.Linq;
|
---|
28 | using System.Text;
|
---|
29 | using System.Windows.Forms;
|
---|
30 | using HeuristicLab.MainForm;
|
---|
31 | using HeuristicLab.MainForm.WindowsForms;
|
---|
32 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
|
---|
33 | using HeuristicLab.Core.Views;
|
---|
34 | using HeuristicLab.Core;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
|
---|
37 | [View("Symbolic Expression Grammar View")]
|
---|
38 | [Content(typeof(DefaultSymbolicExpressionGrammar), true)]
|
---|
39 | public partial class DefaultSymbolicExpressionGrammarView : ItemView {
|
---|
40 | private CheckedItemList<Symbol> symbols;
|
---|
41 |
|
---|
42 | public new DefaultSymbolicExpressionGrammar Content {
|
---|
43 | get { return (DefaultSymbolicExpressionGrammar)base.Content; }
|
---|
44 | set { base.Content = value; }
|
---|
45 | }
|
---|
46 |
|
---|
47 | public DefaultSymbolicExpressionGrammarView() {
|
---|
48 | InitializeComponent();
|
---|
49 | symbols = new CheckedItemList<Symbol>();
|
---|
50 | symbols.CheckedItemsChanged += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<HeuristicLab.Collections.IndexedItem<Symbol>>(symbols_CheckedItemsChanged);
|
---|
51 | }
|
---|
52 |
|
---|
53 | protected override void OnContentChanged() {
|
---|
54 | base.OnContentChanged();
|
---|
55 | UpdateControl();
|
---|
56 | }
|
---|
57 |
|
---|
58 | protected override void SetEnabledStateOfControls() {
|
---|
59 | base.SetEnabledStateOfControls();
|
---|
60 | checkedItemListView.Enabled = Content != null;
|
---|
61 | checkedItemListView.ReadOnly = ReadOnly;
|
---|
62 | }
|
---|
63 |
|
---|
64 | #region content event handlers
|
---|
65 | private void Content_Changed(object sender, EventArgs e) {
|
---|
66 | UpdateControl();
|
---|
67 | }
|
---|
68 | #endregion
|
---|
69 |
|
---|
70 | #region helpers
|
---|
71 | private void UpdateControl() {
|
---|
72 | if (Content == null) {
|
---|
73 | ClearSymbols();
|
---|
74 | checkedItemListView.Content = symbols.AsReadOnly();
|
---|
75 | } else {
|
---|
76 | ClearSymbols();
|
---|
77 | foreach (Symbol symbol in Content.Symbols) {
|
---|
78 | if (!(symbol is ReadOnlySymbol)) {
|
---|
79 | symbol.Changed += new EventHandler(symbol_Changed);
|
---|
80 | symbols.Add(symbol, symbol.InitialFrequency > 0.0);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | checkedItemListView.Content = symbols.AsReadOnly();
|
---|
84 | }
|
---|
85 | SetEnabledStateOfControls();
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | private void symbol_Changed(object sender, EventArgs e) {
|
---|
90 | Symbol symbol = (Symbol)sender;
|
---|
91 | symbols.SetItemCheckedState(symbol, symbol.InitialFrequency > 0.0);
|
---|
92 | }
|
---|
93 |
|
---|
94 | private void symbols_CheckedItemsChanged(object sender, HeuristicLab.Collections.CollectionItemsChangedEventArgs<HeuristicLab.Collections.IndexedItem<Symbol>> e) {
|
---|
95 | ICheckedItemList<Symbol> checkedItemList = (ICheckedItemList<Symbol>)sender;
|
---|
96 | foreach (var indexedItem in e.Items) {
|
---|
97 | if (checkedItemList.ItemChecked(indexedItem.Value)) {
|
---|
98 | indexedItem.Value.InitialFrequency = 1.0;
|
---|
99 | } else {
|
---|
100 | indexedItem.Value.InitialFrequency = 0.0;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | }
|
---|
104 | private void ClearSymbols() {
|
---|
105 | foreach (Symbol s in symbols)
|
---|
106 | s.Changed -= new EventHandler(symbol_Changed);
|
---|
107 | symbols.Clear();
|
---|
108 | }
|
---|
109 | #endregion
|
---|
110 | }
|
---|
111 | }
|
---|