- Timestamp:
- 09/29/14 02:32:06 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
r11177 r11401 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System;23 using System.Drawing;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; 26 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using System; 26 using System.Drawing; 27 27 28 28 namespace HeuristicLab.Optimization.Networks { 29 [Item("Port", "A port of an optimization network entity.")]29 [Item("Port", "Abstract base class for ports of an optimization network node.")] 30 30 [StorableClass] 31 public class Port<T> : NamedItem, IPort<T> where T : class, IItem { 32 public override Image ItemImage { 33 get { 34 if (value != null) return value.ItemImage; 35 else return base.ItemImage; 36 } 31 public abstract class Port<T> : NamedItem, IPort<T> where T : class, IItem { 32 public static new Image StaticItemImage { 33 get { return HeuristicLab.Common.Resources.VSImageLibrary.Field; } 37 34 } 38 35 39 36 [Storable] 40 37 protected T value; 41 public T Value {38 public virtual T Value { 42 39 get { return value; } 43 set {40 protected set { 44 41 if (value != this.value) { 45 42 DeregisterValueEvents(); … … 52 49 object IPort.Value { 53 50 get { return Value; } 54 set {55 T val = value as T;56 if ((value != null) && (val == null))57 throw new InvalidOperationException(58 string.Format("Type mismatch. Value is not a \"{0}\".",59 typeof(T).GetPrettyName())60 );61 Value = val;62 }63 51 } 64 52 … … 70 58 RegisterValueEvents(); 71 59 } 72 public Port() : base("Anonymous") { } 73 public Port(string name) : base(name) { } 74 public Port(string name, string description) : base(name, description) { } 75 public Port(string name, T value) 76 : base(name) { 77 this.value = value; 78 RegisterValueEvents(); 79 } 80 public Port(string name, string description, T value) 81 : base(name, description) { 82 this.value = value; 83 RegisterValueEvents(); 84 } 60 protected Port() : base("Port") { } 61 protected Port(string name) : base(name) { } 62 protected Port(string name, string description) : base(name, description) { } 85 63 86 64 [StorableHook(HookType.AfterDeserialization)] 87 65 private void AfterDeserialization() { 88 66 RegisterValueEvents(); 89 }90 91 public override IDeepCloneable Clone(Cloner cloner) {92 return new Port<T>(this, cloner);93 67 } 94 68 … … 101 75 EventHandler handler = ValueChanged; 102 76 if (handler != null) handler(this, EventArgs.Empty); 103 OnItemImageChanged();104 77 OnToStringChanged(); 105 78 } 106 79 107 pr ivatevoid RegisterValueEvents() {80 protected virtual void RegisterValueEvents() { 108 81 if (value != null) { 109 value.ItemImageChanged += new EventHandler(Value_ItemImageChanged);110 82 value.ToStringChanged += new EventHandler(Value_ToStringChanged); 111 83 } 112 84 } 113 pr ivatevoid DeregisterValueEvents() {85 protected virtual void DeregisterValueEvents() { 114 86 if (value != null) { 115 value.ItemImageChanged -= new EventHandler(Value_ItemImageChanged);116 87 value.ToStringChanged -= new EventHandler(Value_ToStringChanged); 117 88 } 118 }119 private void Value_ItemImageChanged(object sender, EventArgs e) {120 OnItemImageChanged();121 89 } 122 90 private void Value_ToStringChanged(object sender, EventArgs e) {
Note: See TracChangeset
for help on using the changeset viewer.