Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs @ 17078

Last change on this file since 17078 was 16565, checked in by gkronber, 6 years ago

#2520: merged changes from PersistenceOverhaul branch (r16451:16564) into trunk

File size: 5.3 KB
RevLine 
[2853]1#region License Information
2/* HeuristicLab
[16565]3 * Copyright (C) 2002-2019 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2853]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.Collections.Generic;
[4068]23using System.Drawing;
24using HeuristicLab.Common;
[16565]25using HEAL.Attic;
[2853]26
27namespace HeuristicLab.Operators.Views.GraphVisualization {
[16565]28  [StorableType("354155F1-6C42-42D3-99CB-9290CD11649B")]
[6036]29  public class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
[2934]30    [Storable]
31    private List<string> labels;
[6036]32    public IEnumerable<string> Labels {
33      get { return labels; }
34    }
[2853]35
[6029]36    private object lockObject = new object();
37
[4722]38    [StorableConstructor]
[16565]39    protected OperatorShapeInfo(StorableConstructorFlag _) : base(_) { }
[7226]40
[4722]41    protected OperatorShapeInfo(OperatorShapeInfo original, Cloner cloner)
42      : base(original, cloner) {
43      collapsed = original.collapsed;
44      color = original.color;
45      lineColor = original.lineColor;
46      lineWidth = original.lineWidth;
47      title = original.title;
[7199]48      typeName = original.typeName;
[4722]49
[6029]50      //mkommend: necessary because cloning a Bitmap is not threadsafe
51      //see http://stackoverflow.com/questions/1851292/invalidoperationexception-object-is-currently-in-use-elsewhere for further information
[6031]52      if (original.icon != null) {
53        lock (original.lockObject) {
54          icon = (Bitmap)original.icon.Clone();
55        }
56      }
[6029]57
[4722]58      connectorNames = new List<string>(original.connectorNames);
59      labels = new List<string>(original.labels);
60    }
61    public override IDeepCloneable Clone(Cloner cloner) {
[6031]62      return new OperatorShapeInfo(this, cloner);
[4722]63    }
64
[2853]65    public OperatorShapeInfo()
[6036]66      : base() {
[2861]67      this.connectorNames = new List<string>();
[2934]68      this.labels = new List<string>();
[2853]69    }
70
71    public OperatorShapeInfo(IEnumerable<string> connectorNames)
72      : this() {
73      foreach (string connectorName in connectorNames)
74        this.connectorNames.Add(connectorName);
75    }
76
[2934]77    public OperatorShapeInfo(IEnumerable<string> connectorNames, IEnumerable<string> labels)
78      : this(connectorNames) {
79      foreach (string label in labels)
80        this.labels.Add(label);
81    }
82
83    public void AddConnector(string connectorName) {
[3386]84      if (!this.connectorNames.Contains(connectorName)) {
[2861]85        this.connectorNames.Add(connectorName);
[2853]86        this.OnChanged();
[2861]87      }
[2853]88    }
89
[2934]90    public void RemoveConnector(string connectorName) {
[2861]91      if (this.connectorNames.Contains(connectorName)) {
92        this.connectorNames.Remove(connectorName);
[2853]93        this.OnChanged();
[2861]94      }
[2853]95    }
96
[2934]97    public void UpdateLabels(IEnumerable<string> labels) {
98      this.labels = new List<string>(labels);
99      this.OnChanged();
100    }
101
102    [Storable]
[3386]103    private List<string> connectorNames;
104    public override IEnumerable<string> Connectors {
105      get { return this.connectorNames; }
106    }
107
108    [Storable]
[2934]109    private bool collapsed;
110    public bool Collapsed {
111      get { return this.collapsed; }
112      set {
113        if (this.collapsed != value) {
114          this.collapsed = value;
115          this.OnChanged();
116        }
117      }
118    }
119
120    [Storable]
[2853]121    private string title;
122    public string Title {
123      get { return this.title; }
124      set {
125        if (this.title != value) {
126          this.title = value;
127          this.OnChanged();
128        }
129      }
130    }
131
[2934]132    [Storable]
[7199]133    private string typeName;
134    public string TypeName {
135      get { return this.typeName; }
136      set {
137        if (this.typeName != value) {
138          this.typeName = value;
139          this.OnChanged();
140        }
141      }
142    }
143
144    [Storable]
[2934]145    private Color color;
146    public Color Color {
147      get { return this.color; }
[2853]148      set {
[2934]149        if (this.color != value) {
150          this.color = value;
[2853]151          this.OnChanged();
152        }
153      }
154    }
155
[2934]156    [Storable]
[2935]157    private Color lineColor;
158    public Color LineColor {
159      get { return this.lineColor; }
160      set {
161        if (this.lineColor != value) {
162          this.lineColor = value;
163          this.OnChanged();
164        }
165      }
166    }
167
168    [Storable]
169    private float lineWidth;
170    public float LineWidth {
171      get { return this.lineWidth; }
172      set {
173        if (this.lineWidth != value) {
174          this.lineWidth = value;
175          this.OnChanged();
176        }
177      }
178    }
179
[2934]180    private Bitmap icon;
181    public Bitmap Icon {
182      get { return this.icon; }
[2853]183      set {
[2934]184        if (this.icon != value) {
185          this.icon = value;
[2853]186          this.OnChanged();
187        }
188      }
189    }
190  }
191}
Note: See TracBrowser for help on using the repository browser.