source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.Netron/3.0.2672.12446/HeuristicLab.Netron-3.0.2672.12446/Ghosts.cs @ 4068

Last change on this file since 4068 was 4068, checked in by swagner, 11 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 6.8 KB
Line 
1#region License Information
2//This end-user license agreement applies to the following software;
3
4//The Netron Diagramming Library
5//Cobalt.IDE
6//Xeon webserver
7//Neon UI Library
8
9//Copyright (C) 2007, Francois M.Vanderseypen, The Netron Project & The Orbifold
10
11//This program is free software; you can redistribute it and/or
12//modify it under the terms of the GNU General Public License
13//as published by the Free Software Foundation; either version 2
14//of the License, or (at your option) any later version.
15
16//This program is distributed in the hope that it will be useful,
17//but WITHOUT ANY WARRANTY; without even the implied warranty of
18//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19//GNU General Public License for more details.
20
21//You should have received a copy of the GNU General Public License
22//along with this program; if not, write to the Free Software
23//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
24
25
26//http://www.fsf.org/licensing/licenses/gpl.html
27
28//http://www.fsf.org/licensing/licenses/gpl-faq.html
29#endregion
30
31using System;
32using System.Drawing;
33using Netron.Diagramming.Core;
34
35namespace HeuristicLab.Netron {
36  internal static class GhostsFactory {
37    private static RectGhost mRectangular;
38    private static LineGhost mLine;
39    private static EllipticGhost mEllipse;
40    private static MultiLineGhost mMultiLine;
41    private static CurvedLineGhost mCurvedLine;
42    private static PolygonGhost mPolygon;
43
44    private static IView mView;
45    public static IView View {
46      get { return mView; }
47      set { mView = value; }
48    }
49
50    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
51    public static IGhost GetGhost(object pars, GhostTypes type) {
52      Point[] points;
53      switch (type) {
54        case GhostTypes.Rectangle:
55          if (mRectangular == null)
56            mRectangular = new RectGhost(View);
57          points = (Point[])pars;
58          mRectangular.Start = points[0];
59          mRectangular.End = points[1];
60          return mRectangular;
61        case GhostTypes.Ellipse:
62          if (mEllipse == null)
63            mEllipse = new EllipticGhost(View);
64          points = (Point[])pars;
65          mEllipse.Start = points[0];
66          mEllipse.End = points[1];
67          return mEllipse;
68        case GhostTypes.Line:
69          if (mLine == null)
70            mLine = new LineGhost(View);
71          points = (Point[])pars;
72          mLine.Start = points[0];
73          mLine.End = points[1];
74          return mLine;
75        case GhostTypes.MultiLine:
76          if (mMultiLine == null)
77            mMultiLine = new MultiLineGhost(View);
78          points = (Point[])pars;
79          mMultiLine.Points = points;
80          return mMultiLine;
81        case GhostTypes.CurvedLine:
82          if (mCurvedLine == null)
83            mCurvedLine = new CurvedLineGhost(View);
84          points = (Point[])pars;
85          mCurvedLine.Points = points;
86          return mCurvedLine;
87        case GhostTypes.Polygon:
88          if (mPolygon == null)
89            mPolygon = new PolygonGhost(View);
90          points = (Point[])pars;
91          mPolygon.Points = points;
92          return mPolygon;
93        default:
94          return null;
95      }
96    }
97  }
98
99  internal class PolygonGhost : MultiLineGhost {
100    public PolygonGhost(IView view) : base(view) { }
101    public override void Paint(Graphics g) {
102      g.Transform = View.ViewMatrix;
103      g.DrawPolygon(ArtPalette.GhostPen, Points);
104    }
105  }
106
107  internal class CurvedLineGhost : MultiLineGhost {
108    public CurvedLineGhost(IView view)
109      : base(view) { }
110    public override void Paint(Graphics g) {
111      g.Transform = View.ViewMatrix;
112      g.DrawCurve(ArtPalette.GhostPen, Points);
113    }
114  }
115
116  internal class MultiLineGhost : AbstractGhost {
117    private Point[] points;
118    public Point[] Points {
119      get {
120        return points;
121      }
122      set {
123        points = value;
124        Start = value[0];
125        End = value[value.Length - 1];
126      }
127    }
128    public MultiLineGhost(IView view, Point[] points)
129      : base(view) {
130      this.points = points;
131    }
132    public MultiLineGhost(IView view)
133      : base(view) {
134
135    }
136    public override void Paint(Graphics g) {
137      if (g == null)
138        return;
139      g.Transform = View.ViewMatrix;
140      g.DrawLines(ArtPalette.GhostPen, points);
141    }
142  }
143
144  internal class RectGhost : AbstractGhost {
145    public RectGhost(IView view, Point s, Point e)
146      : base(view, s, e) { }
147    public RectGhost(IView view)
148      : base(view) {
149    }
150    public override void Paint(Graphics g) {
151      if (g == null)
152        return;
153      g.FillRectangle(ArtPalette.GhostBrush, Rectangle);
154      g.DrawRectangle(ArtPalette.GhostPen, Rectangle);
155    }
156  }
157
158  internal class EllipticGhost : AbstractGhost {
159    public EllipticGhost(IView view, Point s, Point e)
160      : base(view, s, e) {
161    }
162    public EllipticGhost(IView view)
163      : base(view) {
164    }
165    public override void Paint(Graphics g) {
166      if (g == null)
167        return;
168      g.Transform = View.ViewMatrix;
169      g.FillEllipse(ArtPalette.GhostBrush, Rectangle);
170      g.DrawEllipse(ArtPalette.GhostPen, Rectangle);
171    }
172  }
173
174  internal class LineGhost : AbstractGhost {
175    public LineGhost(IView view, Point s, Point e)
176      : base(view, s, e) {
177    }
178    public LineGhost(IView view)
179      : base(view) {
180    }
181
182    public override void Paint(Graphics g) {
183      if (g == null)
184        return;
185      g.Transform = View.ViewMatrix;
186      g.DrawLine(ArtPalette.GhostPen, Start, End);
187    }
188  }
189
190  internal abstract class AbstractGhost : IGhost {
191    private Point mStart;
192    private Point mEnd;
193    private IView mView;
194    public IView View {
195      get { return mView; }
196      set { mView = value; }
197    }
198    public Rectangle Rectangle {
199      get {
200        return Rectangle.FromLTRB(Math.Min(mStart.X, mEnd.X), Math.Min(mStart.Y, mEnd.Y), Math.Max(mStart.X, mEnd.X), Math.Max(mStart.Y, mEnd.Y));
201      }
202      set {
203        //was orginally empty
204        throw new NotImplementedException();
205      }
206    }
207    public Point Start {
208      get {
209        return mStart;
210      }
211      set {
212        mStart = value;
213      }
214    }
215    public Point End {
216      get {
217        return mEnd;
218      }
219      set {
220        mEnd = value;
221      }
222    }
223    protected AbstractGhost(IView view, Point s, Point e)
224      : this(view) {
225      this.mStart = s;
226      this.mEnd = e;
227    }
228    protected AbstractGhost(IView view) {
229      mView = view;
230    }
231    public abstract void Paint(Graphics g);
232  }
233
234  internal enum GhostTypes {
235    Rectangle,
236    Ellipse,
237    Line,
238    MultiLine,
239    CurvedLine,
240    Polygon
241  }
242}
Note: See TracBrowser for help on using the repository browser.