Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Core/3.3/ItemBase.cs @ 2553

Last change on this file since 2553 was 2546, checked in by swagner, 15 years ago

Continued work on Optimizer and on adapting all views to the new MainForm concept (#770)

File size: 3.6 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Text;
25using System.Xml;
26using System.Drawing;
27using System.Resources;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Common.Resources;
30
31namespace HeuristicLab.Core {
32  /// <summary>
33  /// Represents the base class for all basic item types.
34  /// </summary>
35  [Item("ItemBase", "Base class for all HeuristicLab items.")]
36  [EmptyStorableClass]
37  public abstract class ItemBase : IItem {
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
58    /// <summary>
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>
84    /// Gets the string representation of the current instance.
85    /// </summary>
86    /// <returns>The type name of the current instance.</returns>
87    public override string ToString() {
88      return GetType().Name;
89    }
90
91    /// <summary>
92    /// Fires a new <c>Changed</c> event.
93    /// </summary>
94    /// <remarks>Calls <see cref="OnChanged"/>.</remarks>
95    public void FireChanged() {
96      OnChanged();
97    }
98
99    /// <summary>
100    /// Occurs when the current item was changed.
101    /// </summary>
102    public event EventHandler Changed;
103    /// <summary>
104    /// Fires a new <c>Changed</c> event.
105    /// </summary>
106    protected virtual void OnChanged() {
107      if (Changed != null)
108        Changed(this, new EventArgs());
109    }
110  }
111}
Note: See TracBrowser for help on using the repository browser.