summaryrefslogtreecommitdiff
path: root/index.html
blob: fcdf709d6bfc803ff600e5cd6cfc3c2fd0059924 (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
<html>

<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="utf-8" http-equiv="encoding">
    <title>Xcos</title>

    <!-- Loads and initializes the library -->
    <script type="text/javascript" src="jquery/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="mxClient.min.js"></script>
    <script type="text/javascript" src="jquery/farbtastic.js"></script>

    <link rel="stylesheet" href="jquery/farbtastic.css" type="text/css" />
    <link rel="stylesheet" href="jquery/jquery-ui.css">

    <script type="text/javascript" src="details.js"></script>
    <script type="text/javascript" src="setup.js"></script>
    <script type="text/javascript" src="combined.js"></script>
    <script type="text/javascript" src="orientation.js"></script>

    <script type="text/javascript">
        // Stores edgeState for every recently created edge in updateFixedTerminalPoint() function
        var edgeState = {};

        function main(container, outline, toolbar, sidebar, status) {
            // Checks if the browser is supported
            if (!mxClient.isBrowserSupported()) {
                // Displays an error message if the browser is not supported.
                mxUtils.error('Browser is not supported!', 200, false);
            } else {
                // If connect preview is not moved away then getCellAt is used to detect the cell under
                // the mouse if the mouse is over the preview shape in IE (no event transparency), ie.
                // the built-in hit-detection of the HTML document will not be used in this case.
                mxConnectionHandler.prototype.movePreviewAway = false;
                mxConnectionHandler.prototype.waypointsEnabled = true;
                mxGraph.prototype.resetEdgesOnConnect = false;

                // Enables guides
                mxGraphHandler.prototype.guidesEnabled = true;

                // Alt disables guides
                mxGuide.prototype.isEnabledForEvent = function(evt) {
                    return !mxEvent.isAltDown(evt);
                };

                // Enables snapping waypoints to terminals
                mxEdgeHandler.prototype.snapToTerminals = true;

                // Assigns some global constants for general behaviour, eg. minimum
                // size (in pixels) of the active region for triggering creation of
                // new connections, the portion (100%) of the cell area to be used
                // for triggering new connections, as well as some fading options for
                // windows and the rubberband selection.
                mxConstants.MIN_HOTSPOT_SIZE = 16;
                mxConstants.DEFAULT_HOTSPOT = 1;

                // Workaround for Internet Explorer ignoring certain CSS directives
                if (mxClient.IS_QUIRKS) {
                    document.body.style.overflow = 'hidden';
                    new mxDivResizer(container);
                    new mxDivResizer(outline);
                    new mxDivResizer(toolbar);
                    new mxDivResizer(sidebar);
                    new mxDivResizer(status);
                }

                // Creates a wrapper editor with a graph inside the given container.
                // The editor is used to create certain functionality for the
                // graph, such as the rubberband selection, but most parts
                // of the UI are custom in this example.
                var editor = new mxEditor();
                var graph = editor.graph;
                var model = graph.getModel();

                /*
                    Maverick
                    The following variable 'diagRoot' serves as the root element for the entire
                    diagram.
                */
                var diagRoot = new XcosDiagram(null, model, null);
                graph.setPanning(true);
                graph.setConnectable(true);
                graph.setConnectableEdges(true);
                graph.setDisconnectOnMove(false);
                graph.foldingEnabled = false;

                // Disable highlight of cells when dragging from toolbar
                graph.setDropEnabled(false);

                // Centers the port icon on the target port
                graph.connectionHandler.targetConnectImage = true;

                // Does not allow dangling edges
                graph.setAllowDanglingEdges(false);

                // Sets the graph container and configures the editor
                editor.setGraphContainer(container);

                // Disables built-in context menu
                mxEvent.disableContextMenu(document.body);

                // Configures automatic expand on mouseover
                graph.panningHandler.autoExpand = true;

                /*
                  @jiteshjha, @pooja
                          Overrides mxGraphModel.getStyle to return a specific style
                          for edges that reflects their target terminal.
                */

                graph.model.getStyle = function(cell) {
                    var style = null;
                    if (cell != null) {
                        // Get style for the recently created mxCell.
                        style = mxGraphModel.prototype.getStyle.apply(this, arguments);
                        // If the mxCell is an edge and if it's a fully formed edge
                        if (this.isEdge(cell) && cell.source != null) {
                            var target = this.getTerminal(cell, false);
                            if (target != null) {
                                /* cell.name attribute defines the link name
                                   so that it can be parsed in the XML during
                                   XSLT transformation.
                                */
                                var cellSource = cell.source;
                                while (cellSource.isEdge() == true) {
                                    cellSource = cellSource.source;
                                }
                                if (cellSource.value == "ExplicitOutputPort" || cellSource.value == "ExplicitInputPort") {
                                    if (style == null) {
                                        style = 'ExplicitLink' + ';';
                                    }
                                    cell.name = "ExplicitLink";
                                } else if (cellSource.value == "ImplicitOutputPort" || cellSource.value == "ImplicitInputPort") {
                                    if (style == null) {
                                        style = 'ImplicitLink' + ';';
                                    }
                                    cell.name = "ImplicitLink";
                                } else if (cellSource.value == "CommandPort" || cellSource.value == "ControlPort") {
                                    if (style == null) {
                                        style = 'CommandControlLink' + ';';
                                    }
                                    cell.name = "CommandControlLink";
                                }
                            }
                        }
                    }
                    return style;
                };


                // Creates a right-click menu
                graph.panningHandler.factoryMethod = function(menu, cell, evt) {

                    if (cell != null) {

                        if (cell.value == "ExplicitInputPort" || cell.value == "ExplicitOutputPort" || cell.value == "CommandPort" || cell.value == "ControlPort") {

                        } else if (cell.isEdge() == true) // @ToDo: Pooja: Different edge value cases.
                        {

                            menu.addItem('Delete', 'images/delete2.png', function() {
                                editor.execute('deleteBlock');
                            });
                            var edgeformat = menu.addItem('Format', null, null);

                            menu.addItem('Border Color', 'images/draw-brush.png', function() {
                                showColorWheel(graph, cell, 'edgeStrokeColor');

                            }, edgeformat);
                            menu.addItem('Text and Text Font', 'images/edit.png', function() {
                                showTextEditWindow(graph, cell);
                            }, edgeformat);
                            menu.addItem('Text Color', 'images/edit.png', function() {
                                showColorWheel(graph, cell, 'edgeTextColor');
                            }, edgeformat);

                        } else {
                            menu.addItem('Block Parameters...', 'images/gear.gif', function() {
                                showPropertiesWindow(graph, cell);
                            });

                            menu.addItem('Cut', 'images/cut.png', function() {
                                editor.execute('cut');
                            });
                            menu.addItem('Copy', 'images/copy.png', function() {
                                editor.execute('copy');
                            });
                            menu.addItem('Delete', 'images/delete2.png', function() {
                                editor.execute('delete');
                            });

                            menu.addItem('Selection to superblock', 'images/superblock.png', function() {
                                // @ToDo: Functionality to be put.
                            });
                            var formatMenu = menu.addItem('Format', null, null);
                            menu.addItem('Rotate', 'images/rotate.png', function() {
                                editor.execute('rotateCustom');
                            }, formatMenu);
                            menu.addItem('Flip', 'images/flip.png', function() {
                                editor.execute('flipCustom');
                            }, formatMenu);
                            menu.addItem('Mirror', 'images/mirror.png', function() {
                                editor.execute('mirrorCustom');
                            }, formatMenu);
                            menu.addItem('Border Color', 'images/draw-brush.png', function() {
                                showColorWheel(graph, cell, 'vertexStrokeColor');
                            }, formatMenu);
                            menu.addItem('Fill Color', 'images/edit.png', function() {
                                showColorWheel(graph, cell, 'vertexFillColor');
                            }, formatMenu);
                            menu.addItem('Details', null, function() {
                                // @ToDo: Functionality to be put.
                            });
                        }
                    } else {
                        menu.addItem('Undo', 'images/undo.png', function() {
                            editor.execute('undo');
                        });
                        menu.addItem('Redo', 'images/redo.png', function() {
                            editor.execute('redo');
                        });
                        menu.addItem('Paste', 'images/paste.png', function() {
                            editor.execute('paste');
                        });

                        menu.addItem('Select all', 'images/selectall.png', function() {
                            editor.execute('selectAll');
                        });

                        /*
                            Maverick
                            Added one more parameter to the setContext function.
                        */
                        menu.addItem('Set Context', null, function() {
                            showSetContext(graph, diagRoot);
                        });

                        /*
                            Maverick
                            Added one more parameter to the setContext function.
                        */
                        menu.addItem('Setup', 'images/setup.png', function() {
                            showSetupWindow(graph, diagRoot);
                        });


                        menu.addItem('Zoom In', 'images/zoom_in.png', function() {
                            editor.execute('zoomIn');
                        });
                        menu.addItem('Zoom Out', 'images/zoom_out.png', function() {
                            editor.execute('zoomOut');
                        });
                        menu.addItem('Diagram background...', null, function() {
                            showColorWheel(graph, cell, 'bgColor');
                        });
                    }

                };

                //var config = mxUtils.load('config/editor-commons.xml').getDocumentElement();
                var config = mxUtils.load('config/keyhandler-commons.xml').getDocumentElement();
                editor.configure(config);

                graph.isCellSelectable = function(cell) {
                    if (cell.isConnectable() == true && cell.isEdge() == false) {
                        return false;
                    }
                    return true;
                };

                graph.resizeCell = function(cell, bounds, recurse) {
                    if (cell.getStyle() == 'Split') {
                        return null;
                    } else {
                        return mxGraph.prototype.resizeCell.apply(this, arguments);
                    }
                }

                /*
                  For a new edge on the graph, check if that edge satisfies one of the port constraints.
                  Possible edge cases with source & target :
                  1) Source : Port, Target : Port
                  2) Source : Edge, Target : Port
                  3) Source : Port, Target : Edge
                  4) Source : Edge, Target : Edge
                */
                graph.addEdge = function(edge, parent, source, target, index) {

                    if (source.isEdge() == true && target.isEdge() == true) {
                        alert("Illegal connection! - Link to link connection");
                        return null;
                    }

                    // If the edge is legit, return the edge.
                    if (source.isEdge() == true) {
                        graph.getModel().beginUpdate();
                        try {
                            var edgeSource = source;

                            // While the source of the edge is an edge, find the final port
                            while (edgeSource.isEdge() == true) {
                                edgeSource = edgeSource.source;
                            }

                            // If the edge violates any of the port constraints, don't create the edge
                            if (edgeSource.value == "ExplicitOutputPort" && target.value != "ExplicitInputPort") {
                                alert("Explicit data output port must be connected to explicit data input port");
                                return null;
                            } else if (edgeSource.value == "ExplicitInputPort" && target.value != "ExplicitOutputPort") {
                                alert("Explicit data input port must be connected to explicit data output port");
                                return null;
                            } else if (edgeSource.value == "ImplicitOutputPort" && target.value != "ImplicitInputPort") {
                                alert("Implicit data output port must be connected to implicit data input port");
                                return null;
                            } else if (edgeSource.value == "ImplicitInputPort" && target.value != "ImplicitOutputPort") {
                                alert("Implicit data input port must be connected to implicit data output port");
                                return null;
                            } else if (edgeSource.value == "CommandPort" && target.value != "ControlPort") {
                                alert("Command port must be connected to control port");
                                return null;
                            } else if (edgeSource.value == "ControlPort" && target.value != "CommandPort") {
                                alert("Control port must be connected to command port");
                                return null;
                            }

                            // Create the splitBlock
                            // (x-5, y-5.5) is the offset to correct the position of split-block
                            var cell = graph.insertVertex(graph.getDefaultParent(), null, '', source.sourcePoint.x - 5, source.sourcePoint.y - 5.5, 10, 10, 'Split', false);



                            // Get the source state
                            var sourceState = graph.view.getState(source);
                            var waypoints = source.waypoints;
                            var waypoints1 = [];

                            // Add the absolute points for source edge to waypoints variable
                            for (i in sourceState.absolutePoints) {
                                waypoints1.push(sourceState.absolutePoints[i]);
                            }

                            // Remove source and target points
                            waypoints1.shift();
                            waypoints1.pop();

                            // Store the waypoints to the source edge
                            waypoints = waypoints1;

                            // Find the index in the waypoints nearest to the split-block
                            var seg = mxUtils.findNearestSegment(sourceState, source.sourcePoint.x, source.sourcePoint.y);
                            var sourceTarget = source.target;

                            // Set the type of ports for split-block according to type of source edge
                            if (edgeSource.value == 'ExplicitOutputPort') {
                                createPorts(graph, cell, ['E'], [], ['E'], ['E']);
                            } else if (edgeSource.value == 'ImplicitOutputPort') {
                                createPorts(graph, cell, ['I'], [], ['I', 'I'], []);
                            } else {
                                createPorts(graph, cell, ['CONTROL'], [], ['COMMAND', 'COMMAND'], []);
                            }

                            // Source edge is replaced with first edge and futureSource edges
                            cell.name = 'SPLIT_f';

                            // Hide all the ports of a split-block
                            cell.getChildAt(0).setVisible(false);
                            cell.getChildAt(1).setVisible(false);
                            cell.getChildAt(2).setVisible(false);

                            // Remove the current source
                            graph.removeCells([source], true);

                            /*
                             * If there are any waypoints, divide them for the two newly created edges.
                             * The two newly created edges are inherited from the source edge
                             */
                            if (waypoints != null) {
                                var waypoints1 = [];
                                for (var i = 0; i < seg; i++) {
                                    waypoints1.push(waypoints[i]);
                                }

                                var waypoints2 = [];
                                for (var i = seg; i < waypoints.length; i++) {
                                    waypoints2.push(waypoints[i]);
                                }
                            }

                            // Find the waypoints of the current edge, and set the waypoints for the new thirdEdge
                            var waypoints3 = edgeState.absolutePoints;
                            if (waypoints3 != null && waypoints3.length > 1) {
                                // Remove last absolute point
                                waypoints3.pop();
                            }

                            // Create three edges associated with the split-block
                            var firstEdge = createEdgeObject(graph, cell.getChildAt(1), sourceTarget, waypoints2);
                            var thirdEdge = createEdgeObject(graph, cell.getChildAt(2), target, waypoints3);
                            var futureSource = createEdgeObject(graph, source.source, cell.getChildAt(0), waypoints1);

                            // Set the newly made futureSource as the source
                            source = futureSource;

                            // Connectable for the ports and the split-block should be false
                            cell.getChildAt(0).setConnectable(false);
                            cell.getChildAt(1).setConnectable(false);
                            cell.getChildAt(2).setConnectable(false);
                            cell.setConnectable(false);

                            // Get the parent of the splitBlock
                            var parent = graph.model.getParent(cell);

                            graph.model.beginUpdate();
                            try {
                                /*
                                 * Adds the split-block to the parent at the last index
                                 * Enables split-block to appear over it's associated edges
                                 */
                                graph.model.add(parent, cell, graph.model.getChildCount(parent) - 1);
                            } finally {
                                graph.model.endUpdate();
                            }

                            graph.refresh();
                        } finally {
                            graph.getModel().endUpdate();
                        }

                        /*
                         * Remove the current edge, as we have already created
                         * thirdEdge as it's replacement, to enable waypoints.
                         */
                        return null;
                    }

                    // If the edge is legit, return the edge.
                    if (target.isEdge() == true) {
                        graph.getModel().beginUpdate();
                        try {
                            var edgeSource = target;

                            // While the source of the edge is an edge, find the final port
                            while (edgeSource.isEdge() == true) {
                                edgeSource = edgeSource.source;
                            }

                            // If the edge violates any of the port constraints, don't create the edge
                            if (source.value == "ExplicitOutputPort" && edgeSource.value != "ExplicitInputPort") {
                                alert("Explicit data output port must be connected to explicit data input port");
                                return null;
                            } else if (source.value == "ExplicitInputPort" && edgeSource.value != "ExplicitOutputPort") {
                                alert("Explicit data input port must be connected to explicit data output port");
                                return null;
                            } else if (source.value == "ImplicitOutputPort" && edgeSource.value != "ImplicitInputPort") {
                                alert("Implicit data output port must be connected to implicit data input port");
                                return null;
                            } else if (source.value == "ImplicitInputPort" && edgeSource.value != "ImplicitOutputPort") {
                                alert("Implicit data input port must be connected to implicit data output port");
                                return null;
                            } else if (source.value == "CommandPort" && edgeSource.value != "ControlPort") {
                                alert("Command port must be connected to control port");
                                return null;
                            } else if (source.value == "ControlPort" && edgeSource.value != "CommandPort") {
                                alert("Control port must be connected to command port");
                                return null;
                            }

                            // Create the splitBlock
                            // (x-5, y-5.5) is the offset to correct the position of split-block
                            var cell = graph.insertVertex(graph.getDefaultParent(), null, '', target.sourcePoint.x - 5, target.sourcePoint.y - 5, 10, 10, 'Split', false);

                            // Get the source state
                            var sourceState = graph.view.getState(target);
                            var waypoints = target.waypoints;
                            var waypoints1 = [];

                            // Add the absolute points for source edge to waypoints variable
                            for (i in sourceState.absolutePoints) {
                                waypoints1.push(sourceState.absolutePoints[i]);
                            }
                            waypoints1.shift();
                            waypoints1.pop();
                            waypoints = waypoints1;

                            // Find the index in the waypoints nearest to the split-block
                            var seg = mxUtils.findNearestSegment(sourceState, target.sourcePoint.x, target.sourcePoint.y);
                            var sourceTarget = target.target;

                            if (edgeSource.value == 'ExplicitOutputPort') {
                                createPorts(graph, cell, ['E'], [], ['E'], ['E']);

                            } else if (edgeSource.value == 'ImplicitOutputPort') {
                                createPorts(graph, cell, ['I'], [], ['I', 'I'], []);
                            } else {
                                createPorts(graph, cell, ['CONTROL'], [], ['COMMAND', 'COMMAND'], []);
                            }

                            // Source edge is replaced with first edge and futureSource edges
                            cell.name = 'SPLIT_f';

                            // Hide all the ports of a split-block
                            cell.getChildAt(0).setVisible(false);
                            cell.getChildAt(1).setVisible(false);
                            cell.getChildAt(2).setVisible(false);

                            // Remove the current source
                            graph.removeCells([target], true);

                            /*
                             * If there are any waypoints, divide them for the two newly created edges.
                             * The two newly created edges are inherited from the source edge
                             */
                            if (waypoints != null) {
                                var waypoints1 = [];
                                for (var i = 0; i < seg; i++) {
                                    waypoints1.push(waypoints[i]);
                                }

                                var waypoints2 = [];
                                for (var i = seg; i < waypoints.length; i++) {
                                    waypoints2.push(waypoints[i]);
                                }
                            }

                            // Find the waypoints of the current edge, and set the waypoints for the new thirdEdge
                            var waypoints3 = edgeState.absolutePoints;
                            if (waypoints3 != null && waypoints3.length > 1) {
                                waypoints3.pop();
                            }
                            waypoints3.reverse();

                            // Create three edges associated with the split-block
                            var firstEdge = createEdgeObject(graph, cell.getChildAt(1), sourceTarget, waypoints2);
                            var thirdEdge = createEdgeObject(graph, cell.getChildAt(2), source, waypoints3);
                            var futureSource = createEdgeObject(graph, target.source, cell.getChildAt(0), waypoints1);

                            // Set the newly made futureSource as the source
                            target = futureSource;

                            // Connectable for the ports and the split-block should be false
                            cell.getChildAt(0).setConnectable(false);
                            cell.getChildAt(1).setConnectable(false);
                            cell.getChildAt(2).setConnectable(false);
                            cell.setConnectable(false);

                            // Get the parent of the splitBlock
                            var parent = graph.model.getParent(cell);

                            graph.model.beginUpdate();
                            try {
                                /*
                                 * Adds the split-block to the parent at the last index
                                 * Enables split-block to appear over it's associated edges
                                 */
                                graph.model.add(parent, cell, graph.model.getChildCount(parent) - 1);
                            } finally {
                                graph.model.endUpdate();
                            }

                            graph.refresh();
                        } finally {
                            graph.getModel().endUpdate();
                        }

                        /*
                         * Remove the current edge, as we have already created
                         * thirdEdge as it's replacement, to enable waypoints.
                         */
                        return null;
                    }

                    // If the newly created edge is related to a splitBlock, make the edge.
                    if (source.parent.name == 'SPLIT_f' || target.parent.name == 'SPLIT_f') {
                        return mxGraph.prototype.addEdge.apply(this, arguments);
                    }

                    var edgeSource = source;

                    // If the source of the edge is also an edge, find the port.
                    while (edgeSource.isEdge() == true) {
                        edgeSource = edgeSource.source;
                    }

                    // For port-to-port edges with port constraint violations, don't create that edge
                    if (source.getEdgeCount() > 0 || target.getEdgeCount() > 0) {
                        alert("Port is already connected, please select an please select an unconnected port or a valid link");
                    } else if (edgeSource.value == "ExplicitOutputPort" && target.value != "ExplicitInputPort") {
                        alert("Explicit data output port must be connected to explicit data input port");
                    } else if (edgeSource.value == "ExplicitInputPort" && target.value != "ExplicitOutputPort") {
                        alert("Explicit data input port must be connected to explicit data output port");
                    } else if (edgeSource.value == "ImplicitOutputPort" && target.value != "ImplicitInputPort") {
                        alert("Implicit data output port must be connected to implicit data input port");
                    } else if (edgeSource.value == "ImplicitInputPort" && target.value != "ImplicitOutputPort") {
                        alert("Implicit data input port must be connected to implicit data output port");
                    } else if (edgeSource.value == "CommandPort" && target.value != "ControlPort") {
                        alert("Command port must be connected to control port");
                    } else if (edgeSource.value == "ControlPort" && target.value != "CommandPort") {
                        alert("Control port must be connected to command port");
                    } else {

                        /*
                         * For reverse edges, (that is, edges from input port to outport) :
                         * If the source is input port, and target is an output port
                         * NOTE: Manipulation of source object and target object
                         *       with respect to current edge is not possible,
                         *       as mxGraph.prototype.addEdge(@parameters) function is
                         *       called just before the creation of the edge.
                         *       Hence, the following code creates a identical new edge
                         *       to replace the current edge.
                         */

                        if ((source.value.indexOf('Input') != -1 && target.value.indexOf('Output') != -1) ||
                            (target.value == 'CommandPort' && source.value == 'ControlPort')) {

                            // Get points for the current edge from the global edgeState object
                            var waypoints = edgeState.absolutePoints;

                            // Reverse waypoint array
                            waypoints.reverse();

                            // Create a new edge
                            var newEdge = createEdgeObject(graph, target, source, waypoints);

                            // Return null for the current edge,

                            /*
                             * Return null for the current edge,
                             * since we have created a new edge above to replace it
                             */
                            return null;
                        }
                        // If the edge is legit, return the edge.
                        return mxGraph.prototype.addEdge.apply(this, arguments);
                    }
                    return null;
                }

                // Shows a "modal" window when double clicking a vertex.
                graph.dblClick = function(evt, cell) {
                    // Do not fire a DOUBLE_CLICK event here as mxEditor will
                    // consume the event and start the in-place editor.
                    if (this.isEnabled() &&
                        !mxEvent.isConsumed(evt) &&
                        cell != null &&
                        this.isCellEditable(cell)) {
                        if (!this.isHtmlLabel(cell)) {
                            this.startEditingAtCell(cell);
                        } else {
                            /*
                            var content = document.createElement('div');
                            content.innerHTML = this.convertValueToString(cell);
                            showModalWindow(this, 'Properties', content, 400, 300);
                            */
                            if (cell.isVertex() == true) {
                                showPropertiesWindow(graph, cell);
                            }
                        }
                    }

                    // Disables any default behaviour for the double click
                    mxEvent.consume(evt);
                };

                // Returns a shorter label if the cell is collapsed and no
                // label for expanded groups
                graph.getLabel = function(cell) {
                    var tmp = mxGraph.prototype.getLabel.apply(this, arguments); // "supercall"
                    if (this.isCellLocked(cell)) {
                        // Returns an empty label but makes sure an HTML
                        // element is created for the label (for event
                        // processing wrt the parent label)
                        return '';
                    } else if (this.isCellCollapsed(cell)) {
                        var index = tmp.indexOf('</h1>');
                        if (index > 0) {
                            tmp = tmp.substring(0, index + 5);
                        }
                    }
                    return tmp;
                }

                // Disables HTML labels for swimlanes to avoid conflict
                // for the event processing on the child cells. HTML
                // labels consume events before underlying cells get the
                // chance to process those events.
                //
                // NOTE: Use of HTML labels is only recommended if the specific
                // features of such labels are required, such as special label
                // styles or interactive form fields. Otherwise non-HTML labels
                // should be used by not overidding the following function.
                // See also: configureStylesheet.
                graph.isHtmlLabel = function(cell) {
                    return !this.isSwimlane(cell);
                }

                graph.getTooltipForCell = function(cell) {
                    var text = null;
                    if (cell.isVertex() == true && cell.isConnectable() == false) {
                        var name = cell.value.getAttribute('blockElementName');
                        var cellvar = cell.blockInstance.instance.details();

                        // If cell is a block or ports
                        if (cell.source == null && cell.target == null) {
                            if (cell.connectable) { // Cell is a Port
                                // @ToDo: Port Number
                                text = 'Style : ' + cell.style + "\n";
                            } else { //Cell is a block
                                // @ToDo: Block Name, Simulation, Flip, Mirror
                                // @ToDo: Number of Input, Output, Control, Command Ports
                                var inputPort, outputPort, controlPort, commandPort;
                                if (cellvar.model.in.height == null) {
                                    inputPort = 0;
                                }
                                else {
                                    inputPort = cellvar.model.in.height;
                                }
                                if (cellvar.model.out.height == null) {
                                    outputPort = 0;
                                }
                                else {
                                    outputPort = cellvar.model.out.height;
                                }
                                if (cellvar.model.evtin.height == null) {
                                    controlPort = 0;
                                }
                                else {
                                    controlPort = cellvar.model.evtin.height;
                                }
                                if (cellvar.model.evtout.height == null) {
                                    commandPort = 0;
                                }
                                else {
                                    commandPort = cellvar.model.evtout.height;
                                }

                                var flip = false, mirror = false;
                                var style = cell.style;
                                var styleObject = styleToObject(style);
                                if(styleObject['stencilFlipV'] == null){
                                    flip = false;
                                }
                                else
                                {
                                    
                                    if(styleObject['stencilFlipV'] == 0){
                                        flip = false;
                                    }
                                    else{
                                        flip = true;
                                    }

                                }
                                if(styleObject['stencilFlipH'] == null){
                                    mirror = false;
                                }
                                else
                                {
                                   
                                    if(styleObject['stencilFlipH'] == 0 ){
                                        mirror = false;
                                    }
                                    else{
                                        mirror = true;
                                    }

                                }
                                style = objectToStyle(styleObject);
                                var geometry = cell.getGeometry();
                                text = 'Block Name : ' + cell.value.getAttribute('blockElementName') + "\n" +
                                    'Simulation : ' + cell.value.getAttribute('simulationFunctionName') + "\n" +
                                    'UID : ' + cell.id + "\n" +
                                    'Style : ' + cell.style + "\n" +
                                    'Flip : ' + flip + "\n" +
                                    'Mirror : ' + mirror + "\n" +
                                    'Input Ports : ' + inputPort + "\n" +
                                    'Output Ports : ' + outputPort + "\n" +
                                    'Control Ports : ' + controlPort + "\n" +
                                    'Command Ports : ' + commandPort + "\n" +
                                    'x : ' + geometry.x + "\n" +
                                    'y : ' + geometry.y + "\n" +
                                    'w : ' + geometry.width + "\n" +
                                    'h : ' + geometry.height + "\n";
                            }
                        }
                    }
                    return text;
                };

                // Create XML tags!
                // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
                // https://jgraph.github.io/mxgraph/docs/js-api/files/model/mxCell-js.html
                // Uncomment this block to see XML tags work
                graph.convertValueToString = function(cell) {

                    if (mxUtils.isNode(cell.value)) {
                        var stylesheet = graph.getStylesheet();
						var attribute = cell.value.getAttribute('style');
                        if(attribute == null){
                            attribute = cell.value.getAttribute('interfaceFunctionName');
                        }
                        var style = stylesheet.styles[attribute];
						var displayedLabel = style['displayedLabel'];
                        if (displayedLabel != null) {
                            var displayParameter = cell.blockInstance.instance.displayParameter;
                            for (i in displayParameter) {
                                displayedLabel = displayedLabel.replace("%s", displayParameter[i].toString());
                            }
                            return displayedLabel;
                        } else {
                            return cell.getAttribute('label', '');
                        }
                    }
                };

                var cellLabelChanged = graph.cellLabelChanged;
                graph.cellLabelChanged = function(cell, newValue, autoSize) {
                    if (mxUtils.isNode(cell.value)) {
                        // Clones the value for correct undo/redo
                        var elt = cell.value.cloneNode(true);
                        elt.setAttribute('label', newValue);
                        newValue = elt;
                    }

                    cellLabelChanged.apply(this, arguments);
                };

                // Enables new connections
                graph.setConnectable(true);

                // Adds all required styles to the graph (see below)
                configureStylesheet(graph);

                // Adds sidebar icons.
                addIcons(graph, sidebar);

                // Creates a new DIV that is used as a toolbar and adds
                // toolbar buttons.
                var spacer = document.createElement('div');
                spacer.style.display = 'inline';
                spacer.style.padding = '8px';

                // Defines a new export action
                editor.addAction('toggle', function(editor, cell) {
                    var toggle = document.getElementById("toggleBlocks");
                    var button = document.getElementById("toggle");
                    toggle.click();
                    button.innerHTML = '';
                    if (toggle.innerHTML == 'Expand All') {
                        createButtonImage(button, 'images/navigate_plus.png');
                    } else if (toggle.innerHTML == 'Collapse All') {
                        createButtonImage(button, 'images/navigate_minus.png');
                    }
                    var titleName = document.createTextNode(toggle.innerHTML);
                    button.appendChild(titleName);
                });

                /*
                 * @jiteshjha, @pooja
                 * rotateCustom(@parameters) is defined in 'orientation.js'
                 */
                editor.addAction('rotateCustom', function(editor, cell) {
                    rotateCustom(editor, graph, cell);
                });

                /*
                 * @jiteshjha, @pooja
                 * flipCustom(@parameters) is defined in 'orientation.js'
                 */
                editor.addAction('flipCustom', function(editor, cell) {
                    flipCustom(editor, graph, cell);
                });

                /*
                 * @jiteshjha, @pooja
                 * mirrorCustom(@parameters) is defined in 'orientation.js'
                 */
                 editor.addAction('mirrorCustom', function(editor, cell) {
                    mirrorCustom(editor, graph, cell);
                });

                // @jiteshjha, @pooja
                /*
                   On selection and deletion of any block, 'deleteBlock'
                   function deletes all the associated edges with that block.
                   Used Preorder traversal for edges.
                */
                editor.addAction('deleteBlock', function(editor, cell) {
                    graph.getModel().beginUpdate();
                    try {

                        // getEdgeId(@edgeObject) finds all the associated edges and split-block, and deletes them
                        function getEdgeId(edgeObject) {

                            var cellStack = [];
                            if (edgeObject != null && edgeObject.isEdge() == true) {
                                cellStack.push(edgeObject);
                                while (cellStack.length != 0) {
                                    var tempEdgeObject = cellStack.pop();
                                    if (tempEdgeObject.edge == true && (cells.indexOf(tempEdgeObject) == -1)) {
                                        cells.push(tempEdgeObject);
                                    }

                                    // If the edge is associated with a split-block(source is a split-block)
                                    if (tempEdgeObject.source.parent.name == "SPLIT_f") {
                                        if (tempEdgeObject.source == tempEdgeObject.source.parent.getChildAt(1)) {

                                            var sourceEdge = tempEdgeObject.source.parent.getChildAt(0).getEdgeAt(0);
                                            var target = tempEdgeObject.source.parent.getChildAt(2).getEdgeAt(0).target;

                                            // If the state of the edge is not null
                                            if (graph.view.getState(sourceEdge) != null) {

                                                // Find waypoints for the first edge related to split-block
                                                var waypoints1 = graph.view.getState(sourceEdge).absolutePoints;

                                                // Find the waypoints for the second edge related to split-block
                                                var waypoints2 = graph.view.getState(tempEdgeObject.source.parent.getChildAt(2).getEdgeAt(0)).absolutePoints;
                                                waypoints2.shift();
                                                for (i in waypoints2) {
                                                    waypoints1.push(waypoints2[i]);
                                                }
                                                var geometry = graph.getModel().getGeometry(sourceEdge);
                                                var cloneGeometry = geometry.clone();

                                                cloneGeometry.points = waypoints1;
                                                graph.getModel().setGeometry(sourceEdge, cloneGeometry);
                                                graph.refresh();

                                                // Shift the target for the first edge related to splitBlock
                                                graph.getModel().setTerminal(sourceEdge, target, false);
                                            }
                                            cells.push(tempEdgeObject.source.parent);
                                        } else {
                                            var sourceEdge = tempEdgeObject.source.parent.getChildAt(0).getEdgeAt(0);
                                            var target = tempEdgeObject.source.parent.getChildAt(1).getEdgeAt(0).target;

                                            // If the state of the edge is not null
                                            if (graph.view.getState(sourceEdge) != null) {

                                                // Find waypoints for the first edge related to split-block
                                                var waypoints1 = graph.view.getState(sourceEdge).absolutePoints;

                                                // Find the waypoints for the second edge related to split-block
                                                var waypoints2 = graph.view.getState(tempEdgeObject.source.parent.getChildAt(1).getEdgeAt(0)).absolutePoints;
                                                waypoints1.pop();
                                                waypoints2.shift();
                                                for (i in waypoints2) {
                                                    waypoints1.push(waypoints2[i]);
                                                }
                                                var geometry = graph.getModel().getGeometry(sourceEdge);
                                                var cloneGeometry = geometry.clone();

                                                cloneGeometry.points = waypoints1;
                                                graph.getModel().setGeometry(sourceEdge, cloneGeometry);
                                                graph.refresh();

                                                // Shift the target for the first edge related to splitBlock
                                                graph.getModel().setTerminal(sourceEdge, target, false);
                                            }
                                            cells.push(tempEdgeObject.source.parent);
                                        }

                                    }

                                    // If the edge is associated with a split-block(target is a split-block)
                                    if (tempEdgeObject.target.parent.name == "SPLIT_f") {
                                        if (cells.indexOf(tempEdgeObject.target.parent) == -1) {
                                            cells.push(tempEdgeObject.target.parent);
                                        }
                                        cellStack.push(tempEdgeObject.target.parent.getChildAt(1).getEdgeAt(0));
                                        cellStack.push(tempEdgeObject.target.parent.getChildAt(2).getEdgeAt(0));
                                    }
                                }
                            }
                        }

                        var cells = [];

                        // Get all selected cells
                        var selectionCells = graph.getSelectionCells();

                        // For each cell in the selection
                        for (var k = 0; k < selectionCells.length; k++) {

                            // If the cell is an edge, directly call getEdgeId(@parameter) for deletion
                            if (selectionCells[k].isEdge() == true) {
                                getEdgeId(selectionCells[k]);
                            }

                            // If the cell is a vertex, select the cell
                            else {
                                var portCount = selectionCells[k].getChildCount();
                                cells.push(selectionCells[k]);
                                for (var i = 0; i < portCount; i++) {
                                    var edgeCount = selectionCells[k].getChildAt(i).getEdgeCount();
                                    if (edgeCount != 0) {

                                        /*
                                         * For every edge associated with the current selected cell,
                                         * call the getEdgeId(@parameter), parameter is an edgeObject for deletion
                                         */

                                        for (var j = 0; j < edgeCount; j++) {
                                            var edgeObject = selectionCells[k].getChildAt(i).getEdgeAt(j);
                                            getEdgeId(edgeObject);
                                        }
                                    }
                                }
                            }
                        }

                        graph.removeCells(cells, true);
                    } finally {
                        graph.getModel().endUpdate();
                    }

                });

                addToolbarButton(editor, toolbar, 'toggle', 'Expand All', 'images/navigate_plus.png');
                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'cut', 'Cut', 'images/cut.png');
                addToolbarButton(editor, toolbar, 'copy', 'Copy', 'images/copy.png');
                addToolbarButton(editor, toolbar, 'paste', 'Paste', 'images/paste.png');

                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'deleteBlock', 'Delete', 'images/delete2.png');
                addToolbarButton(editor, toolbar, 'undo', '', 'images/undo.png');
                addToolbarButton(editor, toolbar, 'redo', '', 'images/redo.png');
                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'show', 'Show', 'images/camera.png');
                addToolbarButton(editor, toolbar, 'print', 'Print', 'images/printer.png');

                toolbar.appendChild(spacer.cloneNode(true));


                /*
                    Maverick
                    This method is used for loading the stylesheet from the file.
                    Reference: http://www.w3schools.com/xsl/xsl_client.asp
                  */

                function loadXMLDoc(filename) {
                    if (window.ActiveXObject) {
                        xhttp = new ActiveXObject("Msxml2.XMLHTTP");
                    } else {
                        xhttp = new XMLHttpRequest();
                    }
                    xhttp.open("GET", filename, false);
                    try {
                        xhttp.responseType = "msxml-document"
                    } catch (err) {}
                    xhttp.send("");
                    return xhttp.responseXML;
                }


                /*
                 Maverick
                 The Export buttons in toolbar call this function with varying
                 arguments.
                 The third argument is used to deciFde which button is being
                 pressed.
                 exportXML : 2 arguments
                 exportXcos: 3 arguments
                 */
                function displayXMLorXcos() {
                    var textarea = document.createElement('textarea');
                    textarea.style.width = '400px';
                    textarea.style.height = '400px';

                    var enc = new mxCodec(mxUtils.createXmlDocument());
                    var node = enc.encode(diagRoot);

                    var str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + mxUtils.getPrettyXml(node);

                    textarea.value = str;

                    if (arguments[2] == null) {
                        showModalWindow(graph, 'XML', textarea, 410, 440);
                    } else {

                        return mxUtils.getPrettyXml(node);
                    }
                }

                function getXcosDiagram(editor, cell) {
                    //Mind the 3 parameters.
                    var xmlFromExportXML = displayXMLorXcos(editor, cell, true);
                    if (xmlFromExportXML === null)
                        alert('First create the XML file.');
                    else {

                        var xml = mxUtils.parseXml(xmlFromExportXML);

                        var xsl = loadXMLDoc("finalmodsheet.xsl");

                        xsltProcessor = new XSLTProcessor();
                        xsltProcessor.importStylesheet(xsl);
                        resultDocument = xsltProcessor.transformToDocument(xml);
                        /*
                         Maverick
                         Using resultDocument.documentElement to remove an additional tag "<#document>" created by the XSLTProcessor.
                         */
                        var str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" + mxUtils.getPrettyXml(resultDocument.documentElement);

                        str = str.replace(/\n\n/g, "\n");
                        return str;
                    }
                }

                // Defines a new export action
                editor.addAction('exportXML', function(editor, cell) {
                    //Only two parameters passed here.
                    displayXMLorXcos(editor, cell);
                });

                /* Maverick
                 Reference: http://www.w3schools.com/xsl/xsl_client.asp
                 */

                editor.addAction('exportXcos', function(editor, cell) {
                    var textarea = document.createElement('textarea');
                    textarea.style.width = '400px';
                    textarea.style.height = '400px';
                    textarea.value = getXcosDiagram(editor, cell);
                    showModalWindow(graph, 'Xcos', textarea, 410, 440);
                });

                /*
                    Maverick
                    Adding a new button to import an Xcos diagram to our GUI and perform the simulation 
                    on the remote server.
                    The flow of control is as follows:
                    The entire XML document is traversed, beginning from the root node.
                    The document is traversed three times: 
                    1. All the blocks are appended on the graph. 
                    2. All the ports are added to the blocks.
                    3. All the links are made.

                    Old ids are the ones which can be found from the imported file but when the blocks are added 
                    to the graph mxGraph assigns new ids to them. 
                    Careful mapping needs to be done between these two ids.
                */
                editor.addAction('importXcos', function(editor, cell) {
                    var xmlDocument = '';
                    var div = document.createElement('div');
                    var node = document.createElement('form');
                    div.setAttribute("id", "tempdiv");
                    div.setAttribute("style", "height:200;width:200");

                    /*
                        Maverick
                        Implementing a file picker to choose the Xcos diagram.
                    */
                    var fileNode = document.createElement('input');
                    fileNode.type = 'file';
                    if (!(window.File && window.FileReader && window.Blob && window.FileList)) {
                        alert('This browser doesn\'t support this feature.');
                        return;
                    }

                    node.id = "tempform";
                    node.appendChild(fileNode);
                    var textArea = document.createElement('textarea');
                    textArea.setAttribute("rows", "15");
                    textArea.setAttribute("cols", "60");
                    textArea.setAttribute("name", "tarea");
                    node.appendChild(textArea);
                    var button = document.createElement('button');
                    button.innerHTML = 'Submit';
                    button.type = "button";
                    button.name = "submit";
                    node.appendChild(button);
                    
                    /*
                        Maverick
                        Reference: www.htmlgoodies.com
                    */
                    fileNode.addEventListener('change', function(evt) {

                        var f = evt.target.files[0];
                        var r = new FileReader();
                        r.onload = function(e) {
                            var contents = e.target.result;
                            /*
                                Maverick
                                The following regular expressions are used to format the imported Xcos XML
                                according to the format that is recognized by the mxCodec decoder.
                            */
                            xmlDocument = contents;
                            //RegEx to replace all the newline characters.
                            xmlDocument = xmlDocument.replace(/\n*/, '');
                            //RegEx to replace all the space characters between any a closing and the next opening tag.
                            xmlDocument = xmlDocument.replace(/>\s*</g, '><');
                            //RegEx to replace all the XML comments.
                            xmlDocument = xmlDocument.replace(/<!--[\s\S]*?-->/g, '');
                            textArea.value = xmlDocument;

                        }

                        r.readAsText(f);
                    }, false);

                    /*
                        Maverick
                        A dictionary is used to perform the mapping between the old ids and the new ids.
                        See explanation at the beginning of the function!!!
                    */
                    var nodeDataObject = {};

                    button.onclick = function() {

                        wind.destroy();

                        graph.model.beginUpdate();
                        try {
                            var parent = graph.getDefaultParent();
                            var doc = mxUtils.parseXml(xmlDocument);
                            var codec = new mxCodec(doc);
                            var rootNode = doc.documentElement;
                            /*
                                Maverick
                                Extracting 'Setup Window' values from Xcos diagram and setting the same 
                                on the new diagram.
                            */
                            var defaultProperties = setup("get");
                            var propertiesObject = {};

                            for (var key in defaultProperties) {
                                if (defaultProperties.hasOwnProperty(key)) {
                                    propertiesObject[defaultProperties[key][1]] = rootNode.getAttribute(defaultProperties[key][1]);
                                    /*    
                                        Maverick
                                        Adding the corresponding attributes to the <XcosDiagram> tag.
                                    */
                                    diagRoot[defaultProperties[key][1]] = rootNode.getAttribute(defaultProperties[key][1]);
                                }
                            }

                            setup("set", propertiesObject);



                            while (rootNode.nodeName != 'root') {

                                /*
                                    Maverick
                                    Extracting 'Set Context' values from Xcos diagram and setting the same 
                                    on the new diagram.
                                */
                                if (rootNode.nodeName == 'Array') {

                                    var contextValues = [];

                                    var contextChild = rootNode.firstChild;

                                    while (contextChild != null) {
                                        contextValues.push(contextChild.getAttribute('value'));
                                        contextChild = contextChild.nextSibling;
                                    }

                                    diagRoot.context = contextValues;
                                    diagRoot.context.scilabClass = "String[]";
                                    handleContext("set", contextValues);
                                    rootNode = rootNode.nextSibling;
                                } else {

                                    rootNode = rootNode.firstChild;
                                }

                            }

                            var cells = [];
                            var currentNode = rootNode.firstChild;
                            while (currentNode != null) {
                                var curNodeName = currentNode.nodeName;

                                var cell = codec.decode(currentNode);

                                var curId = currentNode.getAttribute('id');

                                /*
                                    Maverick
                                    Finding the mxGeometry node for all the nodes.
                                */
                                var geometryNode = currentNode.firstChild;
                                var geometryCell = null;

                                if (geometryNode != null) {
                                    while (geometryNode != null && geometryNode.nodeName != 'mxGeometry') {
                                        geometryNode = geometryNode.nextSibling;
                                    }
                                    if (geometryNode != null) {
                                        geometryCell = codec.decode(geometryNode);
                                    }
                                }
                                /*
                                    Maverick
                                    Adding the blocks.
                                    Finding out the constructor names for all the blocks which are not a port or a link.
                                    Ports will be automatically handled with the respective constructor calls.
                                */
                                if (!(curNodeName.endsWith('Link') || curNodeName.endsWith('Port'))) {
                                    var ifaceFuncName = cell.interfaceFunctionName;

                                    /*
                                        Maverick
                                        The following data structure is used to store the information required for each block
                                        to the subsequent mapping.
                                    */
                                    var temporaryMapObject = new Object();
                                    temporaryMapObject.inputArray = [];
                                    temporaryMapObject.outputArray = [];
                                    temporaryMapObject.controlArray = [];
                                    temporaryMapObject.commandArray = [];
                                    temporaryMapObject.inputIds = [];
                                    temporaryMapObject.outputIds = [];
                                    temporaryMapObject.controlIds = [];
                                    temporaryMapObject.commandIds = [];


                                    var details_instance = null;
                                    if (ifaceFuncName != null) {

                                        details_instance = new window[ifaceFuncName]();
                                    }
                                    if (details_instance != null) {
                                        var details = details_instance.define();
                                        var enc = new mxCodec(mxUtils.createXmlDocument());
                                        var node = enc.encode(details);
                                        var temp = enc.encode(parent);
                                        var stylesheet = graph.getStylesheet();
                                        var styleName = currentNode.getAttribute('style');
                                        if (styleName.indexOf(';') != -1) {
                                            styleName = styleName.substring(0, styleName.indexOf(';'));
                                        }
                                        var style = stylesheet.styles[styleName];


                                        /*
                                         * When a particular block is loaded for the first time,
                                         * the image in the style of the block will be a path to the image.
                                         * Set the label in the style property of the block has a html image,
                                         * and set the image in the style property as null
                                         *
                                         * NOTE: Since the image of any block need not be changed for
                                         *       for every movement of that block, the image must be
                                         *       set only once.
                                         */
                                        if (style != null && style['image'] != null) {

                                            // Make label as a image html element
                                            var label = '<img src="' + style['image'] + '" height="80" width="80">';

                                            // Set label
                                            style['label'] = label;
                                            style['imagePath'] = style['image'];
                                            // Set image as null
                                            style['image'] = null;

                                            // Add the label as a part of node
                                            node.setAttribute('label', label);
                                        }

                                        /*
                                         * If a particular block with image tag in it's style property
                                         * has been invoked already, the image tag would be null for any
                                         * successive instances of the same block. Hence, set the label
                                         * from the label tag in style which was set when that blockModel
                                         * was invoked on the first time.
                                         */
                                        if (style != null && style['label'] != null) {

                                            // Set label from the label field in the style property
                                            node.setAttribute('label', style['label']);
                                        }
                                        node.setAttribute('parent', temp.getAttribute('id'));

                                        var blockModel = details_instance.x.model;
                                        var graphics = details_instance.x.graphics;


                                        var v1 = graph.insertVertex(graph.getDefaultParent(), null, node, geometryCell.x, geometryCell.y, 80, 80, ifaceFuncName);
                                        // @Chhavi: Additional attribute to store the block's instance
                                        v1.blockInstance = createInstanceTag(details_instance);
                                        temporaryMapObject.newId = v1.id;

                                        nodeDataObject[curId] = temporaryMapObject;

                                        //findAndCreatePorts(graph,v1,doc,curId,codec);
                                        //createPorts(graph, v1, inputPorts, controlPorts, outputPorts, commandPorts);

                                        v1.setConnectable(false);
                                    }

                                    /*
                                        Maverick
                                        Handling SplitBlock in a different manner.
                                    */
                                    if (curNodeName == 'SplitBlock') {
                                        // (x-5, y-5.5) is the offset to correct the position of split-block
                                        var v1 = graph.insertVertex(graph.getDefaultParent(), null, '', geometryCell.x - 5, geometryCell.y - 5.5, 10, 10, 'Split', false);
                                        temporaryMapObject.newId = v1.id;
                                        nodeDataObject[curId] = temporaryMapObject;
                                        v1.setConnectable(false);
                                    }
                                }

                                if (curNodeName.endsWith('Port')) {

                                    var oldParentId = currentNode.getAttribute('parent');
                                    var newParentObj = nodeDataObject[oldParentId];
                                    var newParentId = newParentObj.newId;

                                    var newParentCell = graph.getModel().getCell(newParentId);
                                    if (curNodeName == 'ExplicitInputPort') {
                                        newParentObj.inputArray.push('E');
                                        newParentObj.inputIds.push(curId);
                                    }
                                    if (curNodeName == 'ImplicitInputPort') {
                                        newParentObj.inputArray.push('I');
                                        newParentObj.inputIds.push(curId);
                                    }
                                    if (curNodeName == 'ExplicitOutputPort') {
                                        newParentObj.outputArray.push('E');
                                        newParentObj.outputIds.push(curId);
                                    }
                                    if (curNodeName == 'ImplicitOutputPort') {
                                        newParentObj.outputArray.push('I');
                                        newParentObj.outputIds.push(curId);
                                    }
                                    if (curNodeName == 'CommandPort') {
                                        newParentObj.commandArray.push('COMMAND');
                                        newParentObj.commandIds.push(curId);
                                    }
                                    if (curNodeName == 'ControlPort') {
                                        newParentObj.controlArray.push('CONTROL');
                                        newParentObj.controlIds.push(curId);
                                    }
                                }

                                //To continue traversal of all the nodes.
                                currentNode = currentNode.nextSibling;
                            }

                            /*
                                Maverick
                                Adding the ports.
                            */
                            currentNode = rootNode.firstChild;
                            while (currentNode != null) {
                                var curNodeName = currentNode.nodeName;
                                /*
                                    Maverick
                                    Handling all the ports of a given block collectively.
                                */
                                if (!(curNodeName.endsWith('Port') || curNodeName.endsWith('Link'))) {
                                    var curId = currentNode.getAttribute('id');
                                    var newParentObj = nodeDataObject[curId];
                                    if (newParentObj != null) {
                                        var newParentId = newParentObj.newId;

                                        var newParentCell = graph.getModel().getCell(newParentId);
                                        createPorts(graph, newParentCell, newParentObj.inputArray, newParentObj.controlArray, newParentObj.outputArray, newParentObj.commandArray, newParentObj, nodeDataObject);
                                    }
                                }
                                currentNode = currentNode.nextSibling;
                            }

                            /*
                                Maverick
                                Connecting the links. 
                            */
                            
                            currentNode = rootNode.firstChild;
                            while (currentNode != null) {
                                var curNodeName = currentNode.nodeName;
                                if (curNodeName.endsWith('Link')) {

                                    var pointsArray = [];
                                    var newSourceObj = nodeDataObject[currentNode.getAttribute('source')];
                                    var newTargetObj = nodeDataObject[currentNode.getAttribute('target')];

                                    var newSourceCell = graph.getModel().getCell(newSourceObj.newId);
                                    var newTargetCell = graph.getModel().getCell(newTargetObj.newId);

                                    var childNode = currentNode.firstChild;
                                    if (childNode != null) {
                                        if (childNode.nodeName == 'mxGeometry') {
                                            var tempNode = childNode.firstChild;
                                            if (tempNode != null) {
                                                if (tempNode.nodeName == 'mxPoint') {
                                                    pointsArray.push(new mxPoint(tempNode.getAttribute('x'), tempNode.getAttribute('y')));
                                                } else {
                                                    if (tempNode.nodeName == 'Array') {
                                                        var mxPointNode = tempNode.firstChild;
                                                        while (mxPointNode != null) {
                                                            pointsArray.push(new mxPoint(mxPointNode.getAttribute('x'), mxPointNode.getAttribute('y')));
                                                            mxPointNode = mxPointNode.nextSibling;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    createEdgeObject(graph, newSourceCell, newTargetCell, null);
                                }
                                currentNode = currentNode.nextSibling;
                            }

                        } finally {
                            graph.model.endUpdate();
                        }

                    }

                    div.appendChild(node);

                    node.style.visibility = "visible";
                    var wind = showModalWindow(graph, 'Set Context', div, 410, 440);
                });


                addToolbarButton(editor, toolbar, 'importXcos', 'Import Xcos', 'images/export1.png');
                addToolbarButton(editor, toolbar, 'exportXML', 'Export XML', 'images/export1.png');
                addToolbarButton(editor, toolbar, 'exportXcos', 'Export Xcos', 'images/export1.png');

                toolbar.appendChild(spacer.cloneNode(true));

                addToolbarButton(editor, toolbar, 'simulate', 'Simulate', 'images/ScilabExecute.png');

                editor.addAction('simulate', function(editor, cell) {
                    var diagram = getXcosDiagram(editor, cell);

                    var blob = new Blob([diagram], {
                        type: 'text/plain'
                    });
                    var xhr = new XMLHttpRequest();
                    xhr.open('POST', 'servlet/SciExec', true);
                    xhr.onload = function() {
                        // Create basic structure for the form
                        var content = document.createElement('div');
                        content.setAttribute("id", "contentProperties");

                        // Heading of content
                        var heading = document.createElement('h2');
                        heading.innerHTML = "Set Scope Parameters";
                        heading.id = "headingProperties";
                        content.appendChild(heading);

                        var paragraph = document.createElement("p");
                        paragraph.innerHTML = xhr.responseText;
                        content.appendChild(paragraph);


                        var img = document.createElement("img");
                        img.src = xhr.responseText;
                        content.appendChild(img);

                        var wind = showModalWindow(graph, 'Properties', content, 1000, 1000);
                    };
                    xhr.onreadystatechange = function() {
                        console.log("state: " + xhr.readyState);
                    };
                    xhr.upload.onprogress = function() {
                        console.log("uploading...");
                    };
                    xhr.setRequestHeader("Content-Type", "text/plain");
                    xhr.send(blob);
                });

                // Adds toolbar buttons into the status bar at the bottom
                // of the window.

                addToolbarButton(editor, status, 'zoomIn', '', 'images/zoom_in.png', true);
                addToolbarButton(editor, status, 'zoomOut', '', 'images/zoom_out.png', true);
                addToolbarButton(editor, status, 'actualSize', '', 'images/view_1_1.png', true);
                addToolbarButton(editor, status, 'fit', '', 'images/fit_to_size.png', true);

                // Creates the outline (navigator, overview) for moving
                // around the graph in the top, right corner of the window.
                var outln = new mxOutline(graph, outline);

                // To show the images in the outline, uncomment the following code
                //outln.outline.labelsVisible = true;
                //outln.outline.setHtmlLabels(true);

                // Fades-out the splash screen after the UI has been loaded.
                var splash = document.getElementById('splash');
                if (splash != null) {
                    try {
                        mxEvent.release(splash);
                        mxEffects.fadeOut(splash, 100, true);
                    } catch (e) {

                        // mxUtils is not available (library not loaded)
                        splash.parentNode.removeChild(splash);
                    }
                }

                // Handles cursor keys - guides.html
                var nudge = function(keyCode) {
                    if (!graph.isSelectionEmpty()) {
                        var dx = 0;
                        var dy = 0;
                        if (keyCode == 37) {
                            dx = -5;
                        } else if (keyCode == 38) {
                            dy = -5;
                        } else if (keyCode == 39) {
                            dx = 5;
                        } else if (keyCode == 40) {
                            dy = 5;
                        }
                        graph.moveCells(graph.getSelectionCells(), dx, dy);
                    }
                };
                // Transfer initial focus to graph container for keystroke handling
                // graph.container.focus();
                // Handles keystroke events
                var keyHandler = new mxKeyHandler(graph);
                keyHandler.bindKey(37, function() {
                    nudge(37);
                });
                keyHandler.bindKey(38, function() {
                    nudge(38);
                });
                keyHandler.bindKey(39, function() {
                    nudge(39);
                });
                keyHandler.bindKey(40, function() {
                    nudge(40);
                });

                // Starts connections on the background in wire-mode
                var connectionHandlerIsStartEvent = graph.connectionHandler.isStartEvent;
                graph.connectionHandler.isStartEvent = function(me) {
                    return connectionHandlerIsStartEvent.apply(this, arguments);
                };

                // Avoids any connections for gestures within tolerance except when in wire-mode
                // or when over a port
                var connectionHandlerMouseUp = graph.connectionHandler.mouseUp;
                graph.connectionHandler.mouseUp = function(sender, me) {
                    if (this.first != null && this.previous != null) {
                        var point = mxUtils.convertPoint(this.graph.container, me.getX(), me.getY());
                        var dx = Math.abs(point.x - this.first.x);
                        var dy = Math.abs(point.y - this.first.y);

                        if (dx < this.graph.tolerance && dy < this.graph.tolerance) {
                            // Selects edges in non-wire mode for single clicks, but starts
                            // connecting for non-edges regardless of wire-mode
                            if (this.graph.getModel().isEdge(this.previous.cell)) {
                                this.reset();
                            }

                            return;
                        }
                    }

                    connectionHandlerMouseUp.apply(this, arguments);
                };

                mxEvent.disableContextMenu(container);

                // @Adhitya: Add focus to a mxCell
                if (mxClient.IS_NS) {
                    mxEvent.addListener(graph.container, 'mousedown', function(evt) {
                        if (!graph.isEditing()) {
                            graph.container.setAttribute('tabindex', '-1');
                            graph.container.focus();
                        }
                    });
                }

            }
        };

        /*
          @jiteshjha
          styleToObject(style) converts style string into an object.
          Format : First item in the object will be 'default: linkStyle',
          and the rest of items will be of the style 'mxConstants:value'
        */

        function styleToObject(style) {
            if (style.indexOf(';') == -1) {
                style = style + ';';
            }
            else if ( style[style.length-1] != ';'){
            	style = style + ';';
        	}
            var defaultStyle = style.substring(0, style.indexOf(';'));
            var styleObject = {
                "default": defaultStyle
            };
            var remainingStyle = style.substring(style.indexOf(';') + 1);

            /*
              remainingStyle is the string without the default style.
              For every key:value pair in the string,
              extract the key(string before '=') and the value
              (string before ';'), set the key:value pair into styleObject
              and remainingStyle is set to a string without the key:value pair.
            */
            while (remainingStyle.length > 0) {
                var indexOfKey = remainingStyle.indexOf('=');
                var key = remainingStyle.substring(0, indexOfKey);
                remainingStyle = remainingStyle.substring(indexOfKey + 1);
                var indexOfValue = remainingStyle.indexOf(';');
                var value = remainingStyle.substring(0, indexOfValue);
                styleObject[key] = value;
                remainingStyle = remainingStyle.substring(indexOfValue + 1);
            }

            return styleObject;
        }

        /*
          @jiteshjha
          styleToObject(style) converts the object back to the style string.
        */
        function objectToStyle(object) {
            var style = "";
            for (var key in object) {
                if (key.toString() == "default") {
                    style += object[key] + ';';
                } else {
                    style += (key + '=' + object[key] + ';');
                }
            }
            return style;
        }

        /*
            Maverick
            The following function is used to define a tag for entire diagram.
            We can set context, model and setup parameters for the entire diagram
            using this function.
        */


        function XcosDiagram(context, model, attributes) {
            this.context = context;
            this.model = model;
            this.finalIntegrationTime = attributes;
        }


        /*
          @jiteshjha, @pooja
          setContext dialog box
          Includes a set context instruction text and input text area.
        */

        /*
            Maverick
            Added 'diagRoot' parameter.
        */
        function showSetContext(graph, diagRoot) {

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "setContext");

            // Add Form
            var myform = document.createElement("form");
            myform.method = "";
            myform.setAttribute("id", "formProperties");

            // Add set context string
            var descriptionSetContext = document.createElement("div");
            descriptionSetContext.innerHTML = "You may enter here scilab instructions to define symbolic parameters used in block definitions using Scilab instructions. These instructions are evaluated once confirmed(i.e. you click on OK and every time the diagram is loaded)";
            descriptionSetContext.setAttribute("id", "descriptionSetContext");
            myform.appendChild(descriptionSetContext);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // input text area
            var textareaSetContext = document.createElement("textarea");
            textareaSetContext.setAttribute("id", "textareaSetContext");

            myform.appendChild(textareaSetContext);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Ok';
            btn.type = "button";
            btn.name = "submit";
            btn.setAttribute("id", "buttonSetContext");

            var contextValue = handleContext("get");

            var displayValue = "";

            /*
                Maverick
                Modified the for loop because only requirement was to
                traverse the array of 'contextValue' and not all the
                elements of it.
            */
            for (var i = 0; i < contextValue.length; i++) {
                displayValue += contextValue[i] + "\n";
            }
            if (contextValue != "") {
                textareaSetContext.value = displayValue;
            } else {
                textareaSetContext.value = "";

            }

            // Executes when button 'btn' is clicked
            btn.onclick = function() {

                var input = document.getElementById('textareaSetContext').value;

                /*
                    Maverick
                    Code to extract context parameter values from the text area
                    containing the input.
                */
                var contextValues = [];
                var i = 0,
                    temp = "";
                for (i = 0; i < input.length; i++) {
                    if (input[i] == '\n') {
                        if (temp != "") {
                            contextValues.push(temp);
                        }
                        temp = "";
                        continue;
                    }
                    temp += input[i];
                }
                if (temp != "") {
                    contextValues.push(temp);
                }

                diagRoot.context = contextValues;
                diagRoot.context.scilabClass = "String[]";
                handleContext("set", contextValues);
                wind.destroy();
            };

            myform.appendChild(btn);
            content.appendChild(myform);
            var wind = showModalWindow(graph, 'Set Context', content, 450, 350);
        };

        function showPropertiesWindow(graph, cell) {

            var name = cell.getAttribute('blockElementName');
            var defaultProperties = cell.blockInstance.instance.get(); //window[name]("get");
            /*{
                nbr_curves: ["Number of curves", 1],
                clrs: ["color (>0) or mark (<0)", [1, 2, 3, 4, 5, 6, 7, 13]],
                siz: ["line or mark size", [1, 1, 1, 1, 1, 1, 1, 1]],
                win: ["Output window number (-1 for automatic)", -1],
                wpos: ["Output window position", [-1, -1]],
                wdim: ["Output window sizes", [-1, -1]],
                vec_x: ["Xmin and Xmax", [-15, 15]],
                vec_y: ["Ymin and Ymax", [-15, 15]],
                vec_z: ["Zmin and Zmax", [-15, 15]],
                param3ds: ["Alpha and Theta", [50, 280]],
                N: ["Buffer size", 2]
            };*/

            //var defaultProperties=window["CONST_m"]("get");

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "contentProperties");

            // Heading of content
            var heading = document.createElement('h2');
            heading.innerHTML = "Set Scope Parameters";
            heading.id = "headingProperties"
            content.appendChild(heading);

            // Add Form
            var myform = document.createElement("form");
            myform.method = "post";
            myform.id = "formProperties";

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            for (var key in defaultProperties) {
                if (defaultProperties.hasOwnProperty(key)) {

                    // Input Title
                    var fieldName = defaultProperties[key];
                    var namelabel = document.createElement('label');
                    namelabel.innerHTML = defaultProperties[key][0];
                    myform.appendChild(namelabel);

                    // Input
                    var input = document.createElement("input");
                    input.name = key;
                    input.value = defaultProperties[key][1];
                    input.setAttribute("id", key.toString());
                    input.setAttribute("class", "fieldInput");
                    myform.appendChild(input);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);
                }
            }

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";

            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var propertiesObject = {
                    id: cell.id
                };

                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        propertiesObject[key] = document.getElementById(key.toString()).value;
                    }
                }
                var details = cell.blockInstance.instance.set(propertiesObject); //window[name]("set",cell.value,propertiesObject);
                var enc = new mxCodec();
                var node = enc.encode(details);
                cell.value = node;
                /*
                    Maverick
                    We have changed the value of the cell, but the change won't be reflected
                    unless the graph is refreshed.
                */
                graph.refresh();
                wind.destroy();
            };
            myform.appendChild(btn);

            // Button - Reset
            var btn = document.createElement("button");
            btn.innerHTML = 'Reset';
            btn.type = "button";
            btn.name = "submit";
            btn.id = "resetButtonProperties";
            btn.onclick = function() {
                // Reset
                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        var element = document.getElementById(key.toString());
                        element.value = defaultProperties[key][1];
                    }
                }
            };

            myform.appendChild(btn);
            // Base height without fields : 135 px
            height = 135 + 26 * defaultProperties.length + 15;

            content.appendChild(myform);
            var wind = showModalWindow(graph, 'Properties', content, 450, height);
        };

        /*
         * @jiteshjha
         * createEdgeObject(@parameters) creates an edge on the graph DOM
         * @Parameters :
         *              source -> source object for the edge
         *              target -> destination object for the edge
         *              points -> waypoints to be inserted in the geometry
         */
        function createEdgeObject(graph, source, target, points) {

            // Start the update on the graph
            graph.getModel().beginUpdate();

            try {

                // Create an edge from the given source object and target object
                var edge = graph.insertEdge(graph.getDefaultParent(), null, '', source, target);

                // Get geometry of the edge
                var geometry = graph.getModel().getGeometry(edge);

                /*
                 * Clone the geometry object
                 * NOTE: Direct manipulation of the geometry object may not be
                 *       registered as an action for some cases, hence we clone the
                 *       geometry, manipulate it and set the geometry.
                 */
                var cloneGeometry = geometry.clone();

                // Add points in the cloned geometry
                cloneGeometry.points = points;

                // Set the changed geometry for the edge
                graph.getModel().setGeometry(edge, cloneGeometry);

                // Refresh to reflect changes made
                graph.refresh();
            } finally {

                // End the update
                graph.getModel().endUpdate();
            }

            return edge;
        }

        /*
          @jiteshjha
          Creates a dialog box related to the edge label properties.
          The properties implemented are : edge label, label fontStyle,
          label fontSize, label fontStyle.
        */


        function showTextEditWindow(graph, cell) {
            var fontFamilyList = {
                "Arial": 0,
                "Dialog": 1,
                "Verdana": 2,
                "Times New Roman": 3
            }
            var defaultProperties = {
                text: ["Text", "text"],
                fontFamily: ["Font Family", fontFamilyList],
                fontSize: ["fontSize", 20]
            };

            var style = graph.getModel().getStyle(cell);
            var styleObject = styleToObject(style);
            if ('fontSize' in styleObject) {
                defaultProperties['fontSize'][1] = styleObject['fontSize'];
            }
            if (cell.value != "") {
                defaultProperties['text'][1] = cell.value;
            }

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "contentProperties");

            // Heading of content
            var heading = document.createElement('h2');
            heading.innerHTML = "Text and Text Font";
            heading.id = "headingProperties"
            content.appendChild(heading);

            // Add Form
            var myform = document.createElement("form");
            myform.method = "post";
            myform.id = "formProperties";

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            for (var key in defaultProperties) {
                if (defaultProperties.hasOwnProperty(key)) {

                    // Input Title
                    var fieldName = defaultProperties[key];
                    var namelabel = document.createElement('label');
                    namelabel.innerHTML = defaultProperties[key][0];
                    myform.appendChild(namelabel);

                    if (key == "fontFamily") {
                        //Here we create a "select" element (a drop down list).
                        var newList = document.createElement("select");
                        newList.style.cssText = "float:right";
                        newList.setAttribute("id", key.toString());
                        var dropdownItems = defaultProperties[key][1];

                        for (var item in dropdownItems) {
                            if (dropdownItems.hasOwnProperty(item)) {
                                option = document.createElement('option');
                                option.value = item;
                                option.text = item;
                                option.setAttribute("id", item);
                                newList.appendChild(option);
                            }
                        }

                        var selectedFontFamily = 0;
                        var styleObject = styleToObject(style);
                        if ('fontFamily' in styleObject) {
                            selectedFontFamily = styleObject['fontFamily'];
                        }
                        newList.selectedIndex = dropdownItems[selectedFontFamily];
                        myform.appendChild(newList);
                    } else {
                        var input = document.createElement("input");
                        input.name = key;
                        input.value = defaultProperties[key][1];
                        input.setAttribute("id", key.toString());
                        input.setAttribute("class", "fieldInput");
                        myform.appendChild(input);
                    }
                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);
                }
            }

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            /*
              changeFontStyle function sets the style for given fontStyle and toggles with the active class
              for "set" type, and toggles with the active class for "get" type.
            */
            function changeFontStyle(type, graph, cell, button, bit) {
                var style = graph.getModel().getStyle(cell);
                var trigger = document.getElementById(button);
                var styleObject = styleToObject(style);
                var previousValue = 1;
                if ('fontStyle' in styleObject) {
                    previousValue = styleObject['fontStyle'];

                    // To get a bit mask:
                    var mask = 1 << bit; // Get the 1st element

                    if (type == "get") {
                        // toggle the bit
                        previousValue ^= mask;
                        trigger.classList.toggle(button);
                        styleObject['fontStyle'] = previousValue;
                        style = objectToStyle(styleObject);
                        graph.getModel().setStyle(cell, style);
                    } else if (type == "set") {
                        if ((previousValue & mask) != 0) {
                            trigger.classList.toggle(button);
                        }
                    }
                }
            }

            // Button - Bold
            var btn = document.createElement("button");
            btn.innerHTML = 'Bold';
            btn.setAttribute("id", "boldButton");
            btn.type = "button";
            btn.name = "submit";
            btn.onclick = function() {
                changeFontStyle("get", graph, cell, 'boldButton', 0);
            }
            myform.appendChild(btn);

            // Button - Italics
            var btn = document.createElement("button");
            btn.innerHTML = 'Italic';
            btn.setAttribute("id", "italicButton");
            btn.type = "button";
            btn.name = "submit";
            btn.onclick = function() {
                changeFontStyle("get", graph, cell, 'italicButton', 1);
            }
            myform.appendChild(btn);

            // Button - Underline
            var btn = document.createElement("button");
            btn.innerHTML = 'Underline';
            btn.setAttribute("id", "underlineButton");
            btn.type = "button";
            btn.name = "submit";
            btn.onclick = function() {
                changeFontStyle("get", graph, cell, 'underlineButton', 2);
            }
            myform.appendChild(btn);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";

            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var propertiesObject = {
                    id: cell.id
                };
                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        propertiesObject[key] = document.getElementById(key.toString()).value;
                    }
                }
                var style = graph.getModel().getStyle(cell);
                var styleObject = styleToObject(style);
                styleObject['fontSize'] = propertiesObject['fontSize'];
                styleObject['fontFamily'] = propertiesObject['fontFamily'];
                style = objectToStyle(styleObject);
                graph.getModel().setStyle(cell, style);
                graph.getModel().setValue(cell, propertiesObject['text']);
                wind.destroy();
            };
            myform.appendChild(btn);

            // Base heights without fields : 135 px
            height = 135 + 26 * defaultProperties.length + 15;
            content.appendChild(myform);
            var wind = showModalWindow(graph, 'Text and Text font', content, 450, height);

            /*
              @jiteshjha
              If any fontStyle(Bold, Italic, Underline) has already been implemented
              for the selected edge label, add the respective active class to that button.
            */

            if ('fontStyle' in styleObject) {
                changeFontStyle("set", graph, cell, 'boldButton', 0);
                changeFontStyle("set", graph, cell, 'italicButton', 1);
                changeFontStyle("set", graph, cell, 'underlineButton', 2);
            }
        };
        /*
          @jiteshjha, @pooja
          showSetupWindow dialog box
        */

        /*
            Maverick
            Added 'diagRoot' parameter.
        */
        function showSetupWindow(graph, diagRoot) {

            /*
                Maverick
                Added one more element in the list for each key to be used in the <XcosDiagram>
                tag.
            */

            var defaultProperties = setup("get");

            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "contentProperties");

            // Heading of content
            var heading = document.createElement('h2');
            heading.innerHTML = "Setup";
            heading.id = "headingProperties"
            content.appendChild(heading);

            // Add Form
            var myform = document.createElement("form");
            myform.method = "post";
            myform.id = "formProperties";

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            for (var key in defaultProperties) {
                if (defaultProperties.hasOwnProperty(key)) {

                    // Input Title
                    var fieldName = defaultProperties[key];
                    var namelabel = document.createElement('label');
                    namelabel.innerHTML = defaultProperties[key][0];
                    myform.appendChild(namelabel);

                    if (key == "solv_kind") {

                        //Here we create a "select" element (a drop down list).
                        var newList = document.createElement("select");
                        newList.style.cssText = "float:right";
                        newList.setAttribute("id", key.toString());
                        var dropdownItems = setup("getArray");

                        // Iterate over the dropdown options and create html elements
                        dropdownItems.forEach(function(value, i) {
                            option = document.createElement('option');
                            option.value = i.toFixed(1);
                            option.text = value;
                            newList.appendChild(option);
                        });
                        newList.selectedIndex = defaultProperties[key][2];
                        myform.appendChild(newList);

                    } else {
                        var input = document.createElement("input");
                        input.name = key;
                        input.value = defaultProperties[key][2];
                        input.setAttribute("id", key.toString());
                        input.setAttribute("class", "fieldInput");
                        myform.appendChild(input);
                    }

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);

                    // Line break
                    var linebreak = document.createElement('br');
                    myform.appendChild(linebreak);
                }
            }

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Set Context
            var btn = document.createElement("button");
            btn.innerHTML = 'Set Context';
            btn.style.cssText = 'float: left';
            btn.type = "button";
            btn.name = "submit";
            btn.id = "resetButtonProperties";
            btn.onclick = function() {
                // show Set Context
                /*
                    Maverick
                    Added the parameter here as well.
                */
                showSetContext(graph, diagRoot);
            };
            myform.appendChild(btn);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);

            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";

            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var propertiesObject = {};

                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        propertiesObject[defaultProperties[key][1]] = document.getElementById(key.toString()).value;

                        /*
                            Maverick
                            Adding the corresponding attributes to the <XcosDiagram> tag.
                        */
                        diagRoot[defaultProperties[key][1]] = document.getElementById(key.toString()).value;
                    }
                }

                setup("set", propertiesObject);
                wind.destroy();
            };

            myform.appendChild(btn);


            // Button - Reset
            var btn = document.createElement("button");
            btn.innerHTML = 'Reset';
            btn.type = "button";
            btn.name = "submit";
            btn.id = "resetButtonProperties";
            btn.onclick = function() {
                // Reset
                for (var key in defaultProperties) {
                    if (defaultProperties.hasOwnProperty(key)) {
                        var element = document.getElementById(key.toString());
                        if (key != "solv_kind") {
                            element.value = defaultProperties[key][2];
                        } else {
                            /*
                                Maverick
                                Code modified to reset the drop down list.
                            */
                            element.selectedIndex = 0;
                        }
                    }
                }
            };

            myform.appendChild(btn);
            // Base height without fields : 135 px
            height = 135 + 26 * defaultProperties.length + 15;

            content.appendChild(myform);
            var wind = showModalWindow(graph, 'Set Parameters', content, 450, height);
        };

        function showColorWheel(graph, cell, selectProperty) {
            // Create basic structure for the form
            var content = document.createElement('div');
            content.setAttribute("id", "colorProperties");
            // Add Form
            var myform = document.createElement("form");
            myform.method = "";
            myform.setAttribute("id", "formProperties");
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            // Input Title
            var fieldName = 'Color';
            var namelabel = document.createElement('label');
            namelabel.innerHTML = fieldName;
            myform.appendChild(namelabel);
            // Input
            var input = document.createElement("input");
            input.name = fieldName;
            input.value = 0;
            input.style.cssText = 'float: right;';
            input.setAttribute("id", "color");
            myform.appendChild(input);
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            var picker = document.createElement('div');
            picker.setAttribute("id", "picker");
            myform.appendChild(picker);
            // Line break
            var linebreak = document.createElement('br');
            myform.appendChild(linebreak);
            // Button - Submit
            var btn = document.createElement("button");
            btn.innerHTML = 'Submit';
            btn.type = "button";
            btn.name = "submit";
            btn.style.cssText = 'margin-left: 75px';
            // Executes when button 'btn' is clicked
            btn.onclick = function() {
                var selectedCells = graph.getSelectionCells();
                graph.getModel().beginUpdate();
                try {
                    for ( var count = 0 ; count < selectedCells.length; count++){
                        var selectedCell = selectedCells[count];
                        var input = document.getElementById('color').value;
                        var style = graph.getModel().getStyle(selectedCell);

                        if (style != null) {
                            var styleObject = styleToObject(style);
                        }

                        if (selectProperty == "edgeStrokeColor") {
                            styleObject['strokeColor'] = input;
                        } else if (selectProperty == "bgColor") {
                            graph.container.style.backgroundColor = input;
                        } else if (selectProperty == "vertexStrokeColor") {
                            styleObject['strokeColor'] = input;
                        } else if (selectProperty == "vertexFillColor") {
                            styleObject['fillColor'] = input;
                        } else if (selectProperty == "edgeTextColor") {
                            styleObject['fontColor'] = input;
                        }

                        if (style != null) {
                            style = objectToStyle(styleObject);
                            graph.getModel().setStyle(selectedCell, style);
                        }
                    }
                }
                finally {
                    graph.getModel().endUpdate();
                }

                wind.destroy();
            };
            myform.appendChild(btn);
            content.appendChild(myform);
            var wind = showModalWindow(graph, 'Diagram background...', content, 285, 340);
            // Invokes the farbtastic functionality
            $(document).ready(function() {
                $('#picker').farbtastic('#color');
            });
        };

        function createButtonImage(button, image) {
            if (image != null) {
                var img = document.createElement('img');
                img.setAttribute('src', image);
                img.style.width = '16px';
                img.style.height = '16px';
                img.style.verticalAlign = 'middle';
                img.style.marginRight = '2px';
                button.appendChild(img);
            }
        }

        function addIcons(graph, sidebar) {
            var req = mxUtils.load('palettes/palettes.xml');
            var root = req.getDocumentElement();
            var x = root.getElementsByTagName('node')[0];
            var categories = x.getElementsByTagName('node');
            for (var i = 0, nodeLength = categories.length; i < nodeLength; i++) {
                var categoryName = categories[i].getAttribute('name');
                var title = document.createElement('h3');
                title.setAttribute('class', 'accordion-header ui-accordion-header ui-helper-reset ui-state-default ui-accordion-icons ui-corner-all');
                var span = document.createElement('span');
                span.setAttribute('class', 'ui-accordion-header-icon ui-icon ui-icon-triangle-1-e');
                var titleName = document.createTextNode(categoryName);
                title.appendChild(span);
                title.appendChild(titleName);
                sidebar.appendChild(title);
                var newImages = document.createElement('div');
                newImages.setAttribute('class', 'ui-accordion-content ui-helper-reset ui-widget-content ui-corner-bottom');
                var blocks = categories[i].getElementsByTagName('block');
                for (var j = 0, blockLength = blocks.length; j < blockLength; j++) {
                    var name = blocks[j].getAttribute('name');
                    var icon = blocks[j].getElementsByTagName('icon')[0];
                    var iconPath = icon.getAttribute('path');
                    addSidebarIcon(graph, newImages, name, iconPath);
                }
                sidebar.appendChild(newImages);
            }
        }

        function addToolbarButton(editor, toolbar, action, label, image, isTransparent) {
            var button = document.createElement('button');
            button.style.fontSize = '10';
            createButtonImage(button, image);
            if (isTransparent) {
                button.style.background = 'transparent';
                button.style.color = '#FFFFFF';
                button.style.border = 'none';
            }
            mxEvent.addListener(button, 'click', function(evt) {
                editor.execute(action);
            });
            mxUtils.write(button, label);
            button.setAttribute('id', action);
            toolbar.appendChild(button);
        };

        function showModalWindow(graph, title, content, width, height) {
            var background = document.createElement('div');
            background.style.position = 'absolute';
            background.style.left = '0px';
            background.style.top = '0px';
            background.style.right = '0px';
            background.style.bottom = '0px';
            background.style.background = 'black';
            mxUtils.setOpacity(background, 50);
            document.body.appendChild(background);

            if (mxClient.IS_IE) {
                new mxDivResizer(background);
            }

            var x = Math.max(0, document.body.scrollWidth / 2 - width / 2);
            var y = Math.max(10, (document.body.scrollHeight || document.documentElement.scrollHeight) / 2 - height * 2 / 3);
            var wind = new mxWindow(title, content, x, y, width, height, false, true);
            wind.setClosable(true);

            // Fades the background out after after the window has been closed
            wind.addListener(mxEvent.DESTROY, function(evt) {
                graph.setEnabled(true);
                mxEffects.fadeOut(background, 50, true, 10, 30, true);
            });

            graph.setEnabled(false);
            graph.tooltipHandler.hide();
            wind.setVisible(true);
            return wind;
        };

        var flag = 0;

        function addSidebarIcon(graph, sidebar, name, image) {
            // Function that is executed when the image is dropped on
            // the graph. The cell argument points to the cell under
            // the mousepointer if there is one.
            var funct = function(graph, evt, cell, x, y) {
                var parent = graph.getDefaultParent();
                var model = graph.getModel();
                var v1 = null;
                var doc = mxUtils.createXmlDocument();
                model.beginUpdate();
                try {
                    var details_instance = new window[name]();
                    var details = details_instance.define();
                    var enc = new mxCodec(mxUtils.createXmlDocument());
                    var node = enc.encode(details);
                    var temp = enc.encode(parent);

                    // Get the stylesheet for the graph
                    var stylesheet = graph.getStylesheet();
                    console.log(name);
                    // From the stylesheet, get the style of the particular block
                    var style = stylesheet.styles[name];

                    /*
                     * When a particular block is loaded for the first time,
                     * the image in the style of the block will be a path to the image.
                     * Set the label in the style property of the block has a html image,
                     * and set the image in the style property as null
                     *
                     * NOTE: Since the image of any block need not be changed for
                     *       for every movement of that block, the image must be
                     *       set only once.
                     */
                    if (style != null && style['image'] != null) {

                        // Make label as a image html element
                        var label = '<img src="' + style['image'] + '" height="80" width="80">';

                        // Set label
                        style['label'] = label;

                        style['imagePath'] = style['image'];

                        // Set image as null
                        style['image'] = null;

                        // Add the label as a part of node
                        node.setAttribute('label', label);
                    }

                    /*
                     * If a particular block with image tag in it's style property
                     * has been invoked already, the image tag would be null for any
                     * successive instances of the same block. Hence, set the label
                     * from the label tag in style which was set when that blockModel
                     * was invoked on the first time.
                     */
                    if (style != null && style['label'] != null) {

                        // Set label from the label field in the style property
                        node.setAttribute('label', style['label']);
                    }

                    node.setAttribute('parent', temp.getAttribute('id'));
                    var i, arr = [];
                    var blockModel = details_instance.x.model;
                    var graphics = details_instance.x.graphics;

                    /* To determine number and type of Port*/
                    var inputPorts = [],
                        outputPorts = [],
                        controlPorts = [],
                        commandPorts = [];
                    if (blockModel.in.height != null) {
                        arr = getData(graphics.in_implicit);
                        if (arr.length != 0) {
                            inputPorts = arr;
                        } else {
                            for (i = 0; i < blockModel.in.height; i++) {
                                inputPorts.push("E");
                            }
                        }
                    }
                    if (blockModel.out.height != null) {
                        arr = getData(graphics.out_implicit);
                        if (arr.length != 0) {
                            outputPorts = arr;
                        } else {
                            for (i = 0; i < blockModel.out.height; i++) {
                                outputPorts.push("E");
                            }
                        }
                    }
                    if (blockModel.evtin.height != null) {
                        for (i = 0; i < blockModel.evtin.height; i++) {
                            controlPorts.push("CONTROL");
                        }
                    }
                    if (blockModel.evtout.height != null) {
                        for (i = 0; i < blockModel.evtout.height; i++) {
                            commandPorts.push("COMMAND");
                        }
                    }
                    v1 = graph.insertVertex(parent, null, node, x, y, 80, 80, name);

                    // @Chhavi: Additional attribute to store the block's instance
                    v1.blockInstance = createInstanceTag(details_instance);
                    v1.currentAngle = 0;
                    v1.flipX = 1;
                    v1.flipY = 1;
                    createPorts(graph, v1, inputPorts, controlPorts, outputPorts, commandPorts);
                    v1.setConnectable(false);
                } finally {
                    model.endUpdate();
                }
                graph.setSelectionCell(v1);
            }

            var para = document.createElement('p');
            var blockFigure = document.createElement('figure');
            var img = document.createElement('img');
            img.setAttribute('src', image);
            var caption = document.createElement('figcaption');
            var blockName = document.createTextNode(name);
            caption.appendChild(blockName);
            blockFigure.appendChild(img);
            blockFigure.appendChild(caption);
            para.appendChild(blockFigure);
            sidebar.appendChild(para);

            var dragElt = document.createElement('div');
            dragElt.style.border = 'dashed black 1px';
            dragElt.style.width = '80px';
            dragElt.style.height = '80px';

            // Creates the image which is used as the drag icon (preview)
            var ds = mxUtils.makeDraggable(img, graph, funct, dragElt, 0, 0, true, true);
            ds.setGuidesEnabled(true);
        };

        // Create ports
        /*
            Maverick
            Modified the createPorts funtion so that it can be used while creating ports from 
            a given Xcos diagram. 
            New parameters are the parentObj where the port is supposed to be added and a dictionary
            object which contains the mapping between the newly assigned Ids and imported Ids.
        */
        function createPorts(graph, block, left, top, right, bottom, parentObj, nodeDataObject) {

            createInputPorts(graph, block, left, top, parentObj, nodeDataObject);
            createOutputPorts(graph, block, right, bottom, parentObj, nodeDataObject);

        }

        function createInputPorts(graph, block, leftArray, topArray, parentObj, nodeDataObject) {

            var topNumber = topArray.length;
            var leftNumber = leftArray.length;

            if (leftNumber != 0) {
                for (var i = 1; i <= leftNumber; i++) {

                    var x = 0;
                    var y = (i / (leftNumber + 1)).toFixed(4);
                    var portType = leftArray[i - 1];
                    //console.log(parentObj.inputIds);
                    if (parentObj != null) {
                        createInputPort(graph, block, x, y, portType, 'left', i, nodeDataObject, parentObj.inputIds);
                    } else {
                        createInputPort(graph, block, x, y, portType, 'left', i);
                    }

                }
            }
            if (topNumber != 0) {
                for (var i = 1; i <= topNumber; i++) {
                    var x = (i / (topNumber + 1)).toFixed(4);
                    var y = 0;
                    var portType = topArray[i - 1];
                    //console.log(parentObj.controlIds);
                    if (parentObj != null) {
                        createInputPort(graph, block, x, y, portType, 'top', i, nodeDataObject, parentObj.controlIds);
                    } else {
                        createInputPort(graph, block, x, y, portType, 'top', i);
                    }
                }
            }

        };

        function createOutputPorts(graph, block, rightArray, bottomArray, parentObj, nodeDataObject) {

            var bottomNumber = bottomArray.length;
            var rightNumber = rightArray.length;
            if (rightNumber != 0) {
                for (var i = 1; i <= rightNumber; i++) {
                    var x = 1;
                    var y = (i / (rightNumber + 1)).toFixed(4);
                    var portType = rightArray[i - 1];
                    //console.log(parentObj.outputIds);
                    if (parentObj != null) {
                        createOutputPort(graph, block, x, y, portType, 'right', i, nodeDataObject, parentObj.outputIds);
                    } else {
                        createOutputPort(graph, block, x, y, portType, 'right', i);
                    }
                }
            }
            if (bottomNumber != 0) {
                for (var i = 1; i <= bottomNumber; i++) {
                    var x = (i / (bottomNumber + 1)).toFixed(4);
                    var y = 1;
                    var portType = bottomArray[i - 1];
                    //console.log(parentObj.commandIds);
                    if (parentObj != null) {
                        createOutputPort(graph, block, x, y, portType, 'bottom', i, nodeDataObject, parentObj.commandIds);
                    } else {
                        createOutputPort(graph, block, x, y, portType, 'bottom', i);
                    }
                }
            }

        };

        function createInputPort(graph, block, x, y, portType, position, ordering, nodeDataObject, idArray) {

            var port = null;
            if (portType == 'COMMAND') {
                port = graph.insertVertex(block, null, 'CommandPort', x, y, 10, 10, 'CommandPort', true);
            } else if (portType == 'CONTROL') {
                port = graph.insertVertex(block, null, 'ControlPort', x, y, 10, 10, 'ControlPort', true);
            } else if (portType == 'I') {
                port = graph.insertVertex(block, null, 'ImplicitInputPort', x, y, 10, 10, 'ImplicitInputPort', true);
            } else if (portType == 'E') {
                port = graph.insertVertex(block, null, 'ExplicitInputPort', x, y, 10, 10, 'ExplicitInputPort', true);
            }
            if (port != null) {
                if (position == 'top') {
                    port.geometry.offset = new mxPoint(-6, -10);
                } else if (position == 'left') {
                    port.geometry.offset = new mxPoint(-10, -6);
                }
                port.ordering = ordering;

                if (nodeDataObject != null) {
                    var obj = new Object();
                    obj.newId = port.id;
                    obj.oldId = idArray[ordering - 1];
                    //console.log(idArray[ordering-1]);
                    nodeDataObject[idArray[ordering - 1]] = obj;
                }

                if (block.style == 'Split') {
                    port.setVisible(false);
                    port.setConnectable(false);
                }
            }
        };

        function createOutputPort(graph, block, x, y, portType, position, ordering, nodeDataObject, idArray) {
            var port = null;

            if (portType == 'COMMAND') {
                port = graph.insertVertex(block, null, 'CommandPort', x, y, 10, 10, 'CommandPort', true);
            } else if (portType == 'CONTROL') {
                port = graph.insertVertex(block, null, 'ControlPort', x, y, 10, 10, 'ControlPort', true);
            } else if (portType == 'I') {
                port = graph.insertVertex(block, null, 'ImplicitOutputPort', x, y, 10, 10, 'ImplicitOutputPort', true);
            } else if (portType == 'E') {
                port = graph.insertVertex(block, null, 'ExplicitOutputPort', x, y, 10, 10, 'ExplicitOutputPort', true);
            }
            if (port != null) {
                if (position == 'bottom') {
                    port.geometry.offset = new mxPoint(-6, 0);
                }
                if (position == 'right') {
                    port.geometry.offset = new mxPoint(0, -6);
                }
                port.ordering = ordering;

                if (nodeDataObject != null) {
                    var obj = new Object();
                    obj.newId = port.id;
                    obj.oldId = idArray[ordering - 1];
                    //console.log(idArray[ordering-1]);
                    nodeDataObject[idArray[ordering - 1]] = obj;
                }

                if (block.style == 'Split') {
                    port.setVisible(false);
                    port.setConnectable(false);
                }
            }
        };

        function configureStylesheet(graph) {
            var req = mxUtils.load('styles/Xcos-style.xml');
            var root = req.getDocumentElement();
            var dec = new mxCodec(root.ownerDocument);
            dec.decode(root, graph.stylesheet);
        };
    </script>
    <!--
        Updates connection points before the routing is called.
    -->
    <script type="text/javascript">
        // Computes the position of edge to edge connection points.
        mxGraphView.prototype.updateFixedTerminalPoint = function(edge, terminal, source, constraint) {

            // Store the edge state for every newly created edge in edgeState variable
            edgeState = edge;
            var pt = null;

            if (constraint != null) {
                pt = this.graph.getConnectionPoint(terminal, constraint);
            }

            if (source) {
                edge.sourceSegment = null;
            } else {
                edge.targetSegment = null;
            }

            if (pt == null) {
                var s = this.scale;
                var tr = this.translate;
                var orig = edge.origin;
                var geo = this.graph.getCellGeometry(edge.cell);
                pt = geo.getTerminalPoint(source);

                // Computes edge-to-edge connection point
                if (pt != null) {
                    pt = new mxPoint(s * (tr.x + pt.x + orig.x),
                        s * (tr.y + pt.y + orig.y));

                    // Finds nearest segment on edge and computes intersection
                    if (terminal != null && terminal.absolutePoints != null) {
                        var seg = mxUtils.findNearestSegment(terminal, pt.x, pt.y);

                        // Finds orientation of the segment
                        var p0 = terminal.absolutePoints[seg];
                        var pe = terminal.absolutePoints[seg + 1];
                        var horizontal = (p0.x - pe.x == 0);

                        // Stores the segment in the edge state
                        var key = (source) ? 'sourceConstraint' : 'targetConstraint';
                        var value = (horizontal) ? 'horizontal' : 'vertical';
                        edge.style[key] = value;

                        // Keeps the coordinate within the segment bounds
                        if (horizontal) {
                            pt.x = p0.x;
                            pt.y = Math.min(pt.y, Math.max(p0.y, pe.y));
                            pt.y = Math.max(pt.y, Math.min(p0.y, pe.y));
                        } else {
                            pt.y = p0.y;
                            pt.x = Math.min(pt.x, Math.max(p0.x, pe.x));
                            pt.x = Math.max(pt.x, Math.min(p0.x, pe.x));
                        }
                    }
                }
                // Computes constraint connection points on vertices and ports
                else if (terminal != null && terminal.cell.geometry.relative) {
                    pt = new mxPoint(this.getRoutingCenterX(terminal),
                        this.getRoutingCenterY(terminal));
                }
            }

            edge.setAbsoluteTerminalPoint(pt, source);
        };
    </script>

    <!--
      Overrides methods to preview and create new edges.
    -->
    <script type="text/javascript">
        // Sets source terminal point for edge-to-edge connections.
        mxConnectionHandler.prototype.createEdgeState = function(me) {
            var edge = this.graph.createEdge();

            if (this.sourceConstraint != null && this.previous != null) {
                edge.style = mxConstants.STYLE_EXIT_X + '=' + this.sourceConstraint.point.x + ';' +
                    mxConstants.STYLE_EXIT_Y + '=' + this.sourceConstraint.point.y + ';';
            } else if (this.graph.model.isEdge(me.getCell())) {
                var scale = this.graph.view.scale;
                var tr = this.graph.view.translate;
                var pt = new mxPoint(this.graph.snap(me.getGraphX() / scale) - tr.x,
                    this.graph.snap(me.getGraphY() / scale) - tr.y);
                edge.geometry.setTerminalPoint(pt, true);
            }

            return this.graph.view.createState(edge);
        };

        mxConnectionHandler.prototype.isStopEvent = function(me) {
            return me.getState() != null || mxEvent.isRightMouseButton(me.getEvent());
        };

        // Updates target terminal point for edge-to-edge connections.
        mxConnectionHandlerUpdateCurrentState = mxConnectionHandler.prototype.updateCurrentState;
        mxConnectionHandler.prototype.updateCurrentState = function(me) {
            mxConnectionHandlerUpdateCurrentState.apply(this, arguments);

            if (this.edgeState != null) {
                this.edgeState.cell.geometry.setTerminalPoint(null, false);

                if (this.shape != null && this.currentState != null &&
                    this.currentState.view.graph.model.isEdge(this.currentState.cell)) {
                    var scale = this.graph.view.scale;
                    var tr = this.graph.view.translate;
                    var pt = new mxPoint(this.graph.snap(me.getGraphX() / scale) - tr.x,
                        this.graph.snap(me.getGraphY() / scale) - tr.y);
                    this.edgeState.cell.geometry.setTerminalPoint(pt, false);
                }
            }
        };

        // Updates the terminal and control points in the cloned preview.
        mxEdgeSegmentHandler.prototype.clonePreviewState = function(point, terminal) {
            var clone = mxEdgeHandler.prototype.clonePreviewState.apply(this, arguments);
            clone.cell = clone.cell.clone();

            if (this.isSource || this.isTarget) {
                clone.cell.geometry = clone.cell.geometry.clone();

                // Sets the terminal point of an edge if we're moving one of the endpoints
                if (this.graph.getModel().isEdge(clone.cell)) {
                    clone.cell.geometry.setTerminalPoint(point, this.isSource);
                } else {
                    clone.cell.geometry.setTerminalPoint(null, this.isSource);
                }
            }

            return clone;
        };

        var mxEdgeHandlerConnect = mxEdgeHandler.prototype.connect;
        mxEdgeHandler.prototype.connect = function(edge, terminal, isSource, isClone, me) {
            var result = null;
            var model = this.graph.getModel();
            var parent = model.getParent(edge);

            model.beginUpdate();
            try {
                result = mxEdgeHandlerConnect.apply(this, arguments);
                var geo = model.getGeometry(result);

                if (geo != null) {
                    geo = geo.clone();
                    var pt = null;

                    if (model.isEdge(terminal)) {
                        pt = this.abspoints[(this.isSource) ? 0 : this.abspoints.length - 1];
                        pt.x = pt.x / this.graph.view.scale - this.graph.view.translate.x;
                        pt.y = pt.y / this.graph.view.scale - this.graph.view.translate.y;

                        var pstate = this.graph.getView().getState(
                            this.graph.getModel().getParent(edge));

                        if (pstate != null) {
                            pt.x -= pstate.origin.x;
                            pt.y -= pstate.origin.y;
                        }

                        pt.x -= this.graph.panDx / this.graph.view.scale;
                        pt.y -= this.graph.panDy / this.graph.view.scale;
                    }

                    geo.setTerminalPoint(pt, isSource);
                    model.setGeometry(edge, geo);
                }
            } finally {
                model.endUpdate();
            }

            return result;
        };
    </script>
    <!--
        Adds in-place highlighting for complete cell area (no hotspot).
    -->
    <script type="text/javascript">
        mxConnectionHandlerCreateMarker = mxConnectionHandler.prototype.createMarker;
        mxConnectionHandler.prototype.createMarker = function() {
            var marker = mxConnectionHandlerCreateMarker.apply(this, arguments);

            // Uses complete area of cell for new connections (no hotspot)
            marker.intersects = function(state, evt) {
                return true;
            };

            return marker;
        };

        mxEdgeHandlerCreateMarker = mxEdgeHandler.prototype.createMarker;
        mxEdgeHandler.prototype.createMarker = function() {
            var marker = mxEdgeHandlerCreateMarker.apply(this, arguments);

            // Adds in-place highlighting when reconnecting existing edges
            marker.highlight.highlight = this.graph.connectionHandler.marker.highlight.highlight;

            return marker;
        }
    </script>
    <!--
       Implements a perpendicular wires connection edge style
    -->
    <script type="text/javascript">
        mxEdgeStyle.WireConnector = function(state, source, target, hints, result) {
            state.cell.waypoints = state.cell.geometry.points;
            // Creates array of all way- and terminalpoints
            var pts = state.absolutePoints;
            var horizontal = true;
            var hint = null;

            // Gets the initial connection from the source terminal or edge
            if (source != null && state.view.graph.model.isEdge(source.cell)) {
                horizontal = state.style['sourceConstraint'] == 'horizontal';
            }
            // If the source terminal is a Split Block, set the horizontal false
            else if (source != null && source.cell.name == 'SPLIT_f') {
                if (state.cell.source != null) {
                    // If the port is the third child of splitBlock, only then set the horizontal as false
                    if (state.cell.source == state.cell.source.parent.getChildAt(2)) {
                        horizontal = state.style['sourceConstraint'] == 'horizontal';
                    }
                }
            } else if (source != null) {
                horizontal = source.style['portConstraint'] != 'vertical';

                // Checks the direction of the shape and rotates
                var direction = source.style[mxConstants.STYLE_DIRECTION];

                if (direction == 'north' || direction == 'south') {
                    horizontal = !horizontal;
                }
            }

            // Adds the first point
            var pt = pts[0];

            /* @jiteshjha splitBlock
             */
            if (state.cell.getGeometry().getTerminalPoint(true) != null) {
                source.cell['sourcePoint'] = state.cell.getGeometry().getTerminalPoint(true);
            }

            if (pt == null && source != null) {
                pt = new mxPoint(state.view.getRoutingCenterX(source), state.view.getRoutingCenterY(source));
            } else if (pt != null) {
                pt = pt.clone();
            }

            var first = pt;
            if (state.cell.getGeometry().getTerminalPoint(false) != null) {
                target.cell['sourcePoint'] = state.cell.getGeometry().getTerminalPoint(false);
            }

            // Adds the waypoints
            if (hints != null && hints.length > 0) {


                for (var i = 0; i < hints.length; i++) {
                    horizontal = !horizontal;
                    hint = state.view.transformControlPoint(state, hints[i]);

                    if (horizontal) {
                        if (pt.y != hint.y) {
                            pt.y = hint.y;
                            result.push(pt.clone());
                        }
                    } else if (pt.x != hint.x) {
                        pt.x = hint.x;
                        result.push(pt.clone());
                    }
                }
            } else {
                hint = pt;
            }

            // Adds the last point
            pt = pts[pts.length - 1];
            if (pt == null && target != null) {
                pt = new mxPoint(state.view.getRoutingCenterX(target), state.view.getRoutingCenterY(target));

            }

            if (horizontal) {
                if (pt.y != hint.y && first.x != pt.x) {
                    result.push(new mxPoint(pt.x, hint.y));
                }
            } else if (pt.x != hint.x && first.y != pt.y) {
                result.push(new mxPoint(hint.x, pt.y));
            }

            // If the target of the edge is a splitBlock, push final coordinate as vertical.
            if (state.cell.target != null) {
                if (state.cell.target.parent.name == "SPLIT_f") {
                    result.pop();
                    result.push(new mxPoint(hint.x, pt.y));
                }
            }
        };

        mxStyleRegistry.putValue('wireEdgeStyle', mxEdgeStyle.WireConnector);

        // This connector needs an mxEdgeSegmentHandler
        mxGraphCreateHandler = mxGraph.prototype.createHandler;
        mxGraph.prototype.createHandler = function(state) {
            var result = null;

            if (state != null) {
                if (this.model.isEdge(state.cell)) {
                    var style = this.view.getEdgeStyle(state);

                    if (style == mxEdgeStyle.WireConnector) {
                        return new mxEdgeSegmentHandler(state);
                    }
                }
            }

            return mxGraphCreateHandler.apply(this, arguments);
        };
    </script>

