Changeset 2934 for trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs
- Timestamp:
- 03/05/10 12:37:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Operators.Views.GraphVisualization/3.3/Model/OperatorShape.cs
r2872 r2934 26 26 using Netron.Diagramming.Core; 27 27 using System.Drawing; 28 using System.Drawing.Drawing2D; 29 using HeuristicLab.Netron; 28 30 29 31 namespace HeuristicLab.Operators.Views.GraphVisualization { 30 public class OperatorShape : ClassShape { 31 32 public class OperatorShape : ComplexShapeBase { 33 private static int LABEL_HEIGHT = 16; 34 private static int LABEL_WIDTH = 180; 35 private static int LABEL_SPACING = 3; 36 private static int HEADER_HEIGHT = 30; 37 38 private ExpandableIconMaterial expandIconMaterial; 32 39 public OperatorShape() 33 40 : base() { 41 this.Resizable = false; 34 42 this.additionalConnectors = new List<IConnector>(); 35 } 36 43 this.labels = new List<string>(); 44 } 45 46 public override string EntityName { 47 get { return "Operator Shape"; } 48 } 49 50 public bool Collapsed { 51 get { return this.expandIconMaterial.Collapsed; } 52 set { 53 if (this.expandIconMaterial.Collapsed != value) 54 this.expandIconMaterial.Collapsed = value; 55 } 56 } 57 58 private Color color; 59 public Color Color { 60 get { return this.color; } 61 set { this.color = value; } 62 } 63 64 private string title; 65 public string Title { 66 get { return title; } 67 set { title = value; } 68 } 69 70 private IconMaterial iconMaterial; 71 public Bitmap Icon { 72 get { return this.iconMaterial.Icon; } 73 set { 74 this.iconMaterial.Icon = value; 75 this.iconMaterial.Transform(new Rectangle(new Point(Rectangle.X + 5, Rectangle.Y + 5), this.iconMaterial.Icon.Size)); 76 } 77 } 78 79 #region additional connectors 37 80 private List<IConnector> additionalConnectors; 38 81 public IEnumerable<string> AdditionalConnectorNames { … … 58 101 } 59 102 60 61 62 103 public void AddConnector(string connectorName) { 63 104 IConnector connector = this.CreateConnector(connectorName, this.BottomRightCorner); … … 89 130 } 90 131 } 91 132 #endregion 133 134 #region label material 135 private List<string> labels; 136 public IEnumerable<string> Labels { 137 get { return this.labels; } 138 } 139 140 public void UpdateLabels(IEnumerable<string> labels) { 141 this.labels = new List<string>(labels); 142 this.expandIconMaterial.Visible = this.labels.Count != 0; 143 this.UpdateLabels(); 144 } 145 #endregion 146 147 private void expandIconMaterial_OnExpand(object sender, EventArgs e) { 148 this.UpdateLabels(); 149 } 150 151 private void expandIconMaterial_OnCollapse(object sender, EventArgs e) { 152 this.UpdateLabels(); 153 } 154 155 private Size CalculateSize() { 156 int width = this.Rectangle.Width; 157 int height = HEADER_HEIGHT; 158 if (!Collapsed) 159 height += this.labels.Count * (LABEL_HEIGHT + LABEL_SPACING); 160 return new Size(width, height); 161 } 162 163 private void UpdateLabels() { 164 Size newSize = CalculateSize(); 165 if (this.Rectangle.Size != newSize) { 166 foreach (IConnector connector in this.additionalConnectors) 167 connector.MoveBy(new Point(0, newSize.Height - this.Rectangle.Height)); 168 this.mRectangle = new Rectangle(this.Rectangle.Location, newSize); 169 this.Invalidate(); 170 this.RaiseOnChange(this, new EntityEventArgs(this)); 171 } 172 } 92 173 93 174 protected override void Initialize() { 94 175 base.Initialize(); 95 176 96 #region Connectors 97 this.Connectors.Clear(); 98 99 predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y)); 100 Connectors.Add(predecessor); 101 102 successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y))); 103 Connectors.Add(successor); 104 #endregion 177 //the initial size 178 this.Transform(0, 0, 200, HEADER_HEIGHT); 179 this.color = Color.LightBlue; 180 181 this.iconMaterial = new IconMaterial(); 182 this.iconMaterial.Gliding = false; 183 this.Children.Add(iconMaterial); 184 185 Bitmap expandBitmap = new Bitmap(HeuristicLab.Common.Resources.VS2008ImageLibrary.Redo); 186 Bitmap collapseBitmap = new Bitmap(HeuristicLab.Common.Resources.VS2008ImageLibrary.Undo); 187 this.expandIconMaterial = new ExpandableIconMaterial(expandBitmap, collapseBitmap); 188 this.expandIconMaterial.Gliding = false; 189 this.expandIconMaterial.Transform(new Rectangle(new Point(Rectangle.Right - 20, Rectangle.Y + 7), expandIconMaterial.Icon.Size)); 190 this.expandIconMaterial.Visible = false; 191 this.expandIconMaterial.OnExpand += new EventHandler(expandIconMaterial_OnExpand); 192 this.expandIconMaterial.OnCollapse += new EventHandler(expandIconMaterial_OnCollapse); 193 this.Children.Add(expandIconMaterial); 194 195 this.predecessor = this.CreateConnector("Predecessor", new Point(Rectangle.Left, Center.Y)); 196 this.Connectors.Add(predecessor); 197 198 this.successor = this.CreateConnector("Successor", (new Point(Rectangle.Right, Center.Y))); 199 this.Connectors.Add(successor); 200 } 201 202 public override void Paint(Graphics g) { 203 base.Paint(g); 204 205 g.SmoothingMode = SmoothingMode.HighQuality; 206 207 Pen pen; 208 if (Hovered) 209 pen = ArtPalette.HighlightPen; 210 else 211 pen = mPenStyle.DrawingPen(); 212 213 GraphicsPath path = new GraphicsPath(); 214 path.AddArc(Rectangle.X, Rectangle.Y, 20, 20, -180, 90); 215 path.AddLine(Rectangle.X + 10, Rectangle.Y, Rectangle.X + Rectangle.Width - 10, Rectangle.Y); 216 path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y, 20, 20, -90, 90); 217 path.AddLine(Rectangle.X + Rectangle.Width, Rectangle.Y + 10, Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 10); 218 path.AddArc(Rectangle.X + Rectangle.Width - 20, Rectangle.Y + Rectangle.Height - 20, 20, 20, 0, 90); 219 path.AddLine(Rectangle.X + Rectangle.Width - 10, Rectangle.Y + Rectangle.Height, Rectangle.X + 10, Rectangle.Y + Rectangle.Height); 220 path.AddArc(Rectangle.X, Rectangle.Y + Rectangle.Height - 20, 20, 20, 90, 90); 221 path.AddLine(Rectangle.X, Rectangle.Y + Rectangle.Height - 10, Rectangle.X, Rectangle.Y + 10); 222 //shadow 223 if (ArtPalette.EnableShadows) { 224 Region darkRegion = new Region(path); 225 darkRegion.Translate(5, 5); 226 g.FillRegion(ArtPalette.ShadowBrush, darkRegion); 227 } 228 //background 229 g.FillPath(Brush, path); 230 231 using (LinearGradientBrush gradientBrush = new LinearGradientBrush(Rectangle.Location, new Point(Rectangle.X + Rectangle.Width, Rectangle.Y), this.Color, Color.White)) { 232 Region gradientRegion = new Region(path); 233 g.FillRegion(gradientBrush, gradientRegion); 234 } 235 236 if (!this.Collapsed) { 237 TextStyle textStyle = new TextStyle(Color.Black, new Font("Arial", 7), StringAlignment.Near, StringAlignment.Near); 238 StringFormat stringFormat = textStyle.StringFormat; 239 stringFormat.Trimming = StringTrimming.EllipsisWord; 240 stringFormat.FormatFlags = StringFormatFlags.LineLimit; 241 Rectangle rect; 242 243 for (int i = 0; i < this.labels.Count; i++) { 244 rect = new Rectangle(Rectangle.X + 25, Rectangle.Y + HEADER_HEIGHT + i * (LABEL_HEIGHT + LABEL_SPACING), LABEL_WIDTH, LABEL_HEIGHT); 245 g.DrawString(textStyle.GetFormattedText(this.labels[i]), textStyle.Font, textStyle.GetBrush(), rect, stringFormat); 246 } 247 } 248 249 //the border 250 g.DrawPath(pen, path); 251 252 //the title 253 g.DrawString(this.Title, ArtPalette.DefaultBoldFont, Brushes.Black, new Rectangle(Rectangle.X + 25, Rectangle.Y + 5, Rectangle.Width - 45, 27)); 254 255 //the material 256 foreach (IPaintable material in Children) 257 material.Paint(g); 258 259 //the connectors 260 if (this.ShowConnectors) { 261 for (int k = 0; k < Connectors.Count; k++) 262 Connectors[k].Paint(g); 263 } 105 264 } 106 265 }
Note: See TracChangeset
for help on using the changeset viewer.