Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Grammar.Editor/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs @ 6727

Last change on this file since 6727 was 6036, checked in by mkommend, 14 years ago

#1486: Decoupled operator graph visualization content classes from view classes.

File size: 5.0 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    protected OperatorShapeInfo(OperatorShapeInfo original, Cloner cloner)
41      : base(original, cloner) {
42      collapsed = original.collapsed;
43      color = original.color;
44      lineColor = original.lineColor;
45      lineWidth = original.lineWidth;
46      title = original.title;
47
48      //mkommend: necessary because cloning a Bitmap is not threadsafe
49      //see http://stackoverflow.com/questions/1851292/invalidoperationexception-object-is-currently-in-use-elsewhere for further information
50      if (original.icon != null) {
51        lock (original.lockObject) {
52          icon = (Bitmap)original.icon.Clone();
53        }
54      }
55
56      connectorNames = new List<string>(original.connectorNames);
57      labels = new List<string>(original.labels);
58    }
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new OperatorShapeInfo(this, cloner);
61    }
62
63    public OperatorShapeInfo()
64      : base() {
65      this.connectorNames = new List<string>();
66      this.labels = new List<string>();
67    }
68
69    public OperatorShapeInfo(IEnumerable<string> connectorNames)
70      : this() {
71      foreach (string connectorName in connectorNames)
72        this.connectorNames.Add(connectorName);
73    }
74
75    public OperatorShapeInfo(IEnumerable<string> connectorNames, IEnumerable<string> labels)
76      : this(connectorNames) {
77      foreach (string label in labels)
78        this.labels.Add(label);
79    }
80
81    public void AddConnector(string connectorName) {
82      if (!this.connectorNames.Contains(connectorName)) {
83        this.connectorNames.Add(connectorName);
84        this.OnChanged();
85      }
86    }
87
88    public void RemoveConnector(string connectorName) {
89      if (this.connectorNames.Contains(connectorName)) {
90        this.connectorNames.Remove(connectorName);
91        this.OnChanged();
92      }
93    }
94
95    public void UpdateLabels(IEnumerable<string> labels) {
96      this.labels = new List<string>(labels);
97      this.OnChanged();
98    }
99
100    [Storable]
101    private List<string> connectorNames;
102    public override IEnumerable<string> Connectors {
103      get { return this.connectorNames; }
104    }
105
106    [Storable]
107    private bool collapsed;
108    public bool Collapsed {
109      get { return this.collapsed; }
110      set {
111        if (this.collapsed != value) {
112          this.collapsed = value;
113          this.OnChanged();
114        }
115      }
116    }
117
118    [Storable]
119    private string title;
120    public string Title {
121      get { return this.title; }
122      set {
123        if (this.title != value) {
124          this.title = value;
125          this.OnChanged();
126        }
127      }
128    }
129
130    [Storable]
131    private Color color;
132    public Color Color {
133      get { return this.color; }
134      set {
135        if (this.color != value) {
136          this.color = value;
137          this.OnChanged();
138        }
139      }
140    }
141
142    [Storable]
143    private Color lineColor;
144    public Color LineColor {
145      get { return this.lineColor; }
146      set {
147        if (this.lineColor != value) {
148          this.lineColor = value;
149          this.OnChanged();
150        }
151      }
152    }
153
154    [Storable]
155    private float lineWidth;
156    public float LineWidth {
157      get { return this.lineWidth; }
158      set {
159        if (this.lineWidth != value) {
160          this.lineWidth = value;
161          this.OnChanged();
162        }
163      }
164    }
165
166    private Bitmap icon;
167    public Bitmap Icon {
168      get { return this.icon; }
169      set {
170        if (this.icon != value) {
171          this.icon = value;
172          this.OnChanged();
173        }
174      }
175    }
176  }
177}
Note: See TracBrowser for help on using the repository browser.