</head>

<!-- Page passes the container for the graph to the program -->

<body onload="main(document.getElementById('graphContainer'),
            document.getElementById('outlineContainer'),
            document.getElementById('toolbarContainer'),
            document.getElementById('sidebarContainer'),
            document.getElementById('statusContainer'));" style="margin:0px;">

    <!-- Creates a container for the splash screen -->
    <div id="splash" style="position:absolute;top:0px;left:0px;width:100%;height:100%;background:white;z-index:1;">
        <center id="splash" style="padding-top:230px;">
            <img src="images/loading.gif">
        </center>
    </div>

    <!-- Creates a container for the sidebar -->
    <div id="toolbarContainer" style="position:absolute;white-space:nowrap;overflow:hidden;top:0px;left:0px;max-height:24px;height:36px;right:0px;padding:6px;background-image:url('images/toolbar_bg.gif');">
    </div>

    <!-- Creates a container for the toolbox -->
    <div id="sidebarContainer" class="ui-accordion ui-widget ui-helper-reset" style="position:absolute;overflow:scroll;top:36px;left:0px;bottom:36px;max-width:266px;width:270px;padding-top:10px;padding-left:4px;">
    </div>

    <!-- Creates a container for the graph -->
    <div id="graphContainer" style="position:absolute;overflow:hidden;top:36px;left:270px;bottom:36px;right:0px;background-image:url('images/grid.gif');cursor:default;">
    </div>

    <!-- Creates a container for the outline -->
    <div id="outlineContainer" style="position:absolute;overflow:hidden;top:36px;right:0px;width:200px;height:140px;background:transparent;border-style:solid;border-color:black;">
    </div>

    <!-- Creates a container for the sidebar -->
    <div id="statusContainer" style="text-align:right;position:absolute;overflow:hidden;bottom:0px;left:0px;max-height:24px;height:36px;right:0px;color:white;padding:6px;background-image:url('images/toolbar_bg.gif');">
        <div style="font-size:10pt;float:left;">
            <a href="http://fossee.in/" target="_tab">FOSSEE</a>
        </div>
    </div>

    <!-- Secret -->
    <p class="accordion-expand-holder" style="display:none">
        <a id='toggleBlocks' class="accordion-expand-all">Expand All</a>
    </p>

