-
Notifications
You must be signed in to change notification settings - Fork 8
/
ArchitectureArea.java
1717 lines (1491 loc) · 51.9 KB
/
ArchitectureArea.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Classname : ArchitectureArea
*
* Version information : 1
*
* Date : 2023
*
*/
/******************************
* Copyright (c) 2003--2023 Kevin Lano
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
* *****************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.border.Border;
import java.util.EventObject;
import java.util.Vector;
import java.util.StringTokenizer;
import java.io.*;
import java.awt.print.*;
class ArchitectureArea extends JPanel
implements MouseListener, MouseMotionListener, KeyListener, Printable
{
// these indicate which option the user has chosen from the menu
public static final int INERT = -1;
public static final int SLINES = 0;
public static final int POINTS = 1;
public static final int EVENTS = 2;
public static final int DLINES = 3;
public static final int EDIT = 4;
public static final int LSTATE = 5;
public static final int EXECOCC = 6;
public static final int TANN = 7;
public static final int DANN = 8;
public static final int SOLID = 0;
public static final int DASHED = 1;
public static final int EDITING = 0;
public static final int DELETING = 1;
public static final int MOVING = 2;
public static final int GLUEMOVE = 3;
public static final int RESIZING = 4;
// Solid line -- could be made smaller for thinner line
final static BasicStroke stroke = new BasicStroke(2.0f);
// ArchitectureWin controller;
UCDArea parent;
//Get the screen size for the size of the scroll bar view
private Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
private Dimension preferredSize = screenSize;
// Record mode e.g. Lines, Points etc.
int mode = INERT;
int editMode = EDITING;
private int x1, y1; // x1,y1 store where the mouse has been pressed
private int x2, y2; //end of line coordinates
private boolean firstpress = false;
// True when the user draws a transition or drags mouse
// True if the user pressed, dragged or released the mouse outside of
// the rectangle; false otherwise.
private boolean pressOut = false;
// Dialog definitions
// private EvtNameDialog nameDialog;
// private MessageEditDialog transDialog;
// private StateEdtDialog sDialog;
// private ExecutionEditDialog eDialog;
// private TAEditDialog taDialog;
// private DurationEditDialog durationDialog;
// private EntityCreateDialog entDialog;
// private ScenarioEditDialog scenarioDialog;
Vector visuals = new Vector(); //holds all the points of the elements drawn
Vector waypoints = new Vector();
// Vector lifelines = new Vector(); // UMLObject
// Vector messages = new Vector(); // Message
// Vector executionInstances = new Vector(); // ExecutionInstance
// Vector lifelineStates = new Vector(); // LifelineState
// Vector timeAnnotations = new Vector(); // TimeAnnotation
// Vector durationAnnotations = new Vector(); // DurationAnnotation
private Vector types = new Vector();
private Vector entities = new Vector();
private Vector requirements = new Vector(); // Requirement
private Vector components = new Vector(); // ArchComponent
private Vector usecases = new Vector();
private UMLObject selectedObject = null;
private VisualData selectedVisual = null;
private Message selectedMessage = null;
private LifelineState selectedState = null;
private TimeAnnotation selectedTimeAnnotation = null;
private ExecutionInstance selectedExecution = null;
private ModelElement selectedInterface = null;
private ArchComponent selectedComponent = null;
private Vector glueset = new Vector(); // of GlueSet
// These variables keep a count of all the items created
// They will be replaced with labels at a later stage
private int rectcount = 0;
private int linecount = 0;
public ArchitectureArea(Object controller,
UCDArea par, String s, Vector es)
{ // this.controller = controller;
parent = par;
entities = new Vector();
if (es != null)
{ entities.addAll(es); }
Border raisedBevel = BorderFactory.createRaisedBevelBorder();
Border loweredBevel = BorderFactory.createLoweredBevelBorder();
Border compound =
BorderFactory.createCompoundBorder(raisedBevel, loweredBevel);
setBorder(compound);
setBackground(Color.white);
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this);
}
public Dimension getPreferredSize() {
return preferredSize;
}
public int getMaxX() // maximum x-coord of any shape
{ int max = 0;
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
int x = vd.getx();
if (x > max)
{ max = x; }
}
return max;
}
public int getMinX() // min x-coord of any shape
{ int min = 1000;
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
int x = vd.getx();
if (x < min)
{ min = x; }
}
return min;
}
public int getMaxY() // maximum y-coord of any shape
{ int max = 0;
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
int y = vd.gety();
if (y > max)
{ max = y; }
}
return max;
}
public int getMinY() // min y-coord of any shape
{ int min = 1000;
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
int y = vd.gety();
if (y < min)
{ min = y; }
}
return min;
}
public void shrink(double factor)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
vd.shrink(factor);
}
}
public void moveAllDown(int amount)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
vd.moveDown(amount);
}
}
public void moveAllUp(int amount)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
vd.moveUp(amount);
}
}
public void moveAllLeft(int amount)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
vd.moveLeft(amount);
}
}
public void moveAllRight(int amount)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
vd.moveRight(amount);
}
}
public Vector getVisuals()
{ return visuals; }
public void setVisuals(Vector vis)
{ visuals = vis; }
public void disp_States()
{ for (int i = 0; i < components.size(); i++)
{ System.out.println(components.get(i)); }
}
public void disp_Trans()
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof ProvidedInterfaceLineData)
{ System.out.println(">> Provided interface: " + vd.getModelElement()); }
else if (vd instanceof RequiredInterfaceLineData)
{ System.out.println(">> Required interface: " + vd.getModelElement()); }
}
}
// and time and duration annotations
public void find_src_targ(LineData line, Message strans)
{
for (int i=0; i < visuals.size(); i++)
{
if (visuals.elementAt(i) instanceof LifelineData)
{
LifelineData rd = (LifelineData) visuals.elementAt(i);
if (rd.isUnder(line.xstart,line.ystart))
{
strans.setSource(rd.object);
UMLObject st = strans.source;
System.out.println(" source ==> " + st.label);
}
if (rd.isUnder(line.xend, line.yend))
{
strans.setTarget(rd.object);
UMLObject ta = strans.target;
System.out.println(" target ==> " + ta.label);
}
}
}
}
public void updateModel()
{ // Scan the visuals, adding/removing component interface
// and connections based on the visual layout.
for (int i=0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof RectData)
{ // component
RectData rd = (RectData) vd;
ArchComponent comp =
(ArchComponent) rd.getModelElement();
if (comp == null)
{ continue; }
comp.clearInterfaces();
for (int j = 0; j < visuals.size(); j++)
{ VisualData ld = (VisualData) visuals.get(j);
if (ld instanceof ProvidedInterfaceLineData)
{ ProvidedInterfaceLineData line =
(ProvidedInterfaceLineData) ld;
if (rd.isUnder(line.xstart,line.ystart))
{ comp.addProvidedInterface((Entity)
line.getModelElement());
}
}
else if (ld instanceof RequiredInterfaceLineData)
{ RequiredInterfaceLineData line =
(RequiredInterfaceLineData) ld;
if (rd.isUnder(line.xstart,line.ystart))
{ comp.addRequiredInterface((Entity)
line.getModelElement());
}
}
}
}
else if (vd instanceof LineData)
{ LineData ld = (LineData) vd;
if (ld instanceof ProvidedInterfaceLineData)
{ findConnection((ProvidedInterfaceLineData) ld,
ld.xend, ld.yend);
}
else if (ld instanceof RequiredInterfaceLineData)
{ findConnection((RequiredInterfaceLineData) ld,
ld.xend, ld.yend);
}
}
}
}
public ArchComponent find_src(ProvidedInterfaceLineData line)
{ ModelElement ent = line.getModelElement();
String ename = ent.getName();
for (int i=0; i < visuals.size(); i++)
{
if (visuals.elementAt(i) instanceof RectData)
{
RectData rd = (RectData) visuals.elementAt(i);
if (rd.isUnder(line.xstart,line.ystart) &&
rd.modelElement instanceof ArchComponent)
{
System.out.println(ename + " is a provided interface of ==> " + rd.label);
ArchComponent comp =
(ArchComponent) rd.modelElement;
comp.addProvidedInterface((Entity) ent);
return comp;
}
}
}
return null;
}
public ArchComponent find_src(RequiredInterfaceLineData line)
{ ModelElement ent = line.getModelElement();
String ename = ent.getName();
for (int i=0; i < visuals.size(); i++)
{
if (visuals.elementAt(i) instanceof RectData)
{
RectData rd = (RectData) visuals.elementAt(i);
if (rd.isUnder(line.xstart,line.ystart) &&
rd.modelElement instanceof ArchComponent)
{
System.out.println(ename + " is a required interface of ==> " + rd.label);
ArchComponent comp =
(ArchComponent) rd.modelElement;
comp.addRequiredInterface((Entity) ent);
return comp;
}
}
}
return null;
}
private void findGlueSet()
{ if (selectedVisual instanceof RoundRectData)
{ RoundRectData rd = (RoundRectData) selectedVisual;
int x = rd.getx();
int y = rd.gety();
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof LineData)
{ LineData ld = (LineData) vd;
if (rd.isUnder(ld.getx(),ld.gety()))
{ ld.setStartSelected();
if (rd.isUnder(ld.xend,ld.yend))
{ ld.setMidSelected();
glueset.add(
new GluedVisual(ld,
rd.width/2,
rd.height/2));
}
else
{ glueset.add(
new GluedVisual(ld, ld.getx() - x,
ld.gety() - y));
}
}
else if (rd.isUnder(ld.xend,ld.yend))
{ glueset.add(
new GluedVisual(ld, ld.xend - x,
ld.yend - y));
ld.setEndSelected();
}
}
}
}
}
public void setEditMode(int emode)
{ editMode = emode;
setAppropriateCursor(mode);
}
public void findSelected(int x, int y)
{ boolean found = false;
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.elementAt(i);
if (vd.isUnder(x,y) || vd.isUnderStart(x,y) || vd.isUnderEnd(x,y))
{ selectedVisual = vd;
found = true;
if (vd instanceof RectData)
{ selectedComponent =
(ArchComponent) ((RectData) vd).modelElement;
System.out.println(">>> Selected component: " + selectedComponent);
}
else if (vd instanceof LineData)
{ selectedInterface =
((LineData) vd).modelElement;
System.out.println("Selected interface: " +
selectedInterface);
}
return;
}
}
if (!found)
{ System.out.println("!! No selection -- click on end of a line or in a component area to select");
}
} // and for others
public void findConnection(VisualData self, int x, int y)
{ boolean found = false;
ModelElement me = self.getModelElement();
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.elementAt(i);
if (vd instanceof LineData && vd.isNearEnd(x,y) &&
vd != self)
{ // selectedVisual = vd;
ModelElement connectedInterface =
((LineData) vd).modelElement;
if (self instanceof ProvidedInterfaceLineData &&
vd instanceof RequiredInterfaceLineData)
{ System.out.println(
">>> Assembly connection between " + me +
" and: " +
connectedInterface);
if (connectedInterface != null &&
me != null &&
connectedInterface.getName().equals(
me.getName()))
{ System.out.println(">>> Valid connection"); }
else if (me != null)
{ System.out.println(">>> All operations of " +
connectedInterface + " must be present in: " +
me);
boolean isImp =
((Entity) me).checkIfDefactoImplementation(
(Entity) connectedInterface);
if (isImp)
{ System.out.println(">>> This is a valid assembly connection."); }
else
{ System.out.println("!! This is not a valid assembly connection!"); }
}
else
{ System.out.println("!! No model element found for " + self); }
found = true;
return;
}
else if (self instanceof RequiredInterfaceLineData &&
vd instanceof ProvidedInterfaceLineData)
{ System.out.println(
">>> Assembly connection between " + me +
" and: " +
connectedInterface);
if (connectedInterface != null &&
me != null &&
connectedInterface.getName().equals(
me.getName()))
{ System.out.println(">>> Valid connection"); }
else if (me != null)
{ System.out.println(">>> All operations of " +
me + " must be present in: " +
connectedInterface);
boolean isImp =
((Entity) connectedInterface).checkIfDefactoImplementation(
(Entity) me);
if (isImp)
{ System.out.println(">>> This is a valid assembly connection."); }
else
{ System.out.println("!! This is not a valid assembly connection!"); }
}
else
{ System.out.println("!! No model element found for " + self); }
found = true;
return;
}
}
}
if (!found)
{ System.out.println(">> No connection found for " + me); }
} // and for others
private void resetSelected()
{ selectedVisual = null;
// selectedObject = null;
selectedComponent = null;
// selectedMessage = null;
// selectedTimeAnnotation = null;
glueset.clear();
}
private void editSelected()
{ // if (selectedObject != null)
// { editObject(selectedObject); }
if (selectedComponent != null)
{ editComponent(selectedComponent); }
else if (selectedInterface != null)
{ editInterface(selectedInterface); }
else
{ System.out.println("!! No selection"); }
mode = INERT;
setAppropriateCursor(INERT);
repaint();
}
private void deleteSelected()
{ visuals.remove(selectedVisual); }
private void moveSelected(int oldx, int oldy, int x, int y)
{ if (selectedVisual != null)
{ selectedVisual.changePosition(oldx,oldy,x,y); }
}
private void resizeSelected(int x, int y)
{ if (selectedVisual != null)
{ if (selectedVisual instanceof RectForm)
{ RectForm rf = (RectForm) selectedVisual;
rf.extendTo(x,y);
}
}
}
private void moveGlueSet(int x, int y)
{ moveSelected(0,0,x,y);
for (int i = 0; i < glueset.size(); i++)
{ GluedVisual gv = (GluedVisual) glueset.get(i);
LineData ld = gv.line;
ld.changePosition(0,0,x+gv.xdisp, y+gv.ydisp);
}
}
private void tofrontSelected()
{ if (selectedVisual != null)
{ visuals.remove(selectedVisual);
visuals.add(selectedVisual);
}
} // Not actually used.
public void saveModelDataToFile(String f)
{ File file = new File("output/requirementsmodel.txt");
Vector saved = new Vector();
try
{ PrintWriter out =
new PrintWriter(
new BufferedWriter(new FileWriter(file)));
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof RectData)
{ RectData rd = (RectData) vd;
ArchComponent req = (ArchComponent) rd.modelElement;
req.saveModelData(out);
}
else if (vd instanceof ReqLineData)
{ ReqLineData rld = (ReqLineData) vd;
// out.println("SubgoalRelation:");
RectData rstart = findRectDataAt(rld.xstart,rld.ystart);
RectData rend = findRectDataAt(rld.xend,rld.yend);
if (rstart != null && rend != null && rstart.modelElement != null && rend.modelElement != null)
{ out.println(rstart.modelElement.getName() + " : " + rend.modelElement.getName() + ".subgoals");
out.println();
}
}
}
out.close();
} catch (Exception e) { }
}
public void saveDataToFile(String f)
{ File file = new File("output/architecture.txt");
Vector saved = new Vector();
try
{ PrintWriter out =
new PrintWriter(
new BufferedWriter(new FileWriter(file)));
for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof RectData)
{ RectData rd = (RectData) vd;
ArchComponent req = (ArchComponent) rd.modelElement;
out.println("Component:");
out.println(rd.getx() + " " + rd.gety());
out.println(req.saveData());
out.println();
out.println();
out.println();
}
else if (vd instanceof ProvidedInterfaceLineData)
{ ProvidedInterfaceLineData rld = (ProvidedInterfaceLineData) vd;
out.println("ProvidedInterface:");
out.println(rld.xstart + " " + rld.ystart + " " + rld.xend + " " + rld.yend);
ModelElement elem = rld.getModelElement();
out.println(elem.getName());
out.println();
out.println();
}
else if (vd instanceof RequiredInterfaceLineData)
{ RequiredInterfaceLineData rld = (RequiredInterfaceLineData) vd;
out.println("RequiredInterface:");
out.println(rld.xstart + " " + rld.ystart + " " + rld.xend + " " + rld.yend);
ModelElement elem = rld.getModelElement();
out.println(elem.getName());
out.println();
out.println();
}
}
out.close();
} catch (Exception e) { }
}
public RectData findRectDataAt(int xx, int yy)
{ for (int i = 0; i < visuals.size(); i++)
{ VisualData vd = (VisualData) visuals.get(i);
if (vd instanceof RectData)
{ RectData rd = (RectData) vd;
if (rd.isUnder(xx,yy))
{ return rd; }
}
}
return null;
}
public void loadDataFromFile(String f)
{ BufferedReader br = null;
Vector res = new Vector();
String s;
boolean eof = false;
File file = new File("output/architecture.txt");
try
{ br = new BufferedReader(new FileReader(file)); }
catch (FileNotFoundException e)
{ System.out.println("!! File not found: " + file);
return;
}
while (!eof)
{ try { s = br.readLine(); }
catch (IOException e)
{ System.out.println("!! Reading failed.");
return;
}
if (s == null)
{ eof = true;
break;
}
else if (s.equals("Component:"))
{ parseComponent(br); }
else if (s.equals("ProvidedInterface:"))
{ parseProvidedInterface(br); }
else if (s.equals("RequiredInterface:"))
{ parseRequiredInterface(br); }
}
try { br.close(); } catch(IOException e) { }
}
private void parseComponent(BufferedReader br)
{ String line1 = ""; // x y
String line2 = ""; // name id
String line3 = ""; // text
String line4 = ""; // kind
String line5 = ""; // scope
Vector line1vals = new Vector();
Vector line2vals = new Vector();
try { line1 = br.readLine(); }
catch (IOException e)
{ System.err.println("Reading component details failed"); }
StringTokenizer st1 =
new StringTokenizer(line1);
try { line2 = br.readLine(); }
catch (IOException e)
{ System.err.println("Reading component details failed"); }
StringTokenizer st2 =
new StringTokenizer(line2);
while (st1.hasMoreTokens())
{ line1vals.add(st1.nextToken()); }
while (st2.hasMoreTokens())
{ line2vals.add(st2.nextToken()); }
if (line1vals.size() < 2) { return; }
String xs = (String) line1vals.get(0);
String ys = (String) line1vals.get(1);
int x = Integer.parseInt(xs);
int y = Integer.parseInt(ys);
if (line2vals.size() < 1) { return; }
String nme = (String) line2vals.get(0);
// String id = (String) line2vals.get(1);
// String txt = line3.trim();
// String kind = line4.trim();
// String scope = line5.trim();
ArchComponent req = new ArchComponent(nme);
// if ("true".equals(scope))
// { req.setScope("local"); }
RectData rd = new RectData(x,y,
getForeground(),
0,
rectcount);
rectcount++;
components.add(req);
visuals.addElement(rd);
rd.setModelElement(req); // why not?
rd.setLabel(nme);
repaint();
}
private void parseProvidedInterface(BufferedReader br)
{ String line1 = ""; // x1 y1 x2 y2
Vector line1vals = new Vector();
String line2 = ""; // Name
Vector line2vals = new Vector();
try { line1 = br.readLine(); }
catch (IOException e)
{ System.err.println("!! Reading interface details failed"); }
StringTokenizer st1 =
new StringTokenizer(line1);
while (st1.hasMoreTokens())
{ line1vals.add(st1.nextToken()); }
if (line1vals.size() < 4)
{ System.err.println("!! Incomplete interface details");
return;
}
String x1s = (String) line1vals.get(0);
String y1s = (String) line1vals.get(1);
int x1 = Integer.parseInt(x1s);
int y1 = Integer.parseInt(y1s);
String x2s = (String) line1vals.get(2);
String y2s = (String) line1vals.get(3);
int x2 = Integer.parseInt(x2s);
int y2 = Integer.parseInt(y2s);
ProvidedInterfaceLineData dline =
new ProvidedInterfaceLineData(
x1,y1,x2,y2,linecount,SOLID);
visuals.addElement(dline);
try { line2 = br.readLine(); }
catch (IOException e)
{ System.err.println("!! Reading interface details failed"); }
StringTokenizer st2 =
new StringTokenizer(line2);
while (st2.hasMoreTokens())
{ line2vals.add(st2.nextToken()); }
if (line2vals.size() < 1) { return; }
String nme = (String) line2vals.get(0);
Entity ent = addInterfaceIfNotExisting(nme);
findConnection(dline,x2,y2);
dline.setModelElement(ent);
find_src(dline);
repaint();
}
private void parseRequiredInterface(BufferedReader br)
{ String line1 = ""; // x1 y1 x2 y2
Vector line1vals = new Vector();
String line2 = ""; // Name
Vector line2vals = new Vector();
try { line1 = br.readLine(); }
catch (IOException e)
{ System.err.println("!! Reading interface details failed"); }
StringTokenizer st1 =
new StringTokenizer(line1);
while (st1.hasMoreTokens())
{ line1vals.add(st1.nextToken()); }
if (line1vals.size() < 4)
{ System.err.println("!! Incomplete interface details");
return;
}
String x1s = (String) line1vals.get(0);
String y1s = (String) line1vals.get(1);
int x1 = Integer.parseInt(x1s);
int y1 = Integer.parseInt(y1s);
String x2s = (String) line1vals.get(2);
String y2s = (String) line1vals.get(3);
int x2 = Integer.parseInt(x2s);
int y2 = Integer.parseInt(y2s);
RequiredInterfaceLineData dline =
new RequiredInterfaceLineData(
x1,y1,x2,y2,linecount,SOLID);
try { line2 = br.readLine(); }
catch (IOException e)
{ System.err.println("!! Reading interface details failed"); }
StringTokenizer st2 =
new StringTokenizer(line2);
while (st2.hasMoreTokens())
{ line2vals.add(st2.nextToken()); }
if (line2vals.size() < 1) { return; }
String nme = (String) line2vals.get(0);
Entity ent = addInterfaceIfNotExisting(nme);
dline.setModelElement(ent);
visuals.addElement(dline);
find_src(dline);
findConnection(dline,x2,y2);
repaint();
}
public void synthesiseJava()
{ for (int i = 0; i < components.size(); i++)
{ ArchComponent comp = (ArchComponent) components.get(i);
String compName = comp.getName();
String lcname = compName.toLowerCase();
String interfacesDefinitions = "";
Vector pinterfaces = comp.getProvidedInterfaces();
for (int j = 0; j < pinterfaces.size(); j++)
{ Entity pint = (Entity) pinterfaces.get(j);
interfacesDefinitions =
interfacesDefinitions +
"/* Interface specification: */\n" +
pint.getKM3() + "\n\n";
}
Vector rinterfaces = comp.getRequiredInterfaces();
for (int j = 0; j < rinterfaces.size(); j++)
{ Entity rint = (Entity) rinterfaces.get(j);
interfacesDefinitions =
interfacesDefinitions +
"/* Interface specification: */\n" +
rint.getKM3() + "\n\n";
}
String res = "package " + lcname + ";\n\n" +
interfacesDefinitions +
"class " + compName;
if (pinterfaces.size() > 0)
{ res = res + " implements "; }
for (int j = 0; j < pinterfaces.size(); j++)
{ Entity pint = (Entity) pinterfaces.get(j);
res = res + pint.getName();
if (j < pinterfaces.size() - 1)
{ res = res + ", "; }
}
res = res + "\n{\n";
String constr = " public " + compName + "(";
String assignments = "";
for (int j = 0; j < rinterfaces.size(); j++)
{ Entity rint = (Entity) rinterfaces.get(j);
String rname = rint.getName();
String rx = rname.toLowerCase() + "_x";
res = res + " " + rname + " " + rx + ";\n";
constr = constr + rname + " " + rx;
if (j < rinterfaces.size()-1)
{ constr = constr + ", "; }
assignments = assignments + " this." + rx + " = " + rx + ";\n";
}
constr = constr + ") {\n" + assignments + " }\n";
res = res + "\n" + constr + "}\n";
System.out.println(res);
System.out.println();
}
}
private Entity addInterfaceIfNotExisting(String jname)
{ Entity pint =
(Entity) ModelElement.lookupByName(jname,entities);
if (pint == null)
{ if (parent != null)
{ Vector pents = parent.getEntities();
Entity pxint =
(Entity) ModelElement.lookupByName(jname,pents);
if (pxint == null)
{ pint = new Entity(jname);
pint.setInterface(true);
int xx = (entities.size() + 1)*150;
int yy = 200;
parent.addEntity(pint,xx,yy);
}
else
{ pint = pxint; }
}
entities.add(pint);
}
else if (parent != null)
{ Vector pents = parent.getEntities();
Entity pxint = (Entity) ModelElement.lookupByName(jname,
pents);
if (pxint == null)
{ // pint = new Entity(jname);
pint.setInterface(true);
int xx = (pents.size() + 1)*150;
int yy = 200;
parent.addEntity(pint,xx,yy);
}
}
return pint;
}
private Entity addEntityIfNotExisting(String jname)
{ Entity pint =
(Entity) ModelElement.lookupByName(jname,entities);
if (pint == null)
{ pint = new Entity(jname);
// pint.setInterface(true);
int xx = (entities.size() + 1)*150;
int yy = 500;
if (parent != null)
{ parent.addEntity(pint,xx,yy); }
entities.add(pint);
}
else if (parent != null)
{ Vector pents = parent.getEntities();
Entity pxint = (Entity) ModelElement.lookupByName(jname,
pents);
if (pxint == null)
{ // pint = new Entity(jname);
int xx = (pents.size() + 1)*150;
int yy = 500;
parent.addEntity(pint,xx,yy);
}
}
return pint;
}
public void synthesiseKM3()
{ for (int i = 0; i < components.size(); i++)
{ ArchComponent comp = (ArchComponent) components.get(i);
String compName = comp.getName();
Entity compEnt = addEntityIfNotExisting(compName);
String lcname = compName.toLowerCase();