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