|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| package org.ericmignot.modeler.gui.workarea; |
|
19 |
| |
|
20 |
| import java.awt.Point; |
|
21 |
| |
|
22 |
| import org.ericmignot.modeler.data.BusinessObject; |
|
23 |
| import org.ericmignot.modeler.data.Link; |
|
24 |
| import org.ericmignot.modeler.data.Model; |
|
25 |
| import org.ericmignot.modeler.data.SimplePoint; |
|
26 |
| |
|
27 |
| public class LinkItemFactory implements ItemFactory |
|
28 |
| { |
|
29 |
| protected Model model; |
|
30 |
| private BusinessObject initialLinkEnd; |
|
31 |
| |
|
32 |
| private ExtremityFactory extremityFactory; |
|
33 |
| |
|
34 |
132
| public LinkItemFactory()
|
|
35 |
| { |
|
36 |
132
| this.extremityFactory = new ExtremityFactory();
|
|
37 |
| } |
|
38 |
| |
|
39 |
0
| public Model getModel()
|
|
40 |
| { |
|
41 |
0
| return model;
|
|
42 |
| } |
|
43 |
| |
|
44 |
112
| public void setModel(Model model)
|
|
45 |
| { |
|
46 |
112
| this.model = model;
|
|
47 |
| } |
|
48 |
| |
|
49 |
69
| public Item createModelerItems(BusinessObject businessObject, WorkArea workArea)
|
|
50 |
| { |
|
51 |
69
| Link link = (Link) businessObject;
|
|
52 |
69
| this.initialLinkEnd = link.getLinkEnd();
|
|
53 |
| |
|
54 |
69
| if (link.getPoints().length == 0)
|
|
55 |
| { |
|
56 |
68
| LinkItem linkItem = (LinkItem) this.createLinkItem(link, workArea);
|
|
57 |
68
| linkItem.setExtremityStrategy(this.extremityFactory.buildExtremityStrategy(link));
|
|
58 |
68
| return linkItem;
|
|
59 |
| } |
|
60 |
| else |
|
61 |
| { |
|
62 |
1
| Point[] points = link.getPoints();
|
|
63 |
1
| BusinessObject start = link.getLinkStart();
|
|
64 |
1
| BusinessObject end = null;
|
|
65 |
1
| for (int i=0; i < points.length; i++)
|
|
66 |
| { |
|
67 |
2
| end = this.createPoint(points[i]);
|
|
68 |
2
| this.model.addBusinessObject(end);
|
|
69 |
2
| if (i==0)
|
|
70 |
| { |
|
71 |
1
| link.setLinkEnd(end);
|
|
72 |
1
| LinkItem transitionItem = (LinkItem) this.createLinkItem(link, workArea);
|
|
73 |
1
| transitionItem.setExtremityStrategy(this.extremityFactory.buildExtremityStrategy(link));
|
|
74 |
1
| workArea.addItem(transitionItem);
|
|
75 |
| } |
|
76 |
| else |
|
77 |
| { |
|
78 |
1
| Link innerLink = createLink(start, end);
|
|
79 |
1
| this.model.addBusinessObject(innerLink);
|
|
80 |
| } |
|
81 |
2
| start = end;
|
|
82 |
| } |
|
83 |
1
| end = this.initialLinkEnd;
|
|
84 |
1
| Link finalLink = createLink(start, end);
|
|
85 |
1
| this.model.addBusinessObject(finalLink);
|
|
86 |
1
| return null;
|
|
87 |
| } |
|
88 |
| } |
|
89 |
| |
|
90 |
2
| protected BusinessObject createPoint(Point p)
|
|
91 |
| { |
|
92 |
2
| SimplePoint simplePoint = new SimplePoint();
|
|
93 |
2
| simplePoint.setCenter(p);
|
|
94 |
2
| return simplePoint;
|
|
95 |
| } |
|
96 |
| |
|
97 |
2
| protected Link createLink(BusinessObject start, BusinessObject end)
|
|
98 |
| { |
|
99 |
2
| Link link = new Link();
|
|
100 |
2
| link.setLinkStart(start);
|
|
101 |
2
| link.setLinkEnd(end);
|
|
102 |
2
| return link;
|
|
103 |
| } |
|
104 |
| |
|
105 |
69
| protected LinkItem createLinkItem(Link link, WorkArea workArea)
|
|
106 |
| { |
|
107 |
69
| LinkItem linkItem = new LinkItem();
|
|
108 |
69
| linkItem.setBusinessObject(link);
|
|
109 |
69
| linkItem.setLinkStart(workArea.getItemByBusinessObject(link.getLinkStart()));
|
|
110 |
69
| linkItem.setLinkEnd(workArea.getItemByBusinessObject(link.getLinkEnd()));
|
|
111 |
69
| return linkItem;
|
|
112 |
| } |
|
113 |
| |
|
114 |
| |
|
115 |
| |
|
116 |
| |
|
117 |
| } |