[2853] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
[4068] | 23 | using System.Drawing;
|
---|
| 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2853] | 26 |
|
---|
| 27 | namespace HeuristicLab.Operators.Views.GraphVisualization {
|
---|
[3017] | 28 | [StorableClass]
|
---|
[6046] | 29 | public class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
|
---|
[2934] | 30 | [Storable]
|
---|
| 31 | private List<string> labels;
|
---|
[6046] | 32 | public IEnumerable<string> Labels {
|
---|
| 33 | get { return labels; }
|
---|
| 34 | }
|
---|
[2853] | 35 |
|
---|
[6046] | 36 | private object lockObject = new object();
|
---|
| 37 |
|
---|
[4722] | 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 |
|
---|
[6046] | 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 |
|
---|
[4722] | 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 |
|
---|
[2853] | 63 | public OperatorShapeInfo()
|
---|
[6046] | 64 | : base() {
|
---|
[2861] | 65 | this.connectorNames = new List<string>();
|
---|
[2934] | 66 | this.labels = new List<string>();
|
---|
[2853] | 67 | }
|
---|
| 68 |
|
---|
| 69 | public OperatorShapeInfo(IEnumerable<string> connectorNames)
|
---|
| 70 | : this() {
|
---|
| 71 | foreach (string connectorName in connectorNames)
|
---|
| 72 | this.connectorNames.Add(connectorName);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[2934] | 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) {
|
---|
[3386] | 82 | if (!this.connectorNames.Contains(connectorName)) {
|
---|
[2861] | 83 | this.connectorNames.Add(connectorName);
|
---|
[2853] | 84 | this.OnChanged();
|
---|
[2861] | 85 | }
|
---|
[2853] | 86 | }
|
---|
| 87 |
|
---|
[2934] | 88 | public void RemoveConnector(string connectorName) {
|
---|
[2861] | 89 | if (this.connectorNames.Contains(connectorName)) {
|
---|
| 90 | this.connectorNames.Remove(connectorName);
|
---|
[2853] | 91 | this.OnChanged();
|
---|
[2861] | 92 | }
|
---|
[2853] | 93 | }
|
---|
| 94 |
|
---|
[2934] | 95 | public void UpdateLabels(IEnumerable<string> labels) {
|
---|
| 96 | this.labels = new List<string>(labels);
|
---|
| 97 | this.OnChanged();
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | [Storable]
|
---|
[3386] | 101 | private List<string> connectorNames;
|
---|
| 102 | public override IEnumerable<string> Connectors {
|
---|
| 103 | get { return this.connectorNames; }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | [Storable]
|
---|
[2934] | 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]
|
---|
[2853] | 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 |
|
---|
[2934] | 130 | [Storable]
|
---|
| 131 | private Color color;
|
---|
| 132 | public Color Color {
|
---|
| 133 | get { return this.color; }
|
---|
[2853] | 134 | set {
|
---|
[2934] | 135 | if (this.color != value) {
|
---|
| 136 | this.color = value;
|
---|
[2853] | 137 | this.OnChanged();
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
[2934] | 142 | [Storable]
|
---|
[2935] | 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 |
|
---|
[2934] | 166 | private Bitmap icon;
|
---|
| 167 | public Bitmap Icon {
|
---|
| 168 | get { return this.icon; }
|
---|
[2853] | 169 | set {
|
---|
[2934] | 170 | if (this.icon != value) {
|
---|
| 171 | this.icon = value;
|
---|
[2853] | 172 | this.OnChanged();
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
| 175 | }
|
---|
| 176 | }
|
---|
| 177 | }
|
---|