[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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.Text;
|
---|
| 25 | using System.Xml;
|
---|
[2546] | 26 | using System.Drawing;
|
---|
| 27 | using System.Resources;
|
---|
[1853] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2546] | 29 | using HeuristicLab.Common.Resources;
|
---|
[2] | 30 |
|
---|
| 31 | namespace HeuristicLab.Core {
|
---|
[776] | 32 | /// <summary>
|
---|
| 33 | /// Represents the base class for all basic item types.
|
---|
| 34 | /// </summary>
|
---|
[2546] | 35 | [Item("ItemBase", "Base class for all HeuristicLab items.")]
|
---|
[1853] | 36 | [EmptyStorableClass]
|
---|
[2526] | 37 | public abstract class ItemBase : IItem {
|
---|
[2546] | 38 | public virtual string Name {
|
---|
| 39 | get {
|
---|
| 40 | if (ItemAttribute.GetName(this.GetType()) != null)
|
---|
| 41 | return ItemAttribute.GetName(this.GetType());
|
---|
| 42 | else
|
---|
| 43 | return this.GetType().Name;
|
---|
| 44 | }
|
---|
| 45 | }
|
---|
| 46 | public virtual string Description {
|
---|
| 47 | get {
|
---|
| 48 | if (ItemAttribute.GetDescription(this.GetType()) != null)
|
---|
| 49 | return ItemAttribute.GetDescription(this.GetType());
|
---|
| 50 | else
|
---|
| 51 | return "No description available.";
|
---|
| 52 | }
|
---|
| 53 | }
|
---|
| 54 | public virtual Image Image {
|
---|
| 55 | get { return Resources.HeuristicLab; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[776] | 58 | /// <summary>
|
---|
[2526] | 59 | /// Creates a deep clone of this instance.
|
---|
| 60 | /// </summary>
|
---|
| 61 | /// <remarks>
|
---|
| 62 | /// This method is the entry point for creating a deep clone of a whole object graph.
|
---|
| 63 | /// </remarks>
|
---|
| 64 | /// <returns>A clone of this instance.</returns>
|
---|
| 65 | public object Clone() {
|
---|
| 66 | return Clone(new Cloner());
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | /// <summary>
|
---|
| 70 | /// Creates a deep clone of this instance.
|
---|
| 71 | /// </summary>
|
---|
| 72 | /// <remarks>This method should not be called directly. It is used for creating clones of
|
---|
| 73 | /// objects which are contained in the object that is currently cloned.</remarks>
|
---|
| 74 | /// <param name="cloner">The cloner which is responsible for keeping track of all already
|
---|
| 75 | /// cloned objects.</param>
|
---|
| 76 | /// <returns>A clone of this instance.</returns>
|
---|
| 77 | public virtual IItem Clone(ICloner cloner) {
|
---|
| 78 | ItemBase clone = (ItemBase)Activator.CreateInstance(this.GetType());
|
---|
| 79 | cloner.RegisterClonedObject(this, clone);
|
---|
| 80 | return clone;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | /// <summary>
|
---|
[776] | 84 | /// Gets the string representation of the current instance.
|
---|
| 85 | /// </summary>
|
---|
| 86 | /// <returns>The type name of the current instance.</returns>
|
---|
[2] | 87 | public override string ToString() {
|
---|
| 88 | return GetType().Name;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[776] | 91 | /// <summary>
|
---|
| 92 | /// Fires a new <c>Changed</c> event.
|
---|
| 93 | /// </summary>
|
---|
| 94 | /// <remarks>Calls <see cref="OnChanged"/>.</remarks>
|
---|
[2] | 95 | public void FireChanged() {
|
---|
| 96 | OnChanged();
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[776] | 99 | /// <summary>
|
---|
| 100 | /// Occurs when the current item was changed.
|
---|
| 101 | /// </summary>
|
---|
[2] | 102 | public event EventHandler Changed;
|
---|
[776] | 103 | /// <summary>
|
---|
| 104 | /// Fires a new <c>Changed</c> event.
|
---|
| 105 | /// </summary>
|
---|
[2] | 106 | protected virtual void OnChanged() {
|
---|
| 107 | if (Changed != null)
|
---|
| 108 | Changed(this, new EventArgs());
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|