</body>
<!-- It's good if this part happens after the entire page has loaded-->
<script type="text/javascript">
    // Preload all images
    var directory = ["/blocks/", "/images/", "/palettes/"];
    for (folder in directory) {
        $.ajax({
            type: "POST",

            // Invoke filenames.php
            url: "filenames.php",

            // Receive the resultant filenames from the php script in JSON format
            dataType: "json",

            // Add url for the required folder
            data: {
                url: directory[folder]
            },
            success: function(data) {
                function preload(sources) {

                    /*
                     * @Parameter: sources will have the required filenames in the mentioned folder
                     * For each image url, make a new image to enable preloading
                     */
                    for (i in sources) {
                        var image = new Image();
                        image.src = sources[i];
                    }
                }
                preload(data);
            }
        });
    }

    //Find out more here: http://stackoverflow.com/questions/12843418/jquery-ui-accordion-expand-collapse-all
    $(window).load(function() {
        var headers = $('#sidebarContainer .accordion-header');
        var contentAreas = $('#sidebarContainer .ui-accordion-content ').hide();
        var expandLink = $('.accordion-expand-all');

        // add the accordion functionality
        headers.click(function() {
            var panel = $(this).next();
            var isOpen = panel.is(':visible');

            // open or close as necessary
            panel[isOpen ? 'slideUp' : 'slideDown']()
                // trigger the correct custom event
                .trigger(isOpen ? 'hide' : 'show');

            // stop the link from causing a pagescroll
            return false;
        });

        // hook up the expand/collapse all
        expandLink.click(function() {
            var isAllOpen = $(this).data('isAllOpen');

            contentAreas[isAllOpen ? 'hide' : 'show']()
                .trigger(isAllOpen ? 'hide' : 'show');
        });

        // when panels open or close, check to see if they're all open
        contentAreas.on({
            // whenever we open a panel, check to see if they're all open
            // if all open, swap the button to collapser
            show: function() {
                var isAllOpen = !contentAreas.is(':hidden');
                if (isAllOpen) {
                    expandLink.text('Collapse All')
                        .data('isAllOpen', true);
                }
            },
            // whenever we close a panel, check to see if they're all open
            // if not all open, swap the button to expander
            hide: function() {
                var isAllOpen = !contentAreas.is(':hidden');
                if (!isAllOpen) {
                    expandLink.text('Expand All')
                        .data('isAllOpen', false);
                }
            }
        });
    });
</script>

</html>