Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 17605 was 9181, checked in by mkommend, 12 years ago

#2006: Changed GhostFactory to not hold a reference to the View object and completely removed the TextEditor tool as it was not in use.

File size: 6.2 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    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily")]
38    public static IGhost GetGhost(object pars, GhostTypes type, IView View) {
39      Point[] points;
40      switch (type) {
41        case GhostTypes.Rectangle:
42          var mRectangular = new RectGhost(View);
43          points = (Point[])pars;
44          mRectangular.Start = points[0];
45          mRectangular.End = points[1];
46          return mRectangular;
47        case GhostTypes.Ellipse:
48          var mEllipse = new EllipticGhost(View);
49          points = (Point[])pars;
50          mEllipse.Start = points[0];
51          mEllipse.End = points[1];
52          return mEllipse;
53        case GhostTypes.Line:
54          var mLine = new LineGhost(View);
55          points = (Point[])pars;
56          mLine.Start = points[0];
57          mLine.End = points[1];
58          return mLine;
59        case GhostTypes.MultiLine:
60          var mMultiLine = new MultiLineGhost(View);
61          points = (Point[])pars;
62          mMultiLine.Points = points;
63          return mMultiLine;
64        case GhostTypes.CurvedLine:
65          var mCurvedLine = new CurvedLineGhost(View);
66          points = (Point[])pars;
67          mCurvedLine.Points = points;
68          return mCurvedLine;
69        case GhostTypes.Polygon:
70          var mPolygon = new PolygonGhost(View);
71          points = (Point[])pars;
72          mPolygon.Points = points;
73          return mPolygon;
74        default:
75          return null;
76      }
77    }
78  }
79
80  internal class PolygonGhost : MultiLineGhost {
81    public PolygonGhost(IView view) : base(view) { }
82    public override void Paint(Graphics g) {
83      g.Transform = View.ViewMatrix;
84      g.DrawPolygon(ArtPalette.GhostPen, Points);
85    }
86  }
87
88  internal class CurvedLineGhost : MultiLineGhost {
89    public CurvedLineGhost(IView view)
90      : base(view) { }
91    public override void Paint(Graphics g) {
92      g.Transform = View.ViewMatrix;
93      g.DrawCurve(ArtPalette.GhostPen, Points);
94    }
95  }
96
97  internal class MultiLineGhost : AbstractGhost {
98    private Point[] points;
99    public Point[] Points {
100      get {
101        return points;
102      }
103      set {
104        points = value;
105        Start = value[0];
106        End = value[value.Length - 1];
107      }
108    }
109    public MultiLineGhost(IView view, Point[] points)
110      : base(view) {
111      this.points = points;
112    }
113    public MultiLineGhost(IView view)
114      : base(view) {
115
116    }
117    public override void Paint(Graphics g) {
118      if (g == null)
119        return;
120      g.Transform = View.ViewMatrix;
121      g.DrawLines(ArtPalette.GhostPen, points);
122    }
123  }
124
125  internal class RectGhost : AbstractGhost {
126    public RectGhost(IView view, Point s, Point e)
127      : base(view, s, e) { }
128    public RectGhost(IView view)
129      : base(view) {
130    }
131    public override void Paint(Graphics g) {
132      if (g == null)
133        return;
134      g.FillRectangle(ArtPalette.GhostBrush, Rectangle);
135      g.DrawRectangle(ArtPalette.GhostPen, Rectangle);
136    }
137  }
138
139  internal class EllipticGhost : AbstractGhost {
140    public EllipticGhost(IView view, Point s, Point e)
141      : base(view, s, e) {
142    }
143    public EllipticGhost(IView view)
144      : base(view) {
145    }
146    public override void Paint(Graphics g) {
147      if (g == null)
148        return;
149      g.Transform = View.ViewMatrix;
150      g.FillEllipse(ArtPalette.GhostBrush, Rectangle);
151      g.DrawEllipse(ArtPalette.GhostPen, Rectangle);
152    }
153  }
154
155  internal class LineGhost : AbstractGhost {
156    public LineGhost(IView view, Point s, Point e)
157      : base(view, s, e) {
158    }
159    public LineGhost(IView view)
160      : base(view) {
161    }
162
163    public override void Paint(Graphics g) {
164      if (g == null)
165        return;
166      g.Transform = View.ViewMatrix;
167      g.DrawLine(ArtPalette.GhostPen, Start, End);
168    }
169  }
170
171  internal abstract class AbstractGhost : IGhost {
172    private Point mStart;
173    private Point mEnd;
174    private IView mView;
175    public IView View {
176      get { return mView; }
177      set { mView = value; }
178    }
179    public Rectangle Rectangle {
180      get {
181        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));
182      }
183      set {
184        //was orginally empty
185        throw new NotImplementedException();
186      }
187    }
188    public Point Start {
189      get {
190        return mStart;
191      }
192      set {
193        mStart = value;
194      }
195    }
196    public Point End {
197      get {
198        return mEnd;
199      }
200      set {
201        mEnd = value;
202      }
203    }
204    protected AbstractGhost(IView view, Point s, Point e)
205      : this(view) {
206      this.mStart = s;
207      this.mEnd = e;
208    }
209    protected AbstractGhost(IView view) {
210      mView = view;
211    }
212    public abstract void Paint(Graphics g);
213  }
214
215  internal enum GhostTypes {
216    Rectangle,
217    Ellipse,
218    Line,
219    MultiLine,
220    CurvedLine,
221    Polygon
222  }
223}
Note: See TracBrowser for help on using the repository browser.