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