Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/23/11 10:00:31 (13 years ago)
Author:
abeham
Message:

#1465

  • updated branch with trunk changes
Location:
branches/histogram
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • branches/histogram/HeuristicLab.Operators.Views.GraphVisualization/3.3/OperatorGraphVisualization/OperatorShapeInfo.cs

    r5445 r6046  
    2222using System.Collections.Generic;
    2323using System.Drawing;
    24 using System.Linq;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    27 using Netron.Diagramming.Core;
    2826
    2927namespace HeuristicLab.Operators.Views.GraphVisualization {
    3028  [StorableClass]
    31   internal class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
     29  public class OperatorShapeInfo : ShapeInfo, IOperatorShapeInfo {
    3230    [Storable]
    3331    private List<string> labels;
     32    public IEnumerable<string> Labels {
     33      get { return labels; }
     34    }
     35
     36    private object lockObject = new object();
    3437
    3538    [StorableConstructor]
     
    4245      lineWidth = original.lineWidth;
    4346      title = original.title;
    44       if (original.icon != null) icon = (Bitmap)original.icon.Clone();
     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      }
    4555
    4656      connectorNames = new List<string>(original.connectorNames);
     
    5262
    5363    public OperatorShapeInfo()
    54       : base(typeof(OperatorShape)) {
     64      : base() {
    5565      this.connectorNames = new List<string>();
    5666      this.labels = new List<string>();
     
    164174      }
    165175    }
    166 
    167     public override IShape CreateShape() {
    168       OperatorShape shape = (OperatorShape)base.CreateShape();
    169       shape.Title = this.Title;
    170       shape.Color = this.Color;
    171       shape.LineColor = this.LineColor;
    172       shape.LineWidth = this.LineWidth;
    173       shape.Icon = this.Icon;
    174       shape.Collapsed = this.Collapsed;
    175       foreach (string connectorName in this.connectorNames)
    176         if (connectorName != OperatorShapeInfoFactory.SuccessorConnector && connectorName != OperatorShapeInfoFactory.PredecessorConnector)
    177           shape.AddConnector(connectorName);
    178 
    179       shape.UpdateLabels(this.labels);
    180       return shape;
    181     }
    182 
    183     public override void UpdateShape(IShape shape) {
    184       base.UpdateShape(shape);
    185       OperatorShape operatorShape = (OperatorShape)shape;
    186       operatorShape.Title = this.Title;
    187       operatorShape.Color = this.Color;
    188       operatorShape.LineColor = this.LineColor;
    189       operatorShape.LineWidth = this.LineWidth;
    190       operatorShape.Icon = this.Icon;
    191       operatorShape.Collapsed = this.Collapsed;
    192 
    193       int i = 0;
    194       int j = 0;
    195       //remove old connectors and skip correct connectors
    196       List<string> oldConnectorNames = operatorShape.AdditionalConnectorNames.ToList();
    197       while (i < this.connectorNames.Count && j < oldConnectorNames.Count) {
    198         if (connectorNames[i] == OperatorShapeInfoFactory.SuccessorConnector ||
    199           connectorNames[i] == OperatorShapeInfoFactory.PredecessorConnector)
    200           i++;
    201         else if (oldConnectorNames[j] == OperatorShapeInfoFactory.SuccessorConnector ||
    202           oldConnectorNames[j] == OperatorShapeInfoFactory.PredecessorConnector)
    203           j++;
    204         else if (this.connectorNames[i] != oldConnectorNames[j]) {
    205           operatorShape.RemoveConnector(oldConnectorNames[j]);
    206           j++;
    207         } else {
    208           i++;
    209           j++;
    210         }
    211       }
    212       //remove remaining old connectors
    213       for (; j < oldConnectorNames.Count; j++)
    214         operatorShape.RemoveConnector(oldConnectorNames[j]);
    215 
    216       //add new connectors except successor and connector
    217       for (; i < this.connectorNames.Count; i++)
    218         if (this.connectorNames[i] != OperatorShapeInfoFactory.SuccessorConnector && this.connectorNames[i] != OperatorShapeInfoFactory.PredecessorConnector)
    219           operatorShape.AddConnector(this.connectorNames[i]);
    220 
    221       operatorShape.UpdateLabels(this.labels);
    222     }
    223 
    224     public override void UpdateShapeInfo(IShape shape) {
    225       base.UpdateShapeInfo(shape);
    226       OperatorShape operatorShape = (OperatorShape)shape;
    227       this.Title = operatorShape.Title;
    228       this.Color = operatorShape.Color;
    229       this.LineColor = operatorShape.LineColor;
    230       this.LineWidth = operatorShape.LineWidth;
    231       this.Icon = operatorShape.Icon;
    232       this.Collapsed = operatorShape.Collapsed;
    233 
    234       //TODO update Connector and labels;
    235     }
    236176  }
    237177}
Note: See TracChangeset for help on using the changeset viewer.