Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TimeSeries/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs @ 7213

Last change on this file since 7213 was 7213, checked in by gkronber, 12 years ago

#1081 merged r7103:7209 from trunk into time series branch

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