1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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.Collections.Generic;
|
---|
23 | using System.Drawing;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
26 |
|
---|
27 | namespace 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 |
|
---|
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;
|
---|
48 | typeName = original.typeName;
|
---|
49 |
|
---|
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
|
---|
52 | if (original.icon != null) {
|
---|
53 | lock (original.lockObject) {
|
---|
54 | icon = (Bitmap)original.icon.Clone();
|
---|
55 | }
|
---|
56 | }
|
---|
57 |
|
---|
58 | connectorNames = new List<string>(original.connectorNames);
|
---|
59 | labels = new List<string>(original.labels);
|
---|
60 | }
|
---|
61 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
62 | return new OperatorShapeInfo(this, cloner);
|
---|
63 | }
|
---|
64 |
|
---|
65 | public OperatorShapeInfo()
|
---|
66 | : base() {
|
---|
67 | this.connectorNames = new List<string>();
|
---|
68 | this.labels = new List<string>();
|
---|
69 | }
|
---|
70 |
|
---|
71 | public OperatorShapeInfo(IEnumerable<string> connectorNames)
|
---|
72 | : this() {
|
---|
73 | foreach (string connectorName in connectorNames)
|
---|
74 | this.connectorNames.Add(connectorName);
|
---|
75 | }
|
---|
76 |
|
---|
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) {
|
---|
84 | if (!this.connectorNames.Contains(connectorName)) {
|
---|
85 | this.connectorNames.Add(connectorName);
|
---|
86 | this.OnChanged();
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | public void RemoveConnector(string connectorName) {
|
---|
91 | if (this.connectorNames.Contains(connectorName)) {
|
---|
92 | this.connectorNames.Remove(connectorName);
|
---|
93 | this.OnChanged();
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | public void UpdateLabels(IEnumerable<string> labels) {
|
---|
98 | this.labels = new List<string>(labels);
|
---|
99 | this.OnChanged();
|
---|
100 | }
|
---|
101 |
|
---|
102 | [Storable]
|
---|
103 | private List<string> connectorNames;
|
---|
104 | public override IEnumerable<string> Connectors {
|
---|
105 | get { return this.connectorNames; }
|
---|
106 | }
|
---|
107 |
|
---|
108 | [Storable]
|
---|
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]
|
---|
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 |
|
---|
132 | [Storable]
|
---|
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]
|
---|
145 | private Color color;
|
---|
146 | public Color Color {
|
---|
147 | get { return this.color; }
|
---|
148 | set {
|
---|
149 | if (this.color != value) {
|
---|
150 | this.color = value;
|
---|
151 | this.OnChanged();
|
---|
152 | }
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | [Storable]
|
---|
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 |
|
---|
180 | private Bitmap icon;
|
---|
181 | public Bitmap Icon {
|
---|
182 | get { return this.icon; }
|
---|
183 | set {
|
---|
184 | if (this.icon != value) {
|
---|
185 | this.icon = value;
|
---|
186 | this.OnChanged();
|
---|
187 | }
|
---|
188 | }
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|