Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/Ants.cs @ 2781

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

added netron specific extensions (ticket #867)

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Drawing.Drawing2D;
6using System.Drawing;
7using Netron.Diagramming.Core;
8
9namespace HeuristicLab.Netron {
10  internal static class AntsFactory {
11    private static RectAnts mRectangular;
12    public readonly static Pen Pen = new Pen(Color.Black, 1f);
13    static AntsFactory() {
14      Pen.DashStyle = DashStyle.Dash;
15    }
16    public static IAnts GetAnts(object pars, AntTypes type) {
17      switch (type) {
18        case AntTypes.Rectangle:
19          if (mRectangular == null)
20            mRectangular = new RectAnts();
21          Point[] points = (Point[])pars;
22          mRectangular.Start = points[0];
23          mRectangular.End = points[1];
24          return mRectangular;
25        default:
26          return null;
27      }
28    }
29
30    internal class RectAnts : AbstractAnt {
31      public RectAnts(Point s, Point e)
32        : this() {
33        this.Start = s;
34        this.End = e;
35
36      }
37
38      public RectAnts()
39        : base() {
40        Pen.DashStyle = DashStyle.Dash;
41      }
42
43      public override void Paint(Graphics g) {
44        if (g == null)
45          return;
46        g.DrawRectangle(AntsFactory.Pen, Start.X, Start.Y, End.X - Start.X, End.Y - Start.Y);
47
48      }
49    }
50
51    internal abstract class AbstractAnt : IAnts {
52      private Point mStart;
53      public Point Start {
54        get {
55          return mStart;
56        }
57        set {
58          mStart = value;
59        }
60      }
61      private Point mEnd;
62      public Point End {
63        get {
64          return mEnd;
65        }
66        set {
67          mEnd = value;
68        }
69      }
70
71      public Rectangle Rectangle {
72        get { return new Rectangle(mStart.X, mStart.Y, mEnd.X - mStart.X, mEnd.Y - mStart.Y); }
73        set {
74          mStart = new Point(value.X, value.Y);
75          mEnd = new Point(value.Right, value.Bottom);
76        }
77      }
78
79      public abstract void Paint(Graphics g);
80    }
81  }
82  internal enum AntTypes {
83    Rectangle
84  }
85}
Note: See TracBrowser for help on using the repository browser.