Download this file

SwingDemo.java    3677 lines (3252 with data), 167.3 kB

   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
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
package net.miginfocom.demo;
import net.miginfocom.layout.*;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import javax.swing.border.LineBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.*;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Random;
/*
* License (BSD):
* ==============
*
* Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or other
* materials provided with the distribution.
* Neither the name of the MiG InfoCom AB nor the names of its contributors may be
* used to endorse or promote products derived from this software without specific
* prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
*
* @version 1.0
* @author Mikael Grev, MiG InfoCom AB
* Date: 2006-sep-08
*/
public class SwingDemo extends JFrame
{
public static final int INITIAL_INDEX = 0;
private static final boolean DEBUG = false;
private static final boolean OPAQUE = false;
private static final String[][] panels = new String[][] {
// {"Test", "BugTestApp, disregard"},
{"Welcome", "\n\n \"MigLayout makes complex layouts easy and normal layouts one-liners.\""},
{"Quick Start", "This is an example of how to build a common dialog type. Note that there are no special components, nested panels or absolute references to cell positions. If you look at the source code you will see that the layout code is very simple to understand."},
{"Plain", "A simple example on how simple it is to create normal forms. No builders needed since the whole layout manager works like a builder."},
{"Alignments", "Shows how the alignment of components are specified. At the top/left is the alignment for the column/row. The components have no alignments specified.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
{"Cell Alignments", "Shows how components are aligned when both column/row alignments and component constraints are specified. At the top/left are the alignment for the column/row and the text on the buttons is the component constraint that will override the column/row alignment if it is an alignment.\n\nNote that baseline alignment will be interpreted as 'center' before JDK 6."},
{"Basic Sizes", "A simple example that shows how to use the column or row min/preferred/max size to set the sizes of the contained components and also an example that shows how to do this directly in the component constraints."},
{"Growing", "A simple example that shows how to use the growx and growy constraint to set the sizes and how they should grow to fit the available size. Both the column/row and the component grow/shrink constraints can be set, but the components will always be confined to the space given by its column/row."},
{"Grow Shrink", "Demonstrates the very flexible grow and shrink constraints that can be set on a component.\nComponents can be divided into grow/shrink groups and also have grow/shrink weight within each of those groups.\n\nBy default " +
"components shrink to their inherent (or specified) minimum size, but they don't grow."},
{"Span", "This example shows the powerful spanning and splitting that can be specified in the component constraints. With spanning any number of cells can be merged with the additional option to split that space for more than one component. This makes layouts very flexible and reduces the number of times you will need nested panels to very few."},
{"Flow Direction", "Shows the different flow directions. Flow direction for the layout specifies if the next cell will be in the x or y dimension. Note that it can be a different flow direction in the slit cell (the middle cell is slit in two). Wrap is set to 3 for all panels."},
{"Grouping", "Sizes for both components and columns/rows can be grouped so they get the same size. For instance buttons in a button bar can be given a size-group so that they will all get " +
"the same minimum and preferred size (the largest within the group). Size-groups can be set for the width, height or both."},
{"Units", "Demonstrates the basic units that are understood by MigLayout. These units can be extended by the user by adding one or more UnitConverter(s)."},
{"Component Sizes", "Minimum, preferred and maximum component sizes can be overridden in the component constraints using any unit type. The format to do this is short and simple to understand. You simply specify the " +
"min, preferred and max sizes with a colon between.\n\nAbove are some examples of this. An exclamation mark means that the value will be used for all sizes."},
{"Bound Sizes", "Shows how to create columns that are stable between tabs using minimum sizes."},
{"Cell Position", "Even though MigLayout has automatic grid flow you can still specify the cell position explicitly. You can even combine absolute (x, y) and flow (skip, wrap and newline) constraints to build your layout."},
{"Orientation", "MigLayout supports not only right-to-left orientation, but also bottom-to-top. You can even set the flow direction so that the flow is vertical instead of horizontal. It will automatically " +
"pick up if right-to-left is to be used depending on the ComponentWrapper, but it can also be manually set for every layout."},
{"Absolute Position", "Demonstrates the option to place any number of components using absolute coordinates. This can be just the position (if min/preferred size) using \"x y p p\" format or" +
"the bounds using the \"x1 y1 x2 y2\" format. Any unit can be used and percent is relative to the parent.\nAbsolute components will not disturb the flow or occupy cells in the grid. " +
"Absolute positioned components will be taken into account when calculating the container's preferred size."},
{"Component Links", "Components can be linked to any side of any other component. It can be a forward, backward or cyclic link references, as long as it is stable and won't continue to change value over many iterations." +
"Links are referencing the ID of another component. The ID can be overridden by the component's constrains or is provided by the ComponentWrapper. For instance it will use the component's 'name' on Swing.\n" +
"Since the links can be combined with any expression (such as 'butt1.x+10' or 'max(button.x, 200)' the links are very customizable."},
{"Docking", "Docking components can be added around the grid. The docked component will get the whole width/height on the docked side by default, however this can be overridden. When all docked components are laid out, whatever space " +
"is left will be available for the normal grid laid out components. Docked components does not in any way affect the flow in the grid.\n\nSince the docking runs in the same code path " +
"as the normal layout code the same properties can be specified for the docking components. You can for instance set the sizes and alignment or link other components to their docked component's bounds."},
{"Button Bars", "Button order is very customizable and are by default different on the supported platforms. E.g. Gaps, button order and minimum button size are properties that are 'per platform'. MigLayout picks up the current platform automatically and adjusts the button order and minimum button size accordingly, all without using a button builder or any other special code construct."},
{"Visual Bounds", "Human perceptible bounds may not be the same as the mathematical bounds for the component. This is for instance the case if there is a drop shadow painted by the component's border. MigLayout can compensate " +
"for this in a simple way. Note the top middle tab-component, it is not aligned visually correct on Windows XP. For the second tab the bounds are corrected automatically on Windows XP."},
{"Debug", "Demonstrates the non-intrusive way to get visual debugging aid. There is no need to use a special DebugPanel or anything that will need code changes. The user can simply turn on debug on the layout manager by using the \"debug\" constraint and it will " +
"continuously repaint the panel with debug information on top. This means you don't have to change your code to debug!"},
{"Layout Showdown", "This is an implementation of the Layout Showdown posted on java.net by John O'Conner. The first tab is a pure implemenetation of the showdown that follows all the rules. The second tab is a slightly fixed version that follows some improved layout guidelines." +
"The source code is for both the first and for the fixed version. Note the simplification of the code for the fixed version. Writing better layouts with MiG Layout is reasier that writing bad.\n\nReference: http://weblogs.java.net/blog/joconner/archive/2006/10/more_informatio.html"},
{"API Constraints1", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."},
{"API Constraints2", "This dialog shows the constraint API added to v2.0. It works the same way as the string constraints but with chained method calls. See the source code for details."}
};
private int lastIndex = -10;
private JPanel contentPanel = DEBUG ? new JPanel(new BorderLayout()) : new JPanel(new MigLayout("wrap", "[]unrel[grow]", "[grow][pref]"));
private JTabbedPane layoutPickerTabPane = new JTabbedPane();
private JList pickerList = new JList(new DefaultListModel());
private JTabbedPane southTabPane = new JTabbedPane();
private JScrollPane descrTextAreaScroll = createTextAreaScroll("", 5, 80, true);
private JTextArea descrTextArea = (JTextArea) descrTextAreaScroll.getViewport().getView();
private JScrollPane sourceTextAreaScroll = null;
private JTextArea sourceTextArea = null;
private JPanel layoutDisplayPanel = new JPanel(new BorderLayout(0, 0));
private static boolean buttonOpaque = true;
private static boolean contentAreaFilled = true;
private JFrame sourceFrame = null;
private JTextArea sourceFrameTextArea = null;
private static int benchRuns = 0;
private static long startupMillis = 0;
private static long timeToShowMillis = 0;
private static long benchRunTime = 0;
private static String benchOutFileName = null;
private static boolean append = false;
private static long lastRunTimeStart = 0;
private static StringBuffer runTimeSB = null;
public static void main(String args[])
{
try {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "MiGLayout Swing Demo");
} catch(Throwable ex) {
// Beacuse we did not have permissions.
}
startupMillis = System.currentTimeMillis();
String laf = UIManager.getSystemLookAndFeelClassName();
if (args.length > 0) {
for (int i = 0; i <args.length; i++) {
String arg = args[i].trim();
if (arg.startsWith("-laf")) {
laf = arg.substring(4);
} else if (arg.startsWith("-bench")) {
benchRuns = 10;
try {
benchRuns = Integer.parseInt(arg.substring(6));
} catch(Exception ex) {}
} else if (arg.startsWith("-bout")) {
benchOutFileName = arg.substring(5);
} else if (arg.startsWith("-append")) {
append = true;
} else if (arg.startsWith("-verbose")) {
runTimeSB = new StringBuffer(256);
} else if (arg.equals("-steel")) {
laf = "javax.swing.plaf.metal.MetalLookAndFeel";
System.setProperty("swing.metalTheme", "steel");
} else if (arg.equals("-ocean")) {
laf = "javax.swing.plaf.metal.MetalLookAndFeel";
} else {
System.out.println("Usage: [-laf[look_&_feel_class_name]] [-bench[#_of_runs]] [-bout[benchmark_results_filename]] [-append] [-steel] [-ocean]\n" +
" -laf Set the Application Look&Feel. (Look and feel must be in Classpath)\n" +
" -bench Run demo as benchmark. Run count can be appended. 10 is default.\n" +
" -bout Benchmark results output filename.\n" +
" -append Appends the result to the -bout file.\n" +
" -verbose Print the times of every run.\n" +
" -steel Sets the old Steel theme for Sun's Metal look&feel.\n" +
" -ocean Sets the Ocean theme for Sun's Metal look&feel.\n" +
"\nExamples:\n" +
" java -jar swingdemoapp.jar -bench -boutC:/bench.txt -append\n" +
" java -jar swingdemoapp.jar -ocean -bench20\n" +
" java -cp c:\\looks-2.0.4.jar;.\\swingdemoapp.jar net.miginfocom.demo.SwingDemo -lafcom.jgoodies.looks.plastic.PlasticLookAndFeel -bench20 -boutC:/bench.txt");
System.exit(0);
}
}
}
if (benchRuns == 0)
LayoutUtil.setDesignTime(null, true); // So that the string constraints to create the UnitValues is saved and can be recreated exactly.
// laf = "net.sourceforge.napkinlaf.NapkinLookAndFeel";
// laf = "javax.swing.plaf.metal.MetalLookAndFeel";
// System.setProperty("swing.metalTheme", "steel");
// laf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
// laf = "com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel";
// laf = "com.jgoodies.looks.plastic.PlasticLookAndFeel";
// laf = "com.jgoodies.looks.plastic.Plastic3DLookAndFeel";
// laf = "com.jgoodies.looks.plastic.PlasticXPLookAndFeel";
// laf = "com.jgoodies.looks.windows.WindowsLookAndFeel";
if (laf.endsWith("WindowsLookAndFeel"))
buttonOpaque = false;
if (laf.endsWith("AquaLookAndFeel"))
contentAreaFilled = false;
final String laff = laf;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(laff);
} catch (Exception ex) {
ex.printStackTrace();
}
new SwingDemo();
}
});
}
public SwingDemo()
{
super("MigLayout Swing Demo v2.5 - Mig Layout v" + LayoutUtil.getVersion());
// if (benchRuns > 0)
// RepaintManager.currentManager(this).setDoubleBufferingEnabled(false);
if (benchRuns == 0) {
sourceTextAreaScroll = createTextAreaScroll("", 5, 80, true);
sourceTextArea = (JTextArea) sourceTextAreaScroll.getViewport().getView();
}
if (DEBUG) {
contentPanel.add(layoutDisplayPanel, BorderLayout.CENTER);
// contentPanel.add(layoutPickerTabPane, BorderLayout.WEST);
// contentPanel.add(descriptionTabPane, BorderLayout.SOUTH);
} else {
contentPanel.add(layoutPickerTabPane, "spany,grow");
contentPanel.add(layoutDisplayPanel, "grow");
contentPanel.add(southTabPane, "growx");
}
setContentPane(contentPanel);
pickerList.setOpaque(OPAQUE);
((DefaultListCellRenderer) pickerList.getCellRenderer()).setOpaque(OPAQUE);
pickerList.setSelectionForeground(new Color(0, 0, 220));
pickerList.setBackground(null);
pickerList.setBorder(new EmptyBorder(2, 5, 0, 4));
pickerList.setFont(pickerList.getFont().deriveFont(Font.BOLD));
layoutPickerTabPane.addTab("Example Browser", pickerList);
descrTextAreaScroll.setBorder(null);
descrTextAreaScroll.setOpaque(OPAQUE);
descrTextAreaScroll.getViewport().setOpaque(OPAQUE);
descrTextArea.setOpaque(OPAQUE);
descrTextArea.setEditable(false);
descrTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
southTabPane.addTab("Description", descrTextAreaScroll);
if (sourceTextArea != null) {
sourceTextAreaScroll.setBorder(null);
sourceTextAreaScroll.setOpaque(OPAQUE);
sourceTextAreaScroll.getViewport().setOpaque(OPAQUE);
sourceTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
sourceTextArea.setOpaque(OPAQUE);
sourceTextArea.setLineWrap(false);
sourceTextArea.setWrapStyleWord(false);
sourceTextArea.setEditable(false);
sourceTextArea.setBorder(new EmptyBorder(0, 4, 0, 4));
sourceTextArea.setFont(new Font("monospaced", Font.PLAIN, 11));
southTabPane.addTab("Source Code", sourceTextAreaScroll);
southTabPane.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() == 2)
showSourceInFrame();
}
});
}
for (int i = 0; i < panels.length; i++)
((DefaultListModel) pickerList.getModel()).addElement(panels[i][0]);
try {
if (UIManager.getLookAndFeel().getID().equals("Aqua")) {
setSize(1000, 750);
} else {
setSize(900, 650);
}
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
} catch(Throwable t) {
t.printStackTrace();
System.exit(1);
}
pickerList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e)
{
int ix = pickerList.getSelectedIndex();
if (ix == -1 || lastIndex == ix)
return;
lastIndex = ix;
String methodName = "create" + panels[ix][0].replace(' ', '_');
layoutDisplayPanel.removeAll();
try {
pickerList.requestFocusInWindow();
final JComponent panel = (JComponent) SwingDemo.class.getMethod(methodName, new Class[0]).invoke(SwingDemo.this, new Object[0]);
layoutDisplayPanel.add(panel);
descrTextArea.setText(panels[ix][1]);
descrTextArea.setCaretPosition(0);
contentPanel.revalidate();
} catch (Exception e1) {
e1.printStackTrace(); // Should never happpen...
}
southTabPane.setSelectedIndex(0);
}
});
pickerList.requestFocusInWindow();
Toolkit.getDefaultToolkit().setDynamicLayout(true);
if (benchRuns > 0) {
doBenchmark();
} else {
pickerList.setSelectedIndex(INITIAL_INDEX);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
public boolean dispatchKeyEvent(KeyEvent e)
{
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_B && (e.getModifiersEx() & KeyEvent.CTRL_DOWN_MASK) > 0) {
startupMillis = System.currentTimeMillis();
timeToShowMillis = System.currentTimeMillis() - startupMillis;
benchRuns = 1;
doBenchmark();
return true;
}
return false;
}
});
}
}
private void doBenchmark()
{
Thread benchThread = new Thread() {
public void run()
{
for (int j = 0; j < benchRuns; j++) {
lastRunTimeStart = System.currentTimeMillis();
for (int i = 0, iCnt = pickerList.getModel().getSize(); i < iCnt; i++) {
if (benchRuns > 0 && panels[i][0].equals("Visual Bounds"))
continue; // the SWT version does not have Visual bounds...
final int ii = i;
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
pickerList.setSelectedIndex(ii);
Toolkit.getDefaultToolkit().sync();
}
});
} catch (Exception e) {
e.printStackTrace();
}
Component[] comps = layoutDisplayPanel.getComponents();
for (int cIx = 0; cIx < comps.length; cIx++) {
if (comps[cIx] instanceof JTabbedPane) {
final JTabbedPane tp = (JTabbedPane) comps[cIx];
for (int k = 0, kCnt = tp.getTabCount(); k < kCnt; k++) {
final int kk = k;
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
tp.setSelectedIndex(kk);
Toolkit.getDefaultToolkit().sync();
if (timeToShowMillis == 0)
timeToShowMillis = System.currentTimeMillis() - startupMillis;
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
if (runTimeSB != null) {
runTimeSB.append("Run ").append(j).append(": ");
runTimeSB.append(System.currentTimeMillis() - lastRunTimeStart).append(" millis.\n");
}
}
benchRunTime = System.currentTimeMillis() - startupMillis - timeToShowMillis;
final String message = "Java Version: " + System.getProperty("java.version") + "\n" +
"Look & Feel: " + UIManager.getLookAndFeel().getDescription() + "\n" +
"Time to Show: " + timeToShowMillis + " millis.\n" +
(runTimeSB != null ? runTimeSB.toString() : "") +
"Benchmark Run Time: " + benchRunTime + " millis.\n" +
"Average Run Time: " + (benchRunTime / benchRuns) + " millis (" + benchRuns + " runs).\n\n";
if (benchOutFileName == null) {
JOptionPane.showMessageDialog(SwingDemo.this, message, "Results", JOptionPane.INFORMATION_MESSAGE);
} else {
FileWriter fw = null;
try {
fw = new FileWriter(benchOutFileName, append);
fw.write(message);
} catch(IOException ex) {
ex.printStackTrace();
} finally {
if (fw != null)
try {fw.close();} catch(IOException ex) {}
}
}
System.out.println(message);
}
};
benchThread.start();
}
private void setSource(String source)
{
if (benchRuns > 0 || sourceTextArea == null)
return;
if (source.length() > 0) {
source = source.replaceAll("\t\t", "");
source = "DOUBLE CLICK TAB TO SHOW SOURCE IN SEPARATE WINDOW!\n===================================================\n\n" + source;
}
sourceTextArea.setText(source);
sourceTextArea.setCaretPosition(0);
if (sourceFrame != null && sourceFrame.isVisible()) {
sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
sourceFrameTextArea.setCaretPosition(0);
}
}
private void showSourceInFrame()
{
if (sourceTextArea == null)
return;
JScrollPane sourceFrameTextAreaScroll = createTextAreaScroll("", 5, 80, true);
sourceFrameTextArea = (JTextArea) sourceFrameTextAreaScroll.getViewport().getView();
sourceFrameTextAreaScroll.setBorder(null);
sourceFrameTextAreaScroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
sourceFrameTextArea.setLineWrap(false);
sourceFrameTextArea.setWrapStyleWord(false);
sourceFrameTextArea.setEditable(false);
sourceFrameTextArea.setBorder(new EmptyBorder(10, 10, 10, 10));
sourceFrameTextArea.setFont(new Font("monospaced", Font.PLAIN, 12));
String source = this.sourceTextArea.getText();
sourceFrameTextArea.setText(source.length() > 105 ? source.substring(105) : "No Source Code Available!");
sourceFrameTextArea.setCaretPosition(0);
sourceFrame = new JFrame("Source Code");
sourceFrame.getContentPane().add(sourceFrameTextAreaScroll, BorderLayout.CENTER);
sourceFrame.setSize(700, 800);
sourceFrame.setLocationRelativeTo(this);
sourceFrame.setVisible(true);
}
public JComponent createTest()
{
JPanel thisp = new JPanel();
MigLayout layout = new MigLayout();
thisp.setLayout(layout);
// thisp.add("wrap, span", new JButton());
// thisp.add("newline, span", new JButton());
// thisp.add("newline, span", new JButton());
// thisp.add("newline, span", new JButton());
// thisp.add("newline 100", new JButton("should have 40 pixels before"));
// thisp.add("newline", new JButton());
// thisp.add("newline", new JButton());
// thisp.add("newline", new JButton());
return thisp;
}
public JComponent createAPI_Constraints1()
{
JTabbedPane tabbedPane = new JTabbedPane();
LC layC = new LC().fill().wrap();
AC colC = new AC().align("right", 1).fill(2, 4).grow(100, 2, 4).align("right", 3).gap("15", 2);
AC rowC = new AC().align("top", 7).gap("15!", 6).grow(100, 8);
JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
// References to text fields not stored to reduce code clutter.
JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
panel.add(list2, new CC().spanY().growY().minWidth("150").gapX(null, "10"));
panel.add(new JLabel("Last Name"));
panel.add(new JTextField());
panel.add(new JLabel("First Name"));
panel.add(new JTextField(), new CC().wrap().alignX("right"));
panel.add(new JLabel("Phone"));
panel.add(new JTextField());
panel.add(new JLabel("Email"));
panel.add(new JTextField());
panel.add(new JLabel("Address 1"));
panel.add(new JTextField(), new CC().spanX().growX());
panel.add(new JLabel("Address 2"));
panel.add(new JTextField(), new CC().spanX().growX());
panel.add(new JLabel("City"));
panel.add(new JTextField(), new CC().wrap());
panel.add(new JLabel("State"));
panel.add(new JTextField());
panel.add(new JLabel("Postal Code"));
panel.add(new JTextField(10), new CC().spanX(2).growX(0));
panel.add(new JLabel("Country"));
panel.add(new JTextField(), new CC().wrap());
panel.add(new JButton("New"), new CC().spanX(5).split(5).tag("other"));
panel.add(new JButton("Delete"), new CC().tag("other"));
panel.add(new JButton("Edit"), new CC().tag("other"));
panel.add(new JButton("Save"), new CC().tag("other"));
panel.add(new JButton("Cancel"), new CC().tag("cancel"));
tabbedPane.addTab("Layout Showdown (improved)", panel);
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"LC layC = new LC().fill().wrap();\n" +
"AC colC = new AC().align(\"right\", 1).fill(2, 4).grow(100, 2, 4).align(\"right\", 3).gap(\"15\", 2);\n" +
"AC rowC = new AC().align(\"top\", 7).gap(\"15!\", 6).grow(100, 8);\n" +
"\n" +
"JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
"\n" +
"// References to text fields not stored to reduce code clutter.\n" +
"\n" +
"JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
"panel.add(list2, new CC().spanY().growY().minWidth(\"150\").gapX(null, \"10\"));\n" +
"\n" +
"panel.add(new JLabel(\"Last Name\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"First Name\"));\n" +
"panel.add(new JTextField(), new CC().wrap().alignX(\"right\"));\n" +
"panel.add(new JLabel(\"Phone\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Email\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Address 1\"));\n" +
"panel.add(new JTextField(), new CC().spanX().growX());\n" +
"panel.add(new JLabel(\"Address 2\"));\n" +
"panel.add(new JTextField(), new CC().spanX().growX());\n" +
"panel.add(new JLabel(\"City\"));\n" +
"panel.add(new JTextField(), new CC().wrap());\n" +
"panel.add(new JLabel(\"State\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Postal Code\"));\n" +
"panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
"panel.add(new JLabel(\"Country\"));\n" +
"panel.add(new JTextField(), new CC().wrap());\n" +
"\n" +
"panel.add(new JButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
"panel.add(new JButton(\"Delete\"), new CC().tag(\"other\"));\n" +
"panel.add(new JButton(\"Edit\"), new CC().tag(\"other\"));\n" +
"panel.add(new JButton(\"Save\"), new CC().tag(\"other\"));\n" +
"panel.add(new JButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
"\n" +
"tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
return tabbedPane;
}
public JComponent createAPI_Constraints2()
{
JTabbedPane tabbedPane = new JTabbedPane();
LC layC = new LC().fill().wrap();
AC colC = new AC().align("right", 0).fill(1, 3).grow(100, 1, 3).align("right", 2).gap("15", 1);
AC rowC = new AC().index(6).gap("15!").align("top").grow(100, 8);
JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient
// References to text fields not stored to reduce code clutter.
panel.add(new JLabel("Last Name"));
panel.add(new JTextField());
panel.add(new JLabel("First Name"));
panel.add(new JTextField(), new CC().wrap());
panel.add(new JLabel("Phone"));
panel.add(new JTextField());
panel.add(new JLabel("Email"));
panel.add(new JTextField());
panel.add(new JLabel("Address 1"));
panel.add(new JTextField(), new CC().spanX().growX());
panel.add(new JLabel("Address 2"));
panel.add(new JTextField(), new CC().spanX().growX());
panel.add(new JLabel("City"));
panel.add(new JTextField(), new CC().wrap());
panel.add(new JLabel("State"));
panel.add(new JTextField());
panel.add(new JLabel("Postal Code"));
panel.add(new JTextField(10), new CC().spanX(2).growX(0));
panel.add(new JLabel("Country"));
panel.add(new JTextField(), new CC().wrap());
panel.add(createButton("New"), new CC().spanX(5).split(5).tag("other"));
panel.add(createButton("Delete"), new CC().tag("other"));
panel.add(createButton("Edit"), new CC().tag("other"));
panel.add(createButton("Save"), new CC().tag("other"));
panel.add(createButton("Cancel"), new CC().tag("cancel"));
tabbedPane.addTab("Layout Showdown (improved)", panel);
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"LC layC = new LC().fill().wrap();\n" +
"AC colC = new AC().align(\"right\", 0).fill(1, 3).grow(100, 1, 3).align(\"right\", 2).gap(\"15\", 1);\n" +
"AC rowC = new AC().index(6).gap(\"15!\").align(\"top\").grow(100, 8);\n" +
"\n" +
"JPanel panel = createTabPanel(new MigLayout(layC, colC, rowC)); // Makes the background gradient\n" +
"\n" +
"// References to text fields not stored to reduce code clutter.\n" +
"\n" +
"panel.add(new JLabel(\"Last Name\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"First Name\"));\n" +
"panel.add(new JTextField(), new CC().wrap());\n" +
"panel.add(new JLabel(\"Phone\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Email\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Address 1\"));\n" +
"panel.add(new JTextField(), new CC().spanX().growX());\n" +
"panel.add(new JLabel(\"Address 2\"));\n" +
"panel.add(new JTextField(), new CC().spanX().growX());\n" +
"panel.add(new JLabel(\"City\"));\n" +
"panel.add(new JTextField(), new CC().wrap());\n" +
"panel.add(new JLabel(\"State\"));\n" +
"panel.add(new JTextField());\n" +
"panel.add(new JLabel(\"Postal Code\"));\n" +
"panel.add(new JTextField(10), new CC().spanX(2).growX(0));\n" +
"panel.add(new JLabel(\"Country\"));\n" +
"panel.add(new JTextField(), new CC().wrap());\n" +
"\n" +
"panel.add(createButton(\"New\"), new CC().spanX(5).split(5).tag(\"other\"));\n" +
"panel.add(createButton(\"Delete\"), new CC().tag(\"other\"));\n" +
"panel.add(createButton(\"Edit\"), new CC().tag(\"other\"));\n" +
"panel.add(createButton(\"Save\"), new CC().tag(\"other\"));\n" +
"panel.add(createButton(\"Cancel\"), new CC().tag(\"cancel\"));\n" +
"\n" +
"tabbedPane.addTab(\"Layout Showdown (improved)\", panel);");
return tabbedPane;
}
public JComponent createLayout_Showdown()
{
JTabbedPane tabbedPane = new JTabbedPane();
JPanel p = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[grow]"));
JScrollPane list1 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
p.add(list1, "spany, growy, wmin 150");
p.add(new JLabel("Last Name"));
p.add(new JTextField());
p.add(new JLabel("First Name"), "split"); // split divides the cell
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Phone"));
p.add(new JTextField());
p.add(new JLabel("Email"), "split");
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Address 1"));
p.add(new JTextField(), "span, growx"); // span merges cells
p.add(new JLabel("Address 2"));
p.add(new JTextField(), "span, growx");
p.add(new JLabel("City"));
p.add(new JTextField(), "wrap"); // wrap continues on next line
p.add(new JLabel("State"));
p.add(new JTextField());
p.add(new JLabel("Postal Code"), "split");
p.add(new JTextField(), "growx, wrap");
p.add(new JLabel("Country"));
p.add(new JTextField(), "wrap 15");
p.add(createButton("New"), "span, split, align left");
p.add(createButton("Delete"), "");
p.add(createButton("Edit"), "");
p.add(createButton("Save"), "");
p.add(createButton("Cancel"), "wrap push");
tabbedPane.addTab("Layout Showdown (pure)", p);
// Fixed version *******************************************
JPanel p2 = createTabPanel(new MigLayout("", "[]15[][grow,fill]15[][grow,fill]")); // Makes the background gradient
// References to text fields not stored to reduce code clutter.
JScrollPane list2 = new JScrollPane(new JList(new String[] {"Mouse, Mickey"}));
p2.add(list2, "spany, growy, wmin 150");
p2.add(new JLabel("Last Name"));
p2.add(new JTextField());
p2.add(new JLabel("First Name"));
p2.add(new JTextField(), "wrap");
p2.add(new JLabel("Phone"));
p2.add(new JTextField());
p2.add(new JLabel("Email"));
p2.add(new JTextField(), "wrap");
p2.add(new JLabel("Address 1"));
p2.add(new JTextField(), "span");
p2.add(new JLabel("Address 2"));
p2.add(new JTextField(), "span");
p2.add(new JLabel("City"));
p2.add(new JTextField(), "wrap");
p2.add(new JLabel("State"));
p2.add(new JTextField());
p2.add(new JLabel("Postal Code"));
p2.add(new JTextField(10), "growx 0, wrap");
p2.add(new JLabel("Country"));
p2.add(new JTextField(), "wrap 15");
p2.add(createButton("New"), "tag other, span, split");
p2.add(createButton("Delete"), "tag other");
p2.add(createButton("Edit"), "tag other");
p2.add(createButton("Save"), "tag other");
p2.add(createButton("Cancel"), "tag cancel, wrap push");
tabbedPane.addTab("Layout Showdown (improved)", p2);
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"JPanel p = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[grow]\"));\n" +
"\n" +
"JScrollPane list1 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
"\n" +
"p.add(list1, \"spany, growy, wmin 150\");\n" +
"p.add(new JLabel(\"Last Name\"));\n" +
"p.add(new JTextField());\n" +
"p.add(new JLabel(\"First Name\"), \"split\"); // split divides the cell\n" +
"p.add(new JTextField(), \"growx, wrap\");\n" +
"p.add(new JLabel(\"Phone\"));\n" +
"p.add(new JTextField());\n" +
"p.add(new JLabel(\"Email\"), \"split\");\n" +
"p.add(new JTextField(), \"growx, wrap\");\n" +
"p.add(new JLabel(\"Address 1\"));\n" +
"p.add(new JTextField(), \"span, growx\"); // span merges cells\n" +
"p.add(new JLabel(\"Address 2\"));\n" +
"p.add(new JTextField(), \"span, growx\");\n" +
"p.add(new JLabel(\"City\"));\n" +
"p.add(new JTextField(), \"wrap\"); // wrap continues on next line\n" +
"p.add(new JLabel(\"State\"));\n" +
"p.add(new JTextField());\n" +
"p.add(new JLabel(\"Postal Code\"), \"split\");\n" +
"p.add(new JTextField(), \"growx, wrap\");\n" +
"p.add(new JLabel(\"Country\"));\n" +
"p.add(new JTextField(), \"wrap 15\");\n" +
"\n" +
"p.add(createButton(\"New\"), \"span, split, align left\");\n" +
"p.add(createButton(\"Delete\"), \"\");\n" +
"p.add(createButton(\"Edit\"), \"\");\n" +
"p.add(createButton(\"Save\"), \"\");\n" +
"p.add(createButton(\"Cancel\"), \"wrap push\");\n" +
"\n" +
"tabbedPane.addTab(\"Layout Showdown (pure)\", p);" +
"\n" +
"\t\t// Fixed version *******************************************\n" +
"JPanel p2 = createTabPanel(new MigLayout(\"\", \"[]15[][grow,fill]15[][grow,fill]\")); // Makes the background gradient\n" +
"\n" +
"// References to text fields not stored to reduce code clutter.\n" +
"\n" +
"JScrollPane list2 = new JScrollPane(new JList(new String[] {\"Mouse, Mickey\"}));\n" +
"p2.add(list2, \"spany, growy, wmin 150\");\n" +
"p2.add(new JLabel(\"Last Name\"));\n" +
"p2.add(new JTextField());\n" +
"p2.add(new JLabel(\"First Name\"));\n" +
"p2.add(new JTextField(), \"wrap\");\n" +
"p2.add(new JLabel(\"Phone\"));\n" +
"p2.add(new JTextField());\n" +
"p2.add(new JLabel(\"Email\"));\n" +
"p2.add(new JTextField(), \"wrap\");\n" +
"p2.add(new JLabel(\"Address 1\"));\n" +
"p2.add(new JTextField(), \"span\");\n" +
"p2.add(new JLabel(\"Address 2\"));\n" +
"p2.add(new JTextField(), \"span\");\n" +
"p2.add(new JLabel(\"City\"));\n" +
"p2.add(new JTextField(), \"wrap\");\n" +
"p2.add(new JLabel(\"State\"));\n" +
"p2.add(new JTextField());\n" +
"p2.add(new JLabel(\"Postal Code\"));\n" +
"p2.add(new JTextField(10), \"growx 0, wrap\");\n" +
"p2.add(new JLabel(\"Country\"));\n" +
"p2.add(new JTextField(), \"wrap 15\");\n" +
"\n" +
"p2.add(createButton(\"New\"), \"tag other, span, split\");\n" +
"p2.add(createButton(\"Delete\"), \"tag other\");\n" +
"p2.add(createButton(\"Edit\"), \"tag other\");\n" +
"p2.add(createButton(\"Save\"), \"tag other\");\n" +
"p2.add(createButton(\"Cancel\"), \"tag cancel, wrap push\");\n" +
"\n" +
"tabbedPane.addTab(\"Layout Showdown (improved)\", p2);");
return tabbedPane;
}
public JComponent createWelcome()
{
JTabbedPane tabbedPane = new JTabbedPane();
MigLayout lm = new MigLayout("ins 20, fill", "", "[grow]unrel[]");
JPanel mainPanel = createTabPanel(lm);
String s = "MigLayout's main purpose is to make layouts for SWT and Swing, and possibly other frameworks, much more powerful and a lot easier to create, especially for manual coding.\n\n" +
"The motto is: \"MigLayout makes complex layouts easy and normal layouts one-liners.\"\n\n" +
"The layout engine is very flexible and advanced, something that is needed to make it simple to use yet handle almost all layout use-cases.\n\n" +
"MigLayout can handle all layouts that the commonly used Swing Layout Managers can handle and this with a lot of extra features. " +
"It also incorporates most, if not all, of the open source alternatives FormLayout's and TableLayout's functionality." +
"\n\n\nThanks to Karsten Lentzsch of JGoodies.com for allowing the reuse of the main demo application layout and for his inspiring talks that led to this layout Manager." +
"\n\n\nMikael Grev\n" +
"MiG InfoCom AB\n" +
"miglayout@miginfocom.com";
JTextArea textArea = new JTextArea(s);
textArea.setEditable(false);
textArea.setSize(400, 400);
if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.WINDOWS_XP)
textArea.setFont(new Font("tahoma", Font.BOLD, 11));
textArea.setOpaque(OPAQUE);
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
JLabel label = new JLabel("You can Right Click any Component or Container to change the constraints for it!");
label.setForeground(new Color(200, 0, 0));
mainPanel.add(textArea, "wmin 500, ay top, grow, push, wrap");
mainPanel.add(label, "growx");
label.setFont(label.getFont().deriveFont(Font.BOLD));
tabbedPane.addTab("Welcome", mainPanel);
setSource("");
return tabbedPane;
}
public JComponent createVisual_Bounds()
{
JTabbedPane tabbedPane = new JTabbedPane();
// "NON"-corrected bounds
JPanel p1 = createTabPanel(new MigLayout("fill, ins 3, novisualpadding"));
p1.setBorder(new LineBorder(Color.BLACK));
JTabbedPane demoPane2 = new JTabbedPane();
JPanel demoPanel2 = new JPanel();
demoPanel2.setBackground(Color.WHITE);
demoPane2.addTab("Demo Tab", demoPanel2);
p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
p1.add(demoPane2, "grow, aligny bottom");
p1.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
p1.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
p1.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
JPanel p2 = createTabPanel(new MigLayout("center,center,fill,ins 3"));
p2.setBorder(new LineBorder(Color.BLACK));
JTabbedPane demoPane = new JTabbedPane();
JPanel demoPanel = new JPanel();
demoPanel.setBackground(Color.WHITE);
demoPane.addTab("Demo Tab", demoPanel);
p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
p2.add(demoPane, "grow, aligny bottom");
p2.add(createTextField("A JTextField", 100), "grow, aligny bottom, wmin 100");
p2.add(createTextArea("A JTextArea", 1, 100), "newline,grow, aligny bottom, wmin 100");
p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
p2.add(createTextArea("A JTextArea", 1, 100), "grow, aligny bottom, wmin 100");
tabbedPane.addTab("Visual Bounds (Not Corrected)", p1);
tabbedPane.addTab("Visual Bounds (Corrected on XP)", p2);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// \"NON\"-corrected bounds\n" +
"JPanel p1 = createTabPanel(new MigLayout(\"fill, ins 3, novisualpadding\"));\n" +
"p1.setBorder(new LineBorder(Color.BLACK));\n" +
"\n" +
"JTabbedPane demoPane2 = new JTabbedPane();\n" +
"JPanel demoPanel2 = new JPanel();\n" +
"demoPanel2.setBackground(Color.WHITE);\n" +
"demoPane2.addTab(\"Demo Tab\", demoPanel2);\n" +
"\n" +
"p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"p1.add(demoPane2, \"grow, aligny bottom\");\n" +
"p1.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
"p1.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
"p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"p1.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"\n" +
"JPanel p2 = createTabPanel(new MigLayout(\"center,center,fill,ins 3\"));\n" +
"p2.setBorder(new LineBorder(Color.BLACK));\n" +
"\n" +
"JTabbedPane demoPane = new JTabbedPane();\n" +
"JPanel demoPanel = new JPanel();\n" +
"demoPanel.setBackground(Color.WHITE);\n" +
"demoPane.addTab(\"Demo Tab\", demoPanel);\n" +
"\n" +
"p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"p2.add(demoPane, \"grow, aligny bottom\");\n" +
"p2.add(createTextField(\"A JTextField\", 100), \"grow, aligny bottom, wmin 100\");\n" +
"p2.add(createTextArea(\"A JTextArea\", 1, 100), \"newline,grow, aligny bottom, wmin 100\");\n" +
"p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"p2.add(createTextArea(\"A JTextArea\", 1, 100), \"grow, aligny bottom, wmin 100\");\n" +
"\n" +
"tabbedPane.addTab(\"Visual Bounds (Not Corrected)\", p1);\n" +
"tabbedPane.addTab(\"Visual Bounds (Corrected on XP)\", p2);");
return tabbedPane;
}
public JComponent createDocking()
{
JTabbedPane tabbedPane = new JTabbedPane();
JPanel p1 = createTabPanel(new MigLayout("fill"));
p1.add(createPanel("1. North"), "north");
p1.add(createPanel("2. West"), "west");
p1.add(createPanel("3. East"), "east");
p1.add(createPanel("4. South"), "south");
String[][] data = new String[20][6];
for (int r = 0; r < data.length; r++) {
data[r] = new String[6];
for (int c = 0; c < data[r].length; c++)
data[r][c] = "Cell " + (r + 1) + ", " + (c + 1);
}
JTable table = new JTable(data, new String[] {"Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Column 6"});
p1.add(new JScrollPane(table), "grow");
JPanel p2 = createTabPanel(new MigLayout("fill", "[c]", ""));
p2.add(createPanel("1. North"), "north");
p2.add(createPanel("2. North"), "north");
p2.add(createPanel("3. West"), "west");
p2.add(createPanel("4. West"), "west");
p2.add(createPanel("5. South"), "south");
p2.add(createPanel("6. East"), "east");
p2.add(createButton("7. Normal"));
p2.add(createButton("8. Normal"));
p2.add(createButton("9. Normal"));
JPanel p3 = createTabPanel(new MigLayout());
p3.add(createPanel("1. North"), "north");
p3.add(createPanel("2. South"), "south");
p3.add(createPanel("3. West"), "west");
p3.add(createPanel("4. East"), "east");
p3.add(createButton("5. Normal"));
JPanel p4 = createTabPanel(new MigLayout());
p4.add(createPanel("1. North"), "north");
p4.add(createPanel("2. North"), "north");
p4.add(createPanel("3. West"), "west");
p4.add(createPanel("4. West"), "west");
p4.add(createPanel("5. South"), "south");
p4.add(createPanel("6. East"), "east");
p4.add(createButton("7. Normal"));
p4.add(createButton("8. Normal"));
p4.add(createButton("9. Normal"));
JPanel p5 = createTabPanel(new MigLayout("fillx", "[c]", ""));
p5.add(createPanel("1. North"), "north");
p5.add(createPanel("2. North"), "north");
p5.add(createPanel("3. West"), "west");
p5.add(createPanel("4. West"), "west");
p5.add(createPanel("5. South"), "south");
p5.add(createPanel("6. East"), "east");
p5.add(createButton("7. Normal"));
p5.add(createButton("8. Normal"));
p5.add(createButton("9. Normal"));
JPanel p6 = createTabPanel(new MigLayout("fill", "", ""));
Random rand = new Random();
String[] sides = {"north", "east", "south", "west"};
for (int i = 0; i < 20; i++) {
int side = rand.nextInt(4);
p6.add(createPanel((i + 1) + " " + sides[side]), sides[side]);
}
p6.add(createPanel("I'm in the Center!"), "dock center");
tabbedPane.addTab("Docking 1 (fill)", p1);
tabbedPane.addTab("Docking 2 (fill)", p2);
tabbedPane.addTab("Docking 3", p3);
tabbedPane.addTab("Docking 4", p4);
tabbedPane.addTab("Docking 5 (fillx)", p5);
tabbedPane.addTab("Random Docking", new JScrollPane(p6));
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"JPanel p1 = createTabPanel(new MigLayout(\"fill\"));\n" +
"\n" +
"p1.add(createPanel(\"1. North\"), \"north\");\n" +
"p1.add(createPanel(\"2. West\"), \"west\");\n" +
"p1.add(createPanel(\"3. East\"), \"east\");\n" +
"p1.add(createPanel(\"4. South\"), \"south\");\n" +
"\n" +
"String[][] data = new String[20][6];\n" +
"for (int r = 0; r < data.length; r++) {\n" +
"\tdata[r] = new String[6];\n" +
"\tfor (int c = 0; c < data[r].length; c++)\n" +
"\t\tdata[r][c] = \"Cell \" + (r + 1) + \", \" + (c + 1);\n" +
"}\n" +
"JTable table = new JTable(data, new String[] {\"Column 1\", \"Column 2\", \"Column 3\", \"Column 4\", \"Column 5\", \"Column 6\"});\n" +
"p1.add(new JScrollPane(table), \"grow\");\n" +
"\n" +
"JPanel p2 = createTabPanel(new MigLayout(\"fill\", \"[c]\", \"\"));\n" +
"\n" +
"p2.add(createPanel(\"1. North\"), \"north\");\n" +
"p2.add(createPanel(\"2. North\"), \"north\");\n" +
"p2.add(createPanel(\"3. West\"), \"west\");\n" +
"p2.add(createPanel(\"4. West\"), \"west\");\n" +
"p2.add(createPanel(\"5. South\"), \"south\");\n" +
"p2.add(createPanel(\"6. East\"), \"east\");\n" +
"p2.add(createButton(\"7. Normal\"));\n" +
"p2.add(createButton(\"8. Normal\"));\n" +
"p2.add(createButton(\"9. Normal\"));\n" +
"\n" +
"JPanel p3 = createTabPanel(new MigLayout());\n" +
"\n" +
"p3.add(createPanel(\"1. North\"), \"north\");\n" +
"p3.add(createPanel(\"2. South\"), \"south\");\n" +
"p3.add(createPanel(\"3. West\"), \"west\");\n" +
"p3.add(createPanel(\"4. East\"), \"east\");\n" +
"p3.add(createButton(\"5. Normal\"));\n" +
"\n" +
"JPanel p4 = createTabPanel(new MigLayout());\n" +
"\n" +
"p4.add(createPanel(\"1. North\"), \"north\");\n" +
"p4.add(createPanel(\"2. North\"), \"north\");\n" +
"p4.add(createPanel(\"3. West\"), \"west\");\n" +
"p4.add(createPanel(\"4. West\"), \"west\");\n" +
"p4.add(createPanel(\"5. South\"), \"south\");\n" +
"p4.add(createPanel(\"6. East\"), \"east\");\n" +
"p4.add(createButton(\"7. Normal\"));\n" +
"p4.add(createButton(\"8. Normal\"));\n" +
"p4.add(createButton(\"9. Normal\"));\n" +
"\n" +
"JPanel p5 = createTabPanel(new MigLayout(\"fillx\", \"[c]\", \"\"));\n" +
"\n" +
"p5.add(createPanel(\"1. North\"), \"north\");\n" +
"p5.add(createPanel(\"2. North\"), \"north\");\n" +
"p5.add(createPanel(\"3. West\"), \"west\");\n" +
"p5.add(createPanel(\"4. West\"), \"west\");\n" +
"p5.add(createPanel(\"5. South\"), \"south\");\n" +
"p5.add(createPanel(\"6. East\"), \"east\");\n" +
"p5.add(createButton(\"7. Normal\"));\n" +
"p5.add(createButton(\"8. Normal\"));\n" +
"p5.add(createButton(\"9. Normal\"));\n" +
"\n" +
"JPanel p6 = createTabPanel(new MigLayout(\"fill\", \"\", \"\"));\n" +
"\n" +
"Random rand = new Random();\n" +
"String[] sides = {\"north\", \"east\", \"south\", \"west\"};\n" +
"for (int i = 0; i < 20; i++) {\n" +
"\tint side = rand.nextInt(4);\n" +
"\tp6.add(createPanel((i + 1) + \" \" + sides[side]), sides[side]);\n" +
"}\n" +
"p6.add(createButton(\"I'm in the middle!\"), \"grow\");\n" +
"\n" +
"tabbedPane.addTab(\"Docking 1 (fill)\", p1);\n" +
"tabbedPane.addTab(\"Docking 2 (fill)\", p2);\n" +
"tabbedPane.addTab(\"Docking 3\", p3);\n" +
"tabbedPane.addTab(\"Docking 4\", p4);\n" +
"tabbedPane.addTab(\"Docking 5 (fillx)\", p5);\n" +
"tabbedPane.addTab(\"Docking Spiral\", new JScrollPane(p6));");
return tabbedPane;
}
public JComponent createAbsolute_Position()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Pos tab
final JPanel posPanel = createTabPanel(new MigLayout());
posPanel.add(createButton(), "pos 0.5al 0al");
posPanel.add(createButton(), "pos 1al 0al");
posPanel.add(createButton(), "pos 0.5al 0.5al");
posPanel.add(createButton(), "pos 5in 45lp");
posPanel.add(createButton(), "pos 0.5al 0.5al");
posPanel.add(createButton(), "pos 0.5al 1.0al");
posPanel.add(createButton(), "pos 1al .25al");
posPanel.add(createButton(), "pos visual.x2-pref visual.y2-pref");
posPanel.add(createButton(), "pos 1al -1in");
posPanel.add(createButton(), "pos 100 100");
posPanel.add(createButton(), "pos (10+(20*3lp)) 200");
posPanel.add(createButton("Drag Window! (pos 500-container.xpos 500-container.ypos)"),
"pos 500-container.xpos 500-container.ypos");
// Bounds tab
JPanel boundsPanel = createTabPanel(new MigLayout());
String constr = "pos (visual.x+visual.w*0.1) visual.y2-40 (visual.x2-visual.w*0.1) visual.y2";
JLabel southLabel = createLabel(constr, SwingConstants.CENTER);
southLabel.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
southLabel.setBackground(new Color(200, 200, 255, benchRuns == 0 ? 70 : 255));
southLabel.setOpaque(true);
southLabel.setFont(southLabel.getFont().deriveFont(Font.BOLD));
boundsPanel.add(southLabel, constr);
boundsPanel.add(createButton(), "pos 0 0 container.x2 n");
boundsPanel.add(createButton(), "pos visual.x 40 visual.x2 70");
boundsPanel.add(createButton(), "pos visual.x 100 visual.x2 p");
boundsPanel.add(createButton(), "pos 0.1al 0.4al n (visual.y2 - 10)");
boundsPanel.add(createButton(), "pos 0.9al 0.4al n visual.y2-10");
boundsPanel.add(createButton(), "pos 0.5al 0.5al, pad 3 0 -3 0");
boundsPanel.add(createButton(), "pos n n 50% 50%");
boundsPanel.add(createButton(), "pos 50% 50% n n");
boundsPanel.add(createButton(), "pos 50% n n 50%");
boundsPanel.add(createButton(), "pos n 50% 50% n");
tabbedPane.addTab("X Y Positions", posPanel);
tabbedPane.addTab("X1 Y1 X2 Y2 Bounds", boundsPanel);
// Glass pane tab
if (benchRuns == 0) {
final JPanel glassPanel = createTabPanel(new MigLayout("align c c, ins 0"));
final JButton butt = createButton("Press me!!");
glassPanel.add(butt);
butt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
butt.setEnabled(false);
final JPanel bg = new JPanel(new MigLayout("align c c,fill")) {
public void paint(Graphics g)
{
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
super.paint(g);
}
};
bg.setOpaque(OPAQUE);
configureActiveComponet(bg);
final JLabel label = createLabel("You don't need a GlassPane to be cool!");
label.setFont(label.getFont().deriveFont(30f));
label.setForeground(new Color(255, 255, 255, 0));
bg.add(label, "align 50% 30%");
glassPanel.add(bg, "pos visual.x visual.y visual.x2 visual.y2", 0);
final long startTime = System.nanoTime();
final long endTime = startTime + 500000000L;
glassPanel.revalidate();
final javax.swing.Timer timer = new Timer(25, null);
timer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
long now = System.nanoTime();
int alpha = (int) (((now - startTime) / (double) (endTime - startTime)) * 300);
if (alpha < 150)
bg.setBackground(new Color(100, 100, 100, alpha));
if (alpha > 150 && alpha < 405) {
label.setForeground(new Color(255, 255, 255, (alpha - 150)));
bg.repaint();
}
if (alpha > 405)
timer.stop();
}
});
timer.start();
}
});
tabbedPane.addTab("GlassPane Substitute", glassPanel);
addComponentListener(new ComponentAdapter() {
public void componentMoved(ComponentEvent e) {
if (posPanel.isDisplayable()) {
posPanel.revalidate();
} else {
removeComponentListener(this);
}
}
});
}
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Pos tab\n" +
"final JPanel posPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"posPanel.add(createButton(), \"pos 0.5al 0al\");\n" +
"posPanel.add(createButton(), \"pos 1al 0al\");\n" +
"posPanel.add(createButton(), \"pos 0.5al 0.5al\");\n" +
"posPanel.add(createButton(), \"pos 5in 45lp\");\n" +
"posPanel.add(createButton(), \"pos 0.5al 0.5al\");\n" +
"posPanel.add(createButton(), \"pos 0.5al 1.0al\");\n" +
"posPanel.add(createButton(), \"pos 1al .25al\");\n" +
"posPanel.add(createButton(), \"pos visual.x2-pref visual.y2-pref\");\n" +
"posPanel.add(createButton(), \"pos 1al -1in\");\n" +
"posPanel.add(createButton(), \"pos 100 100\");\n" +
"posPanel.add(createButton(), \"pos (10+(20*3lp)) 200\");\n" +
"posPanel.add(createButton(\"Drag Window! (pos 500-container.xpos 500-container.ypos)\"),\n" +
" \"pos 500-container.xpos 500-container.ypos\");\n" +
"\n" +
"// Bounds tab\n" +
"JPanel boundsPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"String constr = \"pos (visual.x+visual.w*0.1) visual.y2-40 (visual.x2-visual.w*0.1) visual.y2\";\n" +
"JLabel southLabel = createLabel(constr, SwingConstants.CENTER);\n" +
"southLabel.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));\n" +
"southLabel.setBackground(new Color(200, 200, 255, 70));\n" +
"southLabel.setOpaque(true);\n" +
"southLabel.setFont(southLabel.getFont().deriveFont(Font.BOLD));\n" +
"boundsPanel.add(southLabel, constr);\n" +
"\n" +
"boundsPanel.add(createButton(), \"pos 0 0 container.x2 n\");\n" +
"boundsPanel.add(createButton(), \"pos visual.x 40 visual.x2 70\");\n" +
"boundsPanel.add(createButton(), \"pos visual.x 100 visual.x2 p\");\n" +
"boundsPanel.add(createButton(), \"pos 0.1al 0.4al n visual.y2-10\");\n" +
"boundsPanel.add(createButton(), \"pos 0.9al 0.4al n visual.y2-10\");\n" +
"boundsPanel.add(createButton(), \"pos 0.5al 0.5al, pad 3 0 -3 0\");\n" +
"boundsPanel.add(createButton(), \"pos n n 50% 50%\");\n" +
"boundsPanel.add(createButton(), \"pos 50% 50% n n\");\n" +
"boundsPanel.add(createButton(), \"pos 50% n n 50%\");\n" +
"boundsPanel.add(createButton(), \"pos n 50% 50% n\");\n" +
"\n" +
"// Glass pane tab\n" +
"final JPanel glassPanel = createTabPanel(new MigLayout(\"align c c, ins 0\"));\n" +
"final JButton butt = createButton(\"Press me!!\");\n" +
"glassPanel.add(butt);\n" +
"\n" +
"butt.addActionListener(new ActionListener()\t\t{\n" +
"\tpublic void actionPerformed(ActionEvent e)\n" +
"\t{\n" +
"\t\tbutt.setEnabled(false);\n" +
"\t\tfinal JPanel bg = new JPanel(new MigLayout(\"align c c,fill\")) {\n" +
"\t\t\tpublic void paint(Graphics g)\n" +
"\t\t\t{\n" +
"\t\t\t\tg.setColor(getBackground());\n" +
"\t\t\t\tg.fillRect(0, 0, getWidth(), getHeight());\n" +
"\t\t\t\tsuper.paint(g);\n" +
"\t\t\t}\n" +
"\t\t};\n" +
"\t\tbg.setOpaque(OPAQUE);\n" +
"\t\tconfigureActiveComponet(bg);\n" +
"\n" +
"\t\tfinal JLabel label = createLabel(\"You don't need a GlassPane to be cool!\");\n" +
"\t\tlabel.setFont(label.getFont().deriveFont(30f));\n" +
"\t\tlabel.setForeground(new Color(255, 255, 255, 0));\n" +
"\t\tbg.add(label, \"align 50% 30%\");\n" +
"\n" +
"\t\tglassPanel.add(bg, \"pos visual.x visual.y visual.x2 visual.y2\", 0);\n" +
"\t\tfinal long startTime = System.nanoTime();\n" +
"\t\tfinal long endTime = startTime + 500000000L;\n" +
"\n" +
"\t\tglassPanel.revalidate();\n" +
"\n" +
"\t\tfinal javax.swing.Timer timer = new Timer(25, null);\n" +
"\n" +
"\t\ttimer.addActionListener(new ActionListener() {\n" +
"\t\t\tpublic void actionPerformed(ActionEvent e)\n" +
"\t\t\t{\n" +
"\t\t\t\tlong now = System.nanoTime();\n" +
"\t\t\t\tint alpha = (int) (((now - startTime) / (double) (endTime - startTime)) * 300);\n" +
"\t\t\t\tif (alpha < 150)\n" +
"\t\t\t\t\tbg.setBackground(new Color(100, 100, 100, alpha));\n" +
"\n" +
"\t\t\t\tif (alpha > 150 && alpha < 405) {\n" +
"\t\t\t\t\tlabel.setForeground(new Color(255, 255, 255, (alpha - 150)));\n" +
"\t\t\t\t\tbg.repaint();\n" +
"\t\t\t\t}\n" +
"\t\t\t\tif (alpha > 405)\n" +
"\t\t\t\t\ttimer.stop();\n" +
"\t\t\t}\n" +
"\t\t});\n" +
"\t\ttimer.start();\n" +
"\t}\n" +
"});\n" +
"\n" +
"tabbedPane.addTab(\"X Y Positions\", posPanel);\n" +
"tabbedPane.addTab(\"X1 Y1 X2 Y2 Bounds\", boundsPanel);\n" +
"tabbedPane.addTab(\"GlassPane Substitute\", glassPanel);\n" +
"\n" +
"addComponentListener(new ComponentAdapter() {\n" +
"\tpublic void componentMoved(ComponentEvent e) {\n" +
"\t\tif (posPanel.isDisplayable()) {\n" +
"\t\t\tposPanel.revalidate();\n" +
"\t\t} else {\n" +
"\t\t\tremoveComponentListener(this);\n" +
"\t\t}\n" +
"\t}\n" +
"});");
return tabbedPane;
}
public JComponent createComponent_Links()
{
JTabbedPane tabbedPane = new JTabbedPane();
JPanel linksPanel = createTabPanel(new MigLayout());
// Links tab
JButton mini = createButton("Mini");
mini.setMargin(new Insets(0, 1, 0, 1));
linksPanel.add(mini, "pos null ta.y ta.x2 null");
linksPanel.add(createTextArea("Components, Please Link to Me!\nMy ID is: 'ta'", 3, 30), "id ta, pos 0.5al 0.5al");
linksPanel.add(createButton(), "id b1,pos ta.x2 ta.y2");
linksPanel.add(createButton(), "pos b1.x2+rel b1.y visual.x2 null");
linksPanel.add(createButton(), "pos ta.x2+rel ta.y visual.x2 null");
linksPanel.add(createButton(), "pos null ta.y+(ta.h-pref)/2 ta.x-rel null");
linksPanel.add(createButton(), "pos ta.x ta.y2+100 ta.x2 null");
linksPanel.add(createCheck("pos (ta.x+indent) (ta.y2+rel)"),
"pos (ta.x+indent) (ta.y2+rel)");
// External tab
JPanel externalPanel = createTabPanel(new MigLayout());
JButton extButt = createButton("Bounds Externally Set!");
extButt.setBounds(250, 130, 200, 40);
externalPanel.add(extButt, "id ext, external");
externalPanel.add(createButton(), "pos ext.x2 ext.y2");
externalPanel.add(createButton(), "pos null null ext.x ext.y");
// Start/End Group tab
JPanel egPanel = createTabPanel(new MigLayout());
egPanel.add(createButton(), "id b1, endgroupx g1, pos 200 200");
egPanel.add(createButton(), "id b2, endgroupx g1, pos (b1.x+2ind) (b1.y2+rel)");
egPanel.add(createButton(), "id b3, endgroupx g1, pos (b1.x+4ind) (b2.y2+rel)");
egPanel.add(createButton(), "id b4, endgroupx g1, pos (b1.x+6ind) (b3.y2+rel)");
// Group Bounds tab
JPanel gpPanel = createTabPanel(new MigLayout());
gpPanel.add(createButton(), "id grp1.b1, pos n 0.5al 50% n");
gpPanel.add(createButton(), "id grp1.b2, pos 50% 0.5al n n");
gpPanel.add(createButton(), "id grp1.b3, pos 0.5al n n b1.y");
gpPanel.add(createButton(), "id grp1.b4, pos 0.5al b1.y2 n n");
gpPanel.add(createButton(), "pos n grp1.y2 grp1.x n");
gpPanel.add(createButton(), "pos n n grp1.x grp1.y");
gpPanel.add(createButton(), "pos grp1.x2 n n grp1.y");
gpPanel.add(createButton(), "pos grp1.x2 grp1.y2");
JPanel boundsPanel = new JPanel(null);
boundsPanel.setBackground(new Color(200, 200, 255));
gpPanel.add(boundsPanel, "pos grp1.x grp1.y grp1.x2 grp1.y2");
tabbedPane.addTab("Component Links", linksPanel);
tabbedPane.addTab("External Components", externalPanel);
tabbedPane.addTab("End Grouping", egPanel);
tabbedPane.addTab("Group Bounds", gpPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"JPanel linksPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"// Links tab\n" +
"JButton mini = createButton(\"Mini\");\n" +
"mini.setMargin(new Insets(0, 1, 0, 1));\n" +
"linksPanel.add(mini, \"pos null ta.y ta.x2 null\");\n" +
"linksPanel.add(createTextArea(\"Components, Please Link to Me!\\nMy ID is: 'ta'\", 3, 30), \"id ta, pos 0.5al 0.5al\");\n" +
"linksPanel.add(createButton(), \"id b1,pos ta.x2 ta.y2\");\n" +
"linksPanel.add(createButton(), \"pos b1.x2+rel b1.y visual.x2 null\");\n" +
"linksPanel.add(createButton(), \"pos ta.x2+rel ta.y visual.x2 null\");\n" +
"linksPanel.add(createButton(), \"pos null ta.y+(ta.h-pref)/2 ta.x-rel null\");\n" +
"linksPanel.add(createButton(), \"pos ta.x ta.y2+100 ta.x2 null\");\n" +
"linksPanel.add(createCheck(\"pos (ta.x+indent) (ta.y2+rel)\"),\n" +
" \"pos (ta.x+indent) (ta.y2+rel)\");\n" +
"\n" +
"// External tab\n" +
"JPanel externalPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"JButton extButt = createButton(\"Bounds Externally Set!\");\n" +
"extButt.setBounds(250, 130, 200, 40);\n" +
"externalPanel.add(extButt, \"id ext, external\");\n" +
"externalPanel.add(createButton(), \"pos ext.x2 ext.y2\");\n" +
"externalPanel.add(createButton(), \"pos null null ext.x ext.y\");\n" +
"\n" +
"// Start/End Group tab\n" +
"JPanel egPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"egPanel.add(createButton(), \"id b1, endgroupx g1, pos 200 200\");\n" +
"egPanel.add(createButton(), \"id b2, endgroupx g1, pos (b1.x+2ind) (b1.y2+rel)\");\n" +
"egPanel.add(createButton(), \"id b3, endgroupx g1, pos (b1.x+4ind) (b2.y2+rel)\");\n" +
"egPanel.add(createButton(), \"id b4, endgroupx g1, pos (b1.x+6ind) (b3.y2+rel)\");\n" +
"\n" +
"// Group Bounds tab\n" +
"JPanel gpPanel = createTabPanel(new MigLayout());\n" +
"\n" +
"gpPanel.add(createButton(), \"id grp1.b1, pos n 0.5al 50% n\");\n" +
"gpPanel.add(createButton(), \"id grp1.b2, pos 50% 0.5al n n\");\n" +
"gpPanel.add(createButton(), \"id grp1.b3, pos 0.5al n n b1.y\");\n" +
"gpPanel.add(createButton(), \"id grp1.b4, pos 0.5al b1.y2 n n\");\n" +
"\n" +
"gpPanel.add(createButton(), \"pos n grp1.y2 grp1.x n\");\n" +
"gpPanel.add(createButton(), \"pos n n grp1.x grp1.y\");\n" +
"gpPanel.add(createButton(), \"pos grp1.x2 n n grp1.y\");\n" +
"gpPanel.add(createButton(), \"pos grp1.x2 grp1.y2\");\n" +
"\n" +
"JPanel boundsPanel = new JPanel(null);\n" +
"boundsPanel.setBackground(new Color(200, 200, 255));\n" +
"gpPanel.add(boundsPanel, \"pos grp1.x grp1.y grp1.x2 grp1.y2\");\n" +
"\n" +
"\n" +
"tabbedPane.addTab(\"Component Links\", linksPanel);\n" +
"tabbedPane.addTab(\"External Components\", externalPanel);\n" +
"tabbedPane.addTab(\"End Grouping\", egPanel);\n" +
"tabbedPane.addTab(\"Group Bounds\", gpPanel);");
return tabbedPane;
}
public JComponent createFlow_Direction()
{
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("Layout: flowx, Cell: flowx", createFlowPanel("", "flowx"));
tabbedPane.addTab("Layout: flowx, Cell: flowy", createFlowPanel("", "flowy"));
tabbedPane.addTab("Layout: flowy, Cell: flowx", createFlowPanel("flowy", "flowx"));
tabbedPane.addTab("Layout: flowy, Cell: flowy", createFlowPanel("flowy", "flowy"));
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"tabbedPane.addTab(\"Layout: flowx, Cell: flowx\", createFlowPanel(\"\", \"flowx\"));\n" +
"tabbedPane.addTab(\"Layout: flowx, Cell: flowy\", createFlowPanel(\"\", \"flowy\"));\n" +
"tabbedPane.addTab(\"Layout: flowy, Cell: flowx\", createFlowPanel(\"flowy\", \"flowx\"));\n" +
"tabbedPane.addTab(\"Layout: flowy, Cell: flowy\", createFlowPanel(\"flowy\", \"flowy\"));" +
"\n\tpublic JPanel createFlowPanel(String gridFlow, String cellFlow)\n" +
"\t{\n" +
"MigLayout lm = new MigLayout(\"center, wrap 3,\" + gridFlow,\n" +
" \"[110,fill]\",\n" +
" \"[110,fill]\");\n" +
"JPanel panel = createTabPanel(lm);\n" +
"\n" +
"for (int i = 0; i < 9; i++) {\n" +
"\tJButton b = createButton(\"\" + (i + 1));\n" +
"\tb.setFont(b.getFont().deriveFont(20f));\n" +
"\tpanel.add(b, cellFlow);\n" +
"}\n" +
"\n" +
"JButton b = createButton(\"5:2\");\n" +
"b.setFont(b.getFont().deriveFont(20f));\n" +
"panel.add(b, cellFlow + \",cell 1 1\");\n" +
"\n" +
"return panel;\n" +
"\t}");
return tabbedPane;
}
public JPanel createFlowPanel(String gridFlow, String cellFlow)
{
MigLayout lm = new MigLayout("center, wrap 3," + gridFlow,
"[110,fill]",
"[110,fill]");
JPanel panel = createTabPanel(lm);
Font f = panel.getFont().deriveFont(20f);
for (int i = 0; i < 9; i++) {
JComponent b = createPanel("" + (i + 1));
b.setFont(f);
panel.add(b, cellFlow);
}
JComponent b = createPanel("5:2");
b.setFont(f);
panel.add(b, cellFlow + ",cell 1 1");
return panel;
}
public JComponent createDebug()
{
return createPlainImpl(true);
}
public JComponent createButton_Bars()
{
MigLayout lm = new MigLayout("ins 0 0 15lp 0",
"[grow]",
"[grow][baseline,nogrid]");
final JPanel mainPanel = new JPanel(lm);
final JLabel formatLabel = createLabel("");
formatLabel.setFont(formatLabel.getFont().deriveFont(Font.BOLD));
JTabbedPane tabbedPane = new JTabbedPane();
JToggleButton winButt = createToggleButton("Windows");
JToggleButton macButt = createToggleButton("Mac OS X");
JButton helpButt = createButton("Help");
if (benchRuns == 0) {
winButt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
formatLabel.setText("'" + PlatformDefaults.getButtonOrder() + "'");
((JPanel) ((JFrame) Frame.getFrames()[0]).getContentPane()).revalidate();
}
});
macButt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
PlatformDefaults.setPlatform(PlatformDefaults.MAC_OSX);
formatLabel.setText(PlatformDefaults.getButtonOrder());
((JPanel) ((JFrame) Frame.getFrames()[0]).getContentPane()).revalidate();
}
});
helpButt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(mainPanel, "See JavaDoc for PlatformConverter.getButtonBarOrder(..) for details on the format string.");
}
});
}
ButtonGroup bg = new ButtonGroup();
bg.add(winButt);
bg.add(macButt);
if (benchRuns == 0) {
if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.MAC_OSX) {
macButt.doClick();
} else {
winButt.doClick();
}
}
tabbedPane.addTab("Buttons", createButtonBarsPanel("help", false));
tabbedPane.addTab("Buttons with Help2", createButtonBarsPanel("help2", false));
tabbedPane.addTab("Buttons (Same width)", createButtonBarsPanel("help", true));
mainPanel.add(tabbedPane, "grow,wrap");
mainPanel.add(createLabel("Button Order:"));
mainPanel.add(formatLabel, "growx");
mainPanel.add(winButt);
mainPanel.add(macButt);
mainPanel.add(helpButt, "gapbefore unrel");
// Disregard. Just forgetting the source code text close to the source code.
setSource("MigLayout lm = new MigLayout(\"ins 0 0 15lp 0\",\n" +
" \"[grow]\",\n" +
" \"[grow][baseline,nogrid,gap unrelated]\");\n" +
"\n" +
"final JPanel mainPanel = new JPanel(lm);\n" +
"final JLabel formatLabel = createLabel(\"\");\n" +
"formatLabel.setFont(formatLabel.getFont().deriveFont(Font.BOLD));\n" +
"JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"JToggleButton winButt = createToggleButton(\"Windows\");\n" +
"\n" +
"winButt.addActionListener(new ActionListener() {\n" +
"\tpublic void actionPerformed(ActionEvent e) {\n" +
"\t\tPlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);\n" +
"\t\tformatLabel.setText(\"'\" + PlatformDefaults.getButtonOrder() + \"'\");\n" +
"\t\tSwingUtilities.updateComponentTreeUI(mainPanel);\n" +
"\t}\n" +
"});\n" +
"\n" +
"JToggleButton macButt = createToggleButton(\"Mac OS X\");\n" +
"macButt.addActionListener(new ActionListener() {\n" +
"\tpublic void actionPerformed(ActionEvent e) {\n" +
"\t\tPlatformDefaults.setPlatform(PlatformDefaults.MAC_OSX);\n" +
"\t\tformatLabel.setText(PlatformDefaults.getButtonOrder());\n" +
"\t\tSwingUtilities.updateComponentTreeUI(mainPanel);\n" +
"\t}\n" +
"});\n" +
"\n" +
"JButton helpButt = createButton(\"Help\");\n" +
"helpButt.addActionListener(new ActionListener() {\n" +
"\tpublic void actionPerformed(ActionEvent e) {\n" +
"\t\tJOptionPane.showMessageDialog(mainPanel, \"See JavaDoc for PlatformConverter.getButtonBarOrder(..) for details on the format string.\");\n" +
"\t}\n" +
"});\n" +
"\n" +
"ButtonGroup bg = new ButtonGroup();\n" +
"bg.add(winButt);\n" +
"bg.add(macButt);\n" +
"winButt.doClick();\n" +
"\n" +
"tabbedPane.addTab(\"Buttons\", createButtonBarsPanel(\"help\", false));\n" +
"tabbedPane.addTab(\"Buttons with Help2\", createButtonBarsPanel(\"help2\", false));\n" +
"tabbedPane.addTab(\"Buttons (Same width)\", createButtonBarsPanel(\"help\", true));\n" +
"\n" +
"mainPanel.add(tabbedPane, \"grow,wrap\");\n" +
"\n" +
"mainPanel.add(createLabel(\"Button Order:\"));\n" +
"mainPanel.add(formatLabel, \"growx\");\n" +
"mainPanel.add(winButt);\n" +
"mainPanel.add(macButt);\n" +
"mainPanel.add(helpButt, \"gapbefore unrel\");");
return mainPanel;
}
private JComponent createButtonBarsPanel(String helpTag, boolean sizeLocked)
{
MigLayout lm = new MigLayout("nogrid, fillx, aligny 100%, gapy unrel");
JPanel panel = createTabPanel(lm);
// Notice that the order in the rows below does not matter...
String[][] buttons = new String[][] {
{"OK"},
{"No", "Yes"},
{"Help", "Close"},
{"OK", "Help"},
{"OK", "Cancel", "Help"},
{"OK", "Cancel", "Apply", "Help"},
{"No", "Yes", "Cancel"},
{"Help", "< Back", "Forward >", "Cancel"},
{"Print...", "Cancel", "Help"}
};
for (int r = 0; r < buttons.length; r++) {
for (int i = 0; i < buttons[r].length; i++) {
String txt = buttons[r][i];
String tag = txt;
if (txt.equals("Help")) {
tag = helpTag;
} else if (txt.equals("< Back")) {
tag = "back";
} else if (txt.equals("Close")) {
tag = "cancel";
} else if (txt.equals("Forward >")) {
tag = "next";
} else if (txt.equals("Print...")) {
tag = "other";
}
String wrap = (i == buttons[r].length - 1) ? ",wrap" : "";
String sizeGroup = sizeLocked ? ("sgx " + r + ",") : "";
panel.add(createButton(txt), sizeGroup + "tag " + tag + wrap);
}
}
return panel;
}
public JComponent createOrientation()
{
JTabbedPane tabbedPane = new JTabbedPane();
MigLayout lm = new MigLayout("flowy", "[grow,fill]", "[]20[]20[]20[]");
JPanel mainPanel = createTabPanel(lm);
// Default orientation
MigLayout defLM = new MigLayout("", "[trailing][grow,fill]", "");
JPanel defPanel = createTabPanel(defLM);
addSeparator(defPanel, "Default Orientation");
defPanel.add(createLabel("Level of Trust"));
defPanel.add(createTextField(""), "span,growx");
defPanel.add(createLabel("Radar Presentation"));
defPanel.add(createTextField(""));
defPanel.add(createTextField(""));
// Right-to-left, Top-to-bottom
MigLayout rtlLM = new MigLayout("rtl,ttb",
"[trailing][grow,fill]",
"");
JPanel rtlPanel = createTabPanel(rtlLM);
addSeparator(rtlPanel, "Right to Left");
rtlPanel.add(createLabel("Level of Trust"));
rtlPanel.add(createTextField(""), "span,growx");
rtlPanel.add(createLabel("Radar Presentation"));
rtlPanel.add(createTextField(""));
rtlPanel.add(createTextField(""));
// Right-to-left, Bottom-to-top
MigLayout rtlbLM = new MigLayout("rtl,btt",
"[trailing][grow,fill]",
"");
JPanel rtlbPanel = createTabPanel(rtlbLM);
addSeparator(rtlbPanel, "Right to Left, Bottom to Top");
rtlbPanel.add(createLabel("Level of Trust"));
rtlbPanel.add(createTextField(""), "span,growx");
rtlbPanel.add(createLabel("Radar Presentation"));
rtlbPanel.add(createTextField(""));
rtlbPanel.add(createTextField(""));
// Left-to-right, Bottom-to-top
MigLayout ltrbLM = new MigLayout("ltr,btt",
"[trailing][grow,fill]",
"");
JPanel ltrbPanel = createTabPanel(ltrbLM);
addSeparator(ltrbPanel, "Left to Right, Bottom to Top");
ltrbPanel.add(createLabel("Level of Trust"));
ltrbPanel.add(createTextField(""), "span,growx");
ltrbPanel.add(createLabel("Radar Presentation"));
ltrbPanel.add(createTextField(""));
ltrbPanel.add(createTextField(""));
mainPanel.add(defPanel);
mainPanel.add(rtlPanel);
mainPanel.add(rtlbPanel);
mainPanel.add(ltrbPanel);
tabbedPane.addTab("Orientation", mainPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"MigLayout lm = new MigLayout(\"flowy\", \"[grow,fill]\", \"[]0[]15lp[]0[]\");\n" +
"JPanel mainPanel = createTabPanel(lm);\n" +
"\n" +
"// Default orientation\n" +
"MigLayout defLM = new MigLayout(\"\", \"[][grow,fill]\", \"\");\n" +
"\n" +
"JPanel defPanel = createTabPanel(defLM);\n" +
"addSeparator(defPanel, \"Default Orientation\");\n" +
"defPanel.add(createLabel(\"Level\"));\n" +
"defPanel.add(createTextField(\"\"), \"span,growx\");\n" +
"defPanel.add(createLabel(\"Radar\"));\n" +
"defPanel.add(createTextField(\"\"));\n" +
"defPanel.add(createTextField(\"\"));\n" +
"\n" +
"// Right-to-left, Top-to-bottom\n" +
"MigLayout rtlLM = new MigLayout(\"rtl,ttb\",\n" +
" \"[][grow,fill]\",\n" +
" \"\");\n" +
"JPanel rtlPanel = createTabPanel(rtlLM);\n" +
"addSeparator(rtlPanel, \"Right to Left\");\n" +
"rtlPanel.add(createLabel(\"Level\"));\n" +
"rtlPanel.add(createTextField(\"\"), \"span,growx\");\n" +
"rtlPanel.add(createLabel(\"Radar\"));\n" +
"rtlPanel.add(createTextField(\"\"));\n" +
"rtlPanel.add(createTextField(\"\"));\n" +
"\n" +
"// Right-to-left, Bottom-to-top\n" +
"MigLayout rtlbLM = new MigLayout(\"rtl,btt\",\n" +
" \"[][grow,fill]\",\n" +
" \"\");\n" +
"JPanel rtlbPanel = createTabPanel(rtlbLM);\n" +
"addSeparator(rtlbPanel, \"Right to Left, Bottom to Top\");\n" +
"rtlbPanel.add(createLabel(\"Level\"));\n" +
"rtlbPanel.add(createTextField(\"\"), \"span,growx\");\n" +
"rtlbPanel.add(createLabel(\"Radar\"));\n" +
"rtlbPanel.add(createTextField(\"\"));\n" +
"rtlbPanel.add(createTextField(\"\"));\n" +
"\n" +
"// Left-to-right, Bottom-to-top\n" +
"MigLayout ltrbLM = new MigLayout(\"ltr,btt\",\n" +
" \"[][grow,fill]\",\n" +
" \"\");\n" +
"JPanel ltrbPanel = createTabPanel(ltrbLM);\n" +
"addSeparator(ltrbPanel, \"Left to Right, Bottom to Top\");\n" +
"ltrbPanel.add(createLabel(\"Level\"));\n" +
"ltrbPanel.add(createTextField(\"\"), \"span,growx\");\n" +
"ltrbPanel.add(createLabel(\"Radar\"));\n" +
"ltrbPanel.add(createTextField(\"\"));\n" +
"ltrbPanel.add(createTextField(\"\"));\n" +
"\n" +
"mainPanel.add(defPanel);\n" +
"mainPanel.add(rtlPanel);\n" +
"mainPanel.add(rtlbPanel);\n" +
"mainPanel.add(ltrbPanel);\n" +
"\n" +
"tabbedPane.addTab(\"Orientation\", mainPanel);");
return tabbedPane;
}
public JComponent createCell_Position()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Absolute grid position
MigLayout absLM = new MigLayout("",
"[100:pref,fill]",
"[100:pref,fill]");
JPanel absPanel = createTabPanel(absLM);
absPanel.add(createButton(), "cell 0 0");
absPanel.add(createButton(), "cell 2 0");
absPanel.add(createButton(), "cell 3 0");
absPanel.add(createButton(), "cell 1 1");
absPanel.add(createButton(), "cell 0 2");
absPanel.add(createButton(), "cell 2 2");
absPanel.add(createButton(), "cell 2 2");
// Relative grid position with wrap
MigLayout relAwLM = new MigLayout("wrap",
"[100:pref,fill][100:pref,fill][100:pref,fill][100:pref,fill]",
"[100:pref,fill]");
JPanel relAwPanel = createTabPanel(relAwLM);
relAwPanel.add(createButton());
relAwPanel.add(createButton(), "skip");
relAwPanel.add(createButton());
relAwPanel.add(createButton(), "skip,wrap");
relAwPanel.add(createButton());
relAwPanel.add(createButton(), "skip,split");
relAwPanel.add(createButton());
// Relative grid position with manual wrap
MigLayout relWLM = new MigLayout("",
"[100:pref,fill]",
"[100:pref,fill]");
JPanel relWPanel = createTabPanel(relWLM);
relWPanel.add(createButton());
relWPanel.add(createButton(), "skip");
relWPanel.add(createButton(), "wrap");
relWPanel.add(createButton(), "skip,wrap");
relWPanel.add(createButton());
relWPanel.add(createButton(), "skip,split");
relWPanel.add(createButton());
// Mixed relative and absolute grid position
MigLayout mixLM = new MigLayout("",
"[100:pref,fill]",
"[100:pref,fill]");
JPanel mixPanel = createTabPanel(mixLM);
mixPanel.add(createButton());
mixPanel.add(createButton(), "cell 2 0");
mixPanel.add(createButton());
mixPanel.add(createButton(), "cell 1 1,wrap");
mixPanel.add(createButton());
mixPanel.add(createButton(), "cell 2 2,split");
mixPanel.add(createButton());
tabbedPane.addTab("Absolute", absPanel);
tabbedPane.addTab("Relative + Wrap", relAwPanel);
tabbedPane.addTab("Relative", relWPanel);
tabbedPane.addTab("Mixed", mixPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("\t\tJTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"\t\t// Absolute grid position\n" +
"\t\tMigLayout absLM = new MigLayout(\"\",\n" +
"\t\t \"[100:pref,fill]\",\n" +
"\t\t \"[100:pref,fill]\");\n" +
"\t\tJPanel absPanel = createTabPanel(absLM);\n" +
"\t\tabsPanel.add(createPanel(), \"cell 0 0\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 2 0\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 3 0\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 1 1\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 0 2\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 2 2\");\n" +
"\t\tabsPanel.add(createPanel(), \"cell 2 2\");\n" +
"\n" +
"\n" +
"\t\t// Relative grid position with wrap\n" +
"\t\tMigLayout relAwLM = new MigLayout(\"wrap\",\n" +
"\t\t \"[100:pref,fill][100:pref,fill][100:pref,fill][100:pref,fill]\",\n" +
"\t\t \"[100:pref,fill]\");\n" +
"\t\tJPanel relAwPanel = createTabPanel(relAwLM);\n" +
"\t\trelAwPanel.add(createPanel());\n" +
"\t\trelAwPanel.add(createPanel(), \"skip\");\n" +
"\t\trelAwPanel.add(createPanel());\n" +
"\t\trelAwPanel.add(createPanel(), \"skip,wrap\");\n" +
"\t\trelAwPanel.add(createPanel());\n" +
"\t\trelAwPanel.add(createPanel(), \"skip,split\");\n" +
"\t\trelAwPanel.add(createPanel());\n" +
"\n" +
"\n" +
"\t\t// Relative grid position with manual wrap\n" +
"\t\tMigLayout relWLM = new MigLayout(\"\",\n" +
"\t\t \"[100:pref,fill]\",\n" +
"\t\t \"[100:pref,fill]\");\n" +
"\t\tJPanel relWPanel = createTabPanel(relWLM);\n" +
"\t\trelWPanel.add(createPanel());\n" +
"\t\trelWPanel.add(createPanel(), \"skip\");\n" +
"\t\trelWPanel.add(createPanel(), \"wrap\");\n" +
"\t\trelWPanel.add(createPanel(), \"skip,wrap\");\n" +
"\t\trelWPanel.add(createPanel());\n" +
"\t\trelWPanel.add(createPanel(), \"skip,split\");\n" +
"\n" +
"\t\trelWPanel.add(createPanel());\n" +
"\n" +
"\n" +
"\t\t// Mixed relative and absolute grid position\n" +
"\t\tMigLayout mixLM = new MigLayout(\"\",\n" +
"\t\t \"[100:pref,fill]\",\n" +
"\t\t \"[100:pref,fill]\");\n" +
"\t\tJPanel mixPanel = createTabPanel(mixLM);\n" +
"\t\tmixPanel.add(createPanel());\n" +
"\t\tmixPanel.add(createPanel(), \"cell 2 0\");\n" +
"\t\tmixPanel.add(createPanel());\n" +
"\t\tmixPanel.add(createPanel(), \"cell 1 1,wrap\");\n" +
"\t\tmixPanel.add(createPanel());\n" +
"\t\tmixPanel.add(createPanel(), \"cell 2 2,split\");\n" +
"\t\tmixPanel.add(createPanel());\n" +
"\n" +
"\t\ttabbedPane.addTab(\"Absolute\", absPanel);\n" +
"\t\ttabbedPane.addTab(\"Relative + Wrap\", relAwPanel);\n" +
"\t\ttabbedPane.addTab(\"Relative\", relWPanel);\n" +
"\t\ttabbedPane.addTab(\"Mixed\", mixPanel);");
return tabbedPane;
}
public JComponent createPlain()
{
return createPlainImpl(false);
}
private JComponent createPlainImpl(boolean debug)
{
JTabbedPane tabbedPane = new JTabbedPane();
MigLayout lm = new MigLayout((debug && benchRuns == 0 ? "debug, inset 20" : "ins 20"), "[para]0[][100lp, fill][60lp][95lp, fill]", "");
JPanel panel = createTabPanel(lm);
addSeparator(panel, "Manufacturer");
panel.add(createLabel("Company"), "skip");
panel.add(createTextField(""), "span, growx");
panel.add(createLabel("Contact"), "skip");
panel.add(createTextField(""), "span, growx");
panel.add(createLabel("Order No"), "skip");
panel.add(createTextField(15), "wrap para");
addSeparator(panel, "Inspector");
panel.add(createLabel("Name"), "skip");
panel.add(createTextField(""), "span, growx");
panel.add(createLabel("Reference No"), "skip");
panel.add(createTextField(""), "wrap");
panel.add(createLabel("Status"), "skip");
panel.add(createCombo(new String[] {"In Progress", "Finnished", "Released"}), "wrap para");
addSeparator(panel, "Ship");
panel.add(createLabel("Shipyard"), "skip");
panel.add(createTextField(""), "span, growx");
panel.add(createLabel("Register No"), "skip");
panel.add(createTextField(""));
panel.add(createLabel("Hull No"), "right");
panel.add(createTextField(15), "wrap");
panel.add(createLabel("Project StructureType"), "skip");
panel.add(createCombo(new String[] {"New Building", "Convention", "Repair"}));
if (debug)
panel.add(createLabel("Red is cell bounds. Blue is component bounds."), "newline,ax left,span,gaptop 40,");
tabbedPane.addTab("Plain", panel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"MigLayout lm = new MigLayout((debug && benchRuns == 0 ? \"debug, inset 20\" : \"ins 20\"), \"[para]0[][100lp, fill][60lp][95lp, fill]\", \"\");\n" +
"JPanel panel = createTabPanel(lm);\n" +
"\n" +
"addSeparator(panel, \"Manufacturer\");\n" +
"\n" +
"panel.add(createLabel(\"Company\"), \"skip\");\n" +
"panel.add(createTextField(\"\"), \"span, growx\");\n" +
"panel.add(createLabel(\"Contact\"), \"skip\");\n" +
"panel.add(createTextField(\"\"), \"span, growx\");\n" +
"panel.add(createLabel(\"Order No\"), \"skip\");\n" +
"panel.add(createTextField(15), \"wrap para\");\n" +
"\n" +
"addSeparator(panel, \"Inspector\");\n" +
"\n" +
"panel.add(createLabel(\"Name\"), \"skip\");\n" +
"panel.add(createTextField(\"\"), \"span, growx\");\n" +
"panel.add(createLabel(\"Reference No\"), \"skip\");\n" +
"panel.add(createTextField(\"\"), \"wrap\");\n" +
"panel.add(createLabel(\"Status\"), \"skip\");\n" +
"panel.add(createCombo(new String[] {\"In Progress\", \"Finnished\", \"Released\"}), \"wrap para\");\n" +
"\n" +
"addSeparator(panel, \"Ship\");\n" +
"\n" +
"panel.add(createLabel(\"Shipyard\"), \"skip\");\n" +
"panel.add(createTextField(\"\"), \"span, growx\");\n" +
"panel.add(createLabel(\"Register No\"), \"skip\");\n" +
"panel.add(createTextField(\"\"));\n" +
"panel.add(createLabel(\"Hull No\"), \"right\");\n" +
"panel.add(createTextField(15), \"wrap\");\n" +
"panel.add(createLabel(\"Project StructureType\"), \"skip\");\n" +
"panel.add(createCombo(new String[] {\"New Building\", \"Convention\", \"Repair\"}));\n" +
"\n" +
"if (debug)\n" +
"\tpanel.add(createLabel(\"Red is cell bounds. Blue is component bounds.\"), \"newline,ax left,span,gaptop 40,\");\n" +
"\n" +
"tabbedPane.addTab(\"Plain\", panel);");
return tabbedPane;
}
public JComponent createBound_Sizes()
{
JTabbedPane tabbedPane = new JTabbedPane();
for (int i = 0; i < 2; i++) { // Jumping for 0 and Stable for 1
String colConstr = i == 0 ? "[right][300]" : "[right, 100lp:pref][300]";
MigLayout LM1 = new MigLayout("wrap", colConstr, "");
JPanel panel1 = createTabPanel(LM1);
panel1.add(createLabel("File Number:"));
panel1.add(createTextField(""), "growx");
panel1.add(createLabel("RFQ Number:"));
panel1.add(createTextField(""), "growx");
panel1.add(createLabel("Entry Date:"));
panel1.add(createTextField(6));
panel1.add(createLabel("Sales Person:"));
panel1.add(createTextField(""), "growx");
MigLayout LM2 = new MigLayout("wrap", colConstr, "");
JPanel panel2 = createTabPanel(LM2);
panel2.add(createLabel("Shipper:"));
panel2.add(createTextField(6), "split 2");
panel2.add(createTextField(""), "growx");
panel2.add(createLabel("Consignee:"));
panel2.add(createTextField(6), "split 2");
panel2.add(createTextField(""), "growx");
panel2.add(createLabel("Departure:"));
panel2.add(createTextField(6), "split 2");
panel2.add(createTextField(""), "growx");
panel2.add(createLabel("Destination:"));
panel2.add(createTextField(6), "split 2");
panel2.add(createTextField(""), "growx");
tabbedPane.addTab(i == 0 ? "Jumping 1" : "Stable 1", panel1);
tabbedPane.addTab(i == 0 ? "Jumping 2" : "Stable 2", panel2);
}
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"for (int i = 0; i < 2; i++) { // Jumping for 0 and Stable for 1\n" +
"\tString colConstr = i == 0 ? \"[right][300]\" : \"[right, 100lp:pref][300]\";\n" +
"\n" +
"\tMigLayout LM1 = new MigLayout(\"wrap\", colConstr, \"\");\n" +
"\tJPanel panel1 = createTabPanel(LM1);\n" +
"\tpanel1.add(createLabel(\"File Number:\"));\n" +
"\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
"\tpanel1.add(createLabel(\"RFQ Number:\"));\n" +
"\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
"\tpanel1.add(createLabel(\"Entry Date:\"));\n" +
"\tpanel1.add(createTextField(6));\n" +
"\tpanel1.add(createLabel(\"Sales Person:\"));\n" +
"\tpanel1.add(createTextField(\"\"), \"growx\");\n" +
"\n" +
"\tMigLayout LM2 = new MigLayout(\"wrap\", colConstr, \"\");\n" +
"\tJPanel panel2 = createTabPanel(LM2);\n" +
"\tpanel2.add(createLabel(\"Shipper:\"));\n" +
"\tpanel2.add(createTextField(6), \"split 2\");\n" +
"\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
"\tpanel2.add(createLabel(\"Consignee:\"));\n" +
"\tpanel2.add(createTextField(6), \"split 2\");\n" +
"\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
"\tpanel2.add(createLabel(\"Departure:\"));\n" +
"\tpanel2.add(createTextField(6), \"split 2\");\n" +
"\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
"\tpanel2.add(createLabel(\"Destination:\"));\n" +
"\tpanel2.add(createTextField(6), \"split 2\");\n" +
"\tpanel2.add(createTextField(\"\"), \"growx\");\n" +
"\n" +
"\ttabbedPane.addTab(i == 0 ? \"Jumping 1\" : \"Stable 2\", panel1);\n" +
"\ttabbedPane.addTab(i == 0 ? \"Jumping 2\" : \"Stable 2\", panel2);\n" +
"}");
return tabbedPane;
}
public JComponent createComponent_Sizes()
{
JTabbedPane tabbedPane = new JTabbedPane();
MigLayout LM = new MigLayout("wrap", "[right][0:pref,grow]", "");
JPanel panel = createTabPanel(LM);
JScrollPane descrText = createTextAreaScroll("Use slider to see how the components grow and shrink depending on the constraints set on them.", 0, 0, false);
descrText.setOpaque(OPAQUE);
descrText.setBorder(new EmptyBorder(10, 10, 10, 10));
((JTextArea) descrText.getViewport().getView()).setOpaque(OPAQUE);
descrText.getViewport().setOpaque(OPAQUE);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, panel, descrText);
splitPane.setOpaque(OPAQUE);
splitPane.setBorder(null);
panel.add(createLabel("\"\""));
panel.add(createTextField(""));
panel.add(createLabel("\"min!\""));
panel.add(createTextField("3", 3), "width min!");
panel.add(createLabel("\"pref!\""));
panel.add(createTextField("3", 3), "width pref!");
panel.add(createLabel("\"min:pref\""));
panel.add(createTextField("8", 8), "width min:pref");
panel.add(createLabel("\"min:100:150\""));
panel.add(createTextField("8", 8), "width min:100:150");
panel.add(createLabel("\"min:100:150, growx\""));
panel.add(createTextField("8", 8), "width min:100:150, growx");
panel.add(createLabel("\"min:100, growx\""));
panel.add(createTextField("8", 8), "width min:100, growx");
panel.add(createLabel("\"40!\""));
panel.add(createTextField("8", 8), "width 40!");
panel.add(createLabel("\"40:40:40\""));
panel.add(createTextField("8", 8), "width 40:40:40");
tabbedPane.addTab("Component Sizes", splitPane);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"\t\tMigLayout LM = new MigLayout(\"wrap\", \"[right][0:pref,grow]\", \"\");\n" +
"\n" +
"\t\tJPanel panel = createTabPanel(LM);\n" +
"\t\tJScrollPane descrText = createTextAreaScroll(\"Use slider to see how the components grow and shrink depending on the constraints set on them.\", 0, 0, false);\n" +
"\n" +
"\t\tdescrText.setOpaque(OPAQUE);\n" +
"\t\tdescrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
"\t\t((JTextArea) descrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
"\t\tdescrText.getViewport().setOpaque(OPAQUE);\n" +
"\n" +
"\t\tJSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, panel, descrText);\n" +
"\t\tsplitPane.setOpaque(OPAQUE);\n" +
"\t\tsplitPane.setBorder(null);\n" +
"\n" +
"\t\tpanel.add(createLabel(\"\\\"\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"\"));\n" +
"\t\tpanel.add(createLabel(\"\\\"min!\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"3\", 3), \"width min!\");\n" +
"\t\tpanel.add(createLabel(\"\\\"pref!\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"3\", 3), \"width pref!\");\n" +
"\t\tpanel.add(createLabel(\"\\\"min:pref\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width min:pref\");\n" +
"\t\tpanel.add(createLabel(\"\\\"min:100:150\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width min:100:150\");\n" +
"\t\tpanel.add(createLabel(\"\\\"min:100:150, growx\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width min:100:150, growx\");\n" +
"\t\tpanel.add(createLabel(\"\\\"min:100, growx\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width min:100, growx\");\n" +
"\t\tpanel.add(createLabel(\"\\\"40!\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width 40!\");\n" +
"\t\tpanel.add(createLabel(\"\\\"40:40:40\\\"\"));\n" +
"\t\tpanel.add(createTextField(\"8\", 8), \"width 40:40:40\");\n" +
"\n" +
"\t\ttabbedPane.addTab(\"Component Sizes\", splitPane);");
return tabbedPane;
}
public JComponent createCell_Alignments()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Horizontal
MigLayout hLM = new MigLayout("wrap",
"[grow,left][grow,center][grow,right][grow,fill,center]",
"[]unrel[][]");
JPanel hPanel = createTabPanel(hLM);
String[] sizes = new String[] {"", "growx", "growx 0", "left", "center", "right", "leading", "trailing"};
hPanel.add(createLabel("[left]"), "c");
hPanel.add(createLabel("[center]"), "c");
hPanel.add(createLabel("[right]"), "c");
hPanel.add(createLabel("[fill,center]"), "c, growx 0");
for (int r = 0; r < sizes.length; r++) {
for (int c = 0; c < 4; c++) {
String text = sizes[r].length() > 0 ? sizes[r] : "default";
hPanel.add(createButton(text), sizes[r]);
}
}
// Vertical
MigLayout vLM = new MigLayout("wrap,flowy",
"[right][]",
"[grow,top][grow,center][grow,bottom][grow,fill,bottom][grow,fill,baseline]");
JPanel vPanel = createTabPanel(vLM);
String[] vSizes = new String[] {"", "growy", "growy 0", "top", "aligny center", "bottom"};
vPanel.add(createLabel("[top]"), "aligny center");
vPanel.add(createLabel("[center]"), "aligny center");
vPanel.add(createLabel("[bottom]"), "aligny center");
vPanel.add(createLabel("[fill, bottom]"), "aligny center, growy 0");
vPanel.add(createLabel("[fill, baseline]"), "aligny center");
for (int c = 0; c < vSizes.length; c++) {
for (int r = 0; r < 5; r++) {
String text = vSizes[c].length() > 0 ? vSizes[c] : "default";
JButton b = createButton(text);
if (r == 4 && c <= 1)
b.setFont(new Font("sansserif", Font.PLAIN, 16 + c * 5));
vPanel.add(b, vSizes[c]);
}
}
tabbedPane.addTab("Horizontal", hPanel);
tabbedPane.addTab("Vertical", vPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Horizontal\n" +
"MigLayout hLM = new MigLayout(\"wrap\",\n" +
" \"[grow,left][grow,center][grow,right][grow,fill,center]\",\n" +
" \"[]unrel[][]\");\n" +
"JPanel hPanel = createTabPanel(hLM);\n" +
"String[] sizes = new String[] {\"\", \"growx\", \"growx 0\", \"left\", \"center\", \"right\", \"leading\", \"trailing\"};\n" +
"hPanel.add(createLabel(\"[left]\"), \"c\");\n" +
"hPanel.add(createLabel(\"[center]\"), \"c\");\n" +
"hPanel.add(createLabel(\"[right]\"), \"c\");\n" +
"hPanel.add(createLabel(\"[fill,center]\"), \"c, growx 0\");\n" +
"\n" +
"for (int r = 0; r < sizes.length; r++) {\n" +
"\tfor (int c = 0; c < 4; c++) {\n" +
"\t\tString text = sizes[r].length() > 0 ? sizes[r] : \"default\";\n" +
"\t\thPanel.add(createButton(text), sizes[r]);\n" +
"\t}\n" +
"}\n" +
"\n" +
"// Vertical\n" +
"MigLayout vLM = new MigLayout(\"wrap,flowy\",\n" +
" \"[right][]\",\n" +
" \"[grow,top][grow,center][grow,bottom][grow,fill,bottom][grow,fill,baseline]\");\n" +
"JPanel vPanel = createTabPanel(vLM);\n" +
"String[] vSizes = new String[] {\"\", \"growy\", \"growy 0\", \"top\", \"center\", \"bottom\"};\n" +
"vPanel.add(createLabel(\"[top]\"), \"center\");\n" +
"vPanel.add(createLabel(\"[center]\"), \"center\");\n" +
"vPanel.add(createLabel(\"[bottom]\"), \"center\");\n" +
"vPanel.add(createLabel(\"[fill, bottom]\"), \"center, growy 0\");\n" +
"vPanel.add(createLabel(\"[fill, baseline]\"), \"center\");\n" +
"\n" +
"for (int c = 0; c < vSizes.length; c++) {\n" +
"\tfor (int r = 0; r < 5; r++) {\n" +
"\t\tString text = vSizes[c].length() > 0 ? vSizes[c] : \"default\";\n" +
"\t\tJButton b = createButton(text);\n" +
"\t\tif (r == 4 && c <= 1)\n" +
"\t\t\tb.setFont(new Font(\"sansserif\", Font.PLAIN, 16 + c * 5));\n" +
"\t\tvPanel.add(b, vSizes[c]);\n" +
"\t}\n" +
"}\n" +
"\n" +
"tabbedPane.addTab(\"Horizontal\", hPanel);\n" +
"tabbedPane.addTab(\"Vertical\", vPanel);");
return tabbedPane;
}
public JComponent createUnits()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Horizontal
MigLayout hLM = new MigLayout("wrap,nocache",
"[right][]",
"");
JPanel hPanel = createTabPanel(hLM);
String[] sizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "20sp"};
for (int i = 0; i < sizes.length; i++) {
hPanel.add(createLabel(sizes[i]));
hPanel.add(createTextField(""), "width " + sizes[i] + "!");
}
// Horizontal lp
MigLayout hlpLM = new MigLayout("nocache", "[right][][]", "");
JPanel hlpPanel = createTabPanel(hlpLM);
hlpPanel.add(createLabel("9 cols"));
hlpPanel.add(createTextField(9));
String[] lpSizes = new String[] {"75lp", "75px", "88px", "100px"};
hlpPanel.add(createLabel("Width of createTextField(9)"), "wrap");
for (int i = 0; i < lpSizes.length; i++) {
hlpPanel.add(createLabel(lpSizes[i]));
hlpPanel.add(createTextField(""), "width " + lpSizes[i] + "!, wrap");
}
// Vertical
MigLayout vLM = new MigLayout("wrap,flowy,nocache",
"[c]",
"[top][top]");
JPanel vPanel = createTabPanel(vLM);
String[] vSizes = new String[] {"72pt", "25.4mm", "2.54cm", "1in", "72px", "96px", "120px", "25%", "20sp"};
for (int i = 0; i < sizes.length; i++) {
vPanel.add(createLabel(vSizes[i]));
vPanel.add(createTextArea("", 0, 5), "width 50!, height " + vSizes[i] + "!");
}
// Vertical lp
MigLayout vlpLM = new MigLayout("wrap,flowy,nocache",
"[c]",
"[top][top]40px[top][top]");
JPanel vlpPanel = createTabPanel(vlpLM);
vlpPanel.add(createLabel("4 rows"));
vlpPanel.add(createTextArea("", 4, 5), "width 50!");
vlpPanel.add(createLabel("field"));
vlpPanel.add(createTextField(5));
String[] vlpSizes1 = new String[] {"63lp", "57px", "63px", "68px", "25%"};
String[] vlpSizes2 = new String[] {"21lp", "21px", "23px", "24px", "10%"};
for (int i = 0; i < vlpSizes1.length; i++) {
vlpPanel.add(createLabel(vlpSizes1[i]));
vlpPanel.add(createTextArea("", 1, 5), "width 50!, height " + vlpSizes1[i] + "!");
vlpPanel.add(createLabel(vlpSizes2[i]));
vlpPanel.add(createTextField(5), "height " + vlpSizes2[i] + "!");
}
vlpPanel.add(createLabel("button"), "skip 2");
vlpPanel.add(createButton("..."));
tabbedPane.addTab("Horizontal", hPanel);
tabbedPane.addTab("Horizontal LP", hlpPanel);
tabbedPane.addTab("Vertical", vPanel);
tabbedPane.addTab("Vertical LP", vlpPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Horizontal\n" +
"MigLayout hLM = new MigLayout(\"wrap,nocache\",\n" +
"\t\t\t\t\t\t\t \"[right][]\",\n" +
"\t\t\t\t\t\t\t \"\");\n" +
"JPanel hPanel = createTabPanel(hLM);\n" +
"String[] sizes = new String[] {\"72pt\", \"25.4mm\", \"2.54cm\", \"1in\", \"72px\", \"96px\", \"120px\", \"25%\", \"20sp\"};\n" +
"for (int i = 0; i < sizes.length; i++) {\n" +
"\thPanel.add(createLabel(sizes[i]));\n" +
"\thPanel.add(createTextField(\"\"), \"width \" + sizes[i] + \"!\");\n" +
"}\n" +
"\n" +
"// Horizontal lp\n" +
"MigLayout hlpLM = new MigLayout(\"nocache\", \"[right][][]\", \"\");\n" +
"JPanel hlpPanel = createTabPanel(hlpLM);\n" +
"hlpPanel.add(createLabel(\"9 cols\"));\n" +
"hlpPanel.add(createTextField(9));\n" +
"String[] lpSizes = new String[] {\"75lp\", \"75px\", \"88px\", \"100px\"};\n" +
"hlpPanel.add(createLabel(\"Width of createTextField(9)\"), \"wrap\");\n" +
"for (int i = 0; i < lpSizes.length; i++) {\n" +
"\thlpPanel.add(createLabel(lpSizes[i]));\n" +
"\thlpPanel.add(createTextField(\"\"), \"width \" + lpSizes[i] + \"!, wrap\");\n" +
"}\n" +
"\n" +
"// Vertical\n" +
"MigLayout vLM = new MigLayout(\"wrap,flowy,nocache\",\n" +
"\t\t\t\t\t\t\t \"[c]\",\n" +
"\t\t\t\t\t\t\t \"[top][top]\");\n" +
"JPanel vPanel = createTabPanel(vLM);\n" +
"String[] vSizes = new String[] {\"72pt\", \"25.4mm\", \"2.54cm\", \"1in\", \"72px\", \"96px\", \"120px\", \"25%\", \"20sp\"};\n" +
"for (int i = 0; i < sizes.length; i++) {\n" +
"\tvPanel.add(createLabel(vSizes[i]));\n" +
"\tvPanel.add(createTextArea(\"\", 0, 5), \"width 50!, height \" + vSizes[i] + \"!\");\n" +
"}\n" +
"\n" +
"// Vertical lp\n" +
"MigLayout vlpLM = new MigLayout(\"wrap,flowy,nocache\",\n" +
"\t\t\t\t\t\t\t\t\"[c]\",\n" +
"\t\t\t\t\t\t\t\t\"[top][top]40px[top][top]\");\n" +
"JPanel vlpPanel = createTabPanel(vlpLM);\n" +
"vlpPanel.add(createLabel(\"4 rows\"));\n" +
"vlpPanel.add(createTextArea(\"\", 4, 5), \"width 50!\");\n" +
"vlpPanel.add(createLabel(\"field\"));\n" +
"vlpPanel.add(createTextField(5));\n" +
"\n" +
"String[] vlpSizes1 = new String[] {\"63lp\", \"57px\", \"63px\", \"68px\", \"25%\"};\n" +
"String[] vlpSizes2 = new String[] {\"21lp\", \"21px\", \"23px\", \"24px\", \"10%\"};\n" +
"for (int i = 0; i < vlpSizes1.length; i++) {\n" +
"\tvlpPanel.add(createLabel(vlpSizes1[i]));\n" +
"\tvlpPanel.add(createTextArea(\"\", 1, 5), \"width 50!, height \" + vlpSizes1[i] + \"!\");\n" +
"\tvlpPanel.add(createLabel(vlpSizes2[i]));\n" +
"\tvlpPanel.add(createTextField(5), \"height \" + vlpSizes2[i] + \"!\");\n" +
"}\n" +
"\n" +
"vlpPanel.add(createLabel(\"button\"), \"skip 2\");\n" +
"vlpPanel.add(createButton(\"...\"));\n" +
"\n" +
"tabbedPane.addTab(\"Horizontal\", hPanel);\n" +
"tabbedPane.addTab(\"Horizontal LP\", hlpPanel);\n" +
"tabbedPane.addTab(\"Vertical\", vPanel);\n" +
"tabbedPane.addTab(\"Vertical LP\", vlpPanel);");
return tabbedPane;
}
public JComponent createGrouping()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Ungrouped
MigLayout ugM = new MigLayout("", "[]push[][][]", "");
JPanel ugPanel = createTabPanel(ugM);
ugPanel.add(createButton("Help"));
ugPanel.add(createButton("< Back"), "");
ugPanel.add(createButton("Forward >"), "gap push");
ugPanel.add(createButton("Apply"), "gap unrel");
ugPanel.add(createButton("Cancel"), "gap unrel");
// Grouped Components
MigLayout gM = new MigLayout("nogrid, fillx");
JPanel gPanel = createTabPanel(gM);
gPanel.add(createButton("Help"), "sg");
gPanel.add(createButton("< Back"), "sg,gap push");
gPanel.add(createButton("Forward >"), "sg");
gPanel.add(createButton("Apply"), "sg,gap unrel");
gPanel.add(createButton("Cancel"), "sg,gap unrel");
// Grouped Columns
MigLayout gcM = new MigLayout("", "[sg,fill]push[sg,fill][sg,fill]unrel[sg,fill]unrel[sg,fill]", "");
JPanel gcPanel = createTabPanel(gcM);
gcPanel.add(createButton("Help"));
gcPanel.add(createButton("< Back"));
gcPanel.add(createButton("Forward >"));
gcPanel.add(createButton("Apply"));
gcPanel.add(createButton("Cancel"));
// Ungrouped Rows
MigLayout ugrM = new MigLayout(); // no "sg" is the only difference to next panel
JPanel ugrPanel = createTabPanel(ugrM);
ugrPanel.add(createLabel("File Number:"));
ugrPanel.add(createTextField(30), "wrap");
ugrPanel.add(createLabel("BL/MBL number:"));
ugrPanel.add(createTextField(7), "split 2");
ugrPanel.add(createTextField(7), "wrap");
ugrPanel.add(createLabel("Entry Date:"));
ugrPanel.add(createTextField(7), "wrap");
ugrPanel.add(createLabel("RFQ Number:"));
ugrPanel.add(createTextField(30), "wrap");
ugrPanel.add(createLabel("Goods:"));
ugrPanel.add(createCheck("Dangerous"), "wrap");
ugrPanel.add(createLabel("Shipper:"));
ugrPanel.add(createTextField(30), "wrap");
ugrPanel.add(createLabel("Customer:"));
ugrPanel.add(createTextField(""), "split 2,growx");
ugrPanel.add(createButton("..."), "width 60px:pref,wrap");
ugrPanel.add(createLabel("Port of Loading:"));
ugrPanel.add(createTextField(30), "wrap");
ugrPanel.add(createLabel("Destination:"));
ugrPanel.add(createTextField(30), "wrap");
// Grouped Rows
MigLayout grM = new MigLayout("", "[]", "[sg]"); // "sg" is the only difference to previous panel
JPanel grPanel = createTabPanel(grM);
grPanel.add(createLabel("File Number:"));
grPanel.add(createTextField(30),"wrap");
grPanel.add(createLabel("BL/MBL number:"));
grPanel.add(createTextField(7),"split 2");
grPanel.add(createTextField(7), "wrap");
grPanel.add(createLabel("Entry Date:"));
grPanel.add(createTextField(7), "wrap");
grPanel.add(createLabel("RFQ Number:"));
grPanel.add(createTextField(30), "wrap");
grPanel.add(createLabel("Goods:"));
grPanel.add(createCheck("Dangerous"), "wrap");
grPanel.add(createLabel("Shipper:"));
grPanel.add(createTextField(30), "wrap");
grPanel.add(createLabel("Customer:"));
grPanel.add(createTextField(""), "split 2,growx");
grPanel.add(createButton("..."), "width 50px:pref,wrap");
grPanel.add(createLabel("Port of Loading:"));
grPanel.add(createTextField(30), "wrap");
grPanel.add(createLabel("Destination:"));
grPanel.add(createTextField(30), "wrap");
tabbedPane.addTab("Ungrouped", ugPanel);
tabbedPane.addTab("Grouped (Components)", gPanel);
tabbedPane.addTab("Grouped (Columns)", gcPanel);
tabbedPane.addTab("Ungrouped Rows", ugrPanel);
tabbedPane.addTab("Grouped Rows", grPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Ungrouped\n" +
"MigLayout ugM = new MigLayout(\"\", \"[]push[][][]\", \"\");\n" +
"JPanel ugPanel = createTabPanel(ugM);\n" +
"ugPanel.add(createButton(\"Help\"));\n" +
"ugPanel.add(createButton(\"< Back\"), \"\");\n" +
"ugPanel.add(createButton(\"Forward >\"), \"gap push\");\n" +
"ugPanel.add(createButton(\"Apply\"), \"gap unrel\");\n" +
"ugPanel.add(createButton(\"Cancel\"), \"gap unrel\");\n" +
"\n" +
"// Grouped Components\n" +
"MigLayout gM = new MigLayout(\"nogrid, fillx\");\n" +
"JPanel gPanel = createTabPanel(gM);\n" +
"gPanel.add(createButton(\"Help\"), \"sg\");\n" +
"gPanel.add(createButton(\"< Back\"), \"sg,gap push\");\n" +
"gPanel.add(createButton(\"Forward >\"), \"sg\");\n" +
"gPanel.add(createButton(\"Apply\"), \"sg,gap unrel\");\n" +
"gPanel.add(createButton(\"Cancel\"), \"sg,gap unrel\");\n" +
"\n" +
"// Grouped Columns\n" +
"MigLayout gcM = new MigLayout(\"\", \"[sg,fill]push[sg,fill][sg,fill]unrel[sg,fill]unrel[sg,fill]\", \"\");\n" +
"JPanel gcPanel = createTabPanel(gcM);\n" +
"gcPanel.add(createButton(\"Help\"));\n" +
"gcPanel.add(createButton(\"< Back\"));\n" +
"gcPanel.add(createButton(\"Forward >\"));\n" +
"gcPanel.add(createButton(\"Apply\"));\n" +
"gcPanel.add(createButton(\"Cancel\"));\n" +
"\n" +
"// Ungrouped Rows\n" +
"MigLayout ugrM = new MigLayout(); // no \"sg\" is the only difference to next panel\n" +
"JPanel ugrPanel = createTabPanel(ugrM);\n" +
"ugrPanel.add(createLabel(\"File Number:\"));\n" +
"ugrPanel.add(createTextField(30), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"BL/MBL number:\"));\n" +
"ugrPanel.add(createTextField(7), \"split 2\");\n" +
"ugrPanel.add(createTextField(7), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"Entry Date:\"));\n" +
"ugrPanel.add(createTextField(7), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"RFQ Number:\"));\n" +
"ugrPanel.add(createTextField(30), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"Goods:\"));\n" +
"ugrPanel.add(createCheck(\"Dangerous\"), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"Shipper:\"));\n" +
"ugrPanel.add(createTextField(30), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"Customer:\"));\n" +
"ugrPanel.add(createTextField(\"\"), \"split 2,growx\");\n" +
"ugrPanel.add(createButton(\"...\"), \"width 60px:pref,wrap\");\n" +
"ugrPanel.add(createLabel(\"Port of Loading:\"));\n" +
"ugrPanel.add(createTextField(30), \"wrap\");\n" +
"ugrPanel.add(createLabel(\"Destination:\"));\n" +
"ugrPanel.add(createTextField(30), \"wrap\");\n" +
"\n" +
"// Grouped Rows\n" +
"MigLayout grM = new MigLayout(\"\", \"[]\", \"[sg]\"); // \"sg\" is the only difference to previous panel\n" +
"JPanel grPanel = createTabPanel(grM);\n" +
"grPanel.add(createLabel(\"File Number:\"));\n" +
"grPanel.add(createTextField(30),\"wrap\");\n" +
"grPanel.add(createLabel(\"BL/MBL number:\"));\n" +
"grPanel.add(createTextField(7),\"split 2\");\n" +
"grPanel.add(createTextField(7), \"wrap\");\n" +
"grPanel.add(createLabel(\"Entry Date:\"));\n" +
"grPanel.add(createTextField(7), \"wrap\");\n" +
"grPanel.add(createLabel(\"RFQ Number:\"));\n" +
"grPanel.add(createTextField(30), \"wrap\");\n" +
"grPanel.add(createLabel(\"Goods:\"));\n" +
"grPanel.add(createCheck(\"Dangerous\"), \"wrap\");\n" +
"grPanel.add(createLabel(\"Shipper:\"));\n" +
"grPanel.add(createTextField(30), \"wrap\");\n" +
"grPanel.add(createLabel(\"Customer:\"));\n" +
"grPanel.add(createTextField(\"\"), \"split 2,growx\");\n" +
"grPanel.add(createButton(\"...\"), \"width 50px:pref,wrap\");\n" +
"grPanel.add(createLabel(\"Port of Loading:\"));\n" +
"grPanel.add(createTextField(30), \"wrap\");\n" +
"grPanel.add(createLabel(\"Destination:\"));\n" +
"grPanel.add(createTextField(30), \"wrap\");\n" +
"\n" +
"tabbedPane.addTab(\"Ungrouped\", ugPanel);\n" +
"tabbedPane.addTab(\"Grouped (Components)\", gPanel);\n" +
"tabbedPane.addTab(\"Grouped (Columns)\", gcPanel);\n" +
"tabbedPane.addTab(\"Ungrouped Rows\", ugrPanel);\n" +
"tabbedPane.addTab(\"Grouped Rows\", grPanel);");
return tabbedPane;
}
public JComponent createSpan()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Horizontal span
MigLayout colLM = new MigLayout("nocache",
"[fill][25%!,fill][105lp!,fill][100px!,fill]",
"[]15[][]");
JPanel colPanel = createTabPanel(colLM);
colPanel.add(createTextField("Col1 [ ]"));
colPanel.add(createTextField("Col2 [25%!]"));
colPanel.add(createTextField("Col3 [105lp!]"));
colPanel.add(createTextField("Col4 [100px!]"), "wrap");
colPanel.add(createLabel("Full Name:"));
colPanel.add(createTextField("span, growx", 40), "span,growx");
colPanel.add(createLabel("Phone:"));
colPanel.add(createTextField(5), "span 3, split 5");
colPanel.add(createTextField(7));
colPanel.add(createTextField(7));
colPanel.add(createTextField(9));
colPanel.add(createLabel("(span 3, split 4)"), "wrap");
colPanel.add(createLabel("Zip/City:"));
colPanel.add(createTextField(5));
colPanel.add(createTextField("span 2, growx", 5), "span 2,growx");
// Vertical span
MigLayout rowLM = new MigLayout("wrap",
"[225lp]para[225lp]",
"[]3[]unrel[]3[]unrel[]3[]");
JPanel rowPanel = createTabPanel(rowLM);
rowPanel.add(createLabel("Name"));
rowPanel.add(createLabel("Notes"));
rowPanel.add(createTextField("growx"), "growx");
rowPanel.add(createTextArea("spany,grow", 5, 20), "spany,grow");
rowPanel.add(createLabel("Phone"));
rowPanel.add(createTextField("growx"), "growx");
rowPanel.add(createLabel("Fax"));
rowPanel.add(createTextField("growx"), "growx");
tabbedPane.addTab("Column Span/Split", colPanel);
tabbedPane.addTab("Row Span", rowPanel);
// Disregard. Just forgetting the source code text close to the source code.
setSource("\t\tJTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"\t\t// Horizontal span\n" +
"\t\tMigLayout colLM = new MigLayout(\"\",\n" +
"\t\t \"[fill][25%!,fill][105lp!,fill][100px!,fill]\",\n" +
"\t\t \"[]15[][]\");\n" +
"\t\tJPanel colPanel = createTabPanel(colLM);\n" +
"\t\tcolPanel.add(createTextField(\"Col1 [ ]\"));\n" +
"\t\tcolPanel.add(createTextField(\"Col2 [25%!]\"));\n" +
"\t\tcolPanel.add(createTextField(\"Col3 [105lp!]\"));\n" +
"\t\tcolPanel.add(createTextField(\"Col4 [100px!]\"), \"wrap\");\n" +
"\n" +
"\t\tcolPanel.add(createLabel(\"Full Name:\"));\n" +
"\t\tcolPanel.add(createTextField(\"span, growx\", 40), \"span,growx\");\n" +
"\n" +
"\t\tcolPanel.add(createLabel(\"Phone:\"));\n" +
"\t\tcolPanel.add(createTextField(5), \"span 3, split 5\");\n" +
"\t\tcolPanel.add(createTextField(7));\n" +
"\t\tcolPanel.add(createTextField(7));\n" +
"\t\tcolPanel.add(createTextField(9));\n" +
"\t\tcolPanel.add(createLabel(\"(span 3, split 4)\"), \"wrap\");\n" +
"\n" +
"\t\tcolPanel.add(createLabel(\"Zip/City:\"));\n" +
"\t\tcolPanel.add(createTextField(5));\n" +
"\t\tcolPanel.add(createTextField(\"span 2, growx\", 5), \"span 2,growx\");\n" +
"\n" +
"\t\t// Vertical span\n" +
"\t\tMigLayout rowLM = new MigLayout(\"wrap\",\n" +
"\t\t \"[225lp]para[225lp]\",\n" +
"\t\t \"[]3[]unrel[]3[]unrel[]3[]\");\n" +
"\t\tJPanel rowPanel = createTabPanel(rowLM);\n" +
"\t\trowPanel.add(createLabel(\"Name\"));\n" +
"\t\trowPanel.add(createLabel(\"Notes\"));\n" +
"\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
"\t\trowPanel.add(createTextArea(\"spany,grow\", 5, 20), \"spany,grow\");\n" +
"\t\trowPanel.add(createLabel(\"Phone\"));\n" +
"\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
"\t\trowPanel.add(createLabel(\"Fax\"));\n" +
"\t\trowPanel.add(createTextField(\"growx\"), \"growx\");\n" +
"\n" +
"\t\ttabbedPane.addTab(\"Column Span/Split\", colPanel);\n" +
"\t\ttabbedPane.addTab(\"Row Span\", rowPanel);");
return tabbedPane;
}
public JComponent createGrowing()
{
JTabbedPane tabbedPane = new JTabbedPane();
// All tab
MigLayout allLM = new MigLayout("",
"[pref!][grow,fill]",
"[]15[]");
JPanel allTab = createTabPanel(allLM);
allTab.add(createLabel("Fixed"));
allTab.add(createLabel("Gets all extra space"), "wrap");
allTab.add(createTextField(5));
allTab.add(createTextField(5));
// Half tab
MigLayout halfLM = new MigLayout("",
"[pref!][grow,fill]",
"[]15[]");
JPanel halfTab = createTabPanel(halfLM);
halfTab.add(createLabel("Fixed"));
halfTab.add(createLabel("Gets half of extra space"));
halfTab.add(createLabel("Gets half of extra space"), "wrap");
halfTab.add(createTextField(5));
halfTab.add(createTextField(5));
halfTab.add(createTextField(5));
// Percent 1 tab
MigLayout p1LM = new MigLayout("",
"[pref!][0:0,grow 25,fill][0:0,grow 75,fill]",
"[]15[]");
JPanel p1Tab = createTabPanel(p1LM);
p1Tab.add(createLabel("Fixed"));
p1Tab.add(createLabel("Gets 25% of extra space"), "");
p1Tab.add(createLabel("Gets 75% of extra space"), "wrap");
p1Tab.add(createTextField(5));
p1Tab.add(createTextField(5));
p1Tab.add(createTextField(5));
// Percent 2 tab
MigLayout p2LM = new MigLayout("",
"[0:0,grow 33,fill][0:0,grow 67,fill]",
"[]15[]");
JPanel p2Tab = createTabPanel(p2LM);
p2Tab.add(createLabel("Gets 33% of extra space"), "");
p2Tab.add(createLabel("Gets 67% of extra space"), "wrap");
p2Tab.add(createTextField(5));
p2Tab.add(createTextField(5));
// Vertical 1 tab
MigLayout v1LM = new MigLayout("flowy",
"[]15[]",
"[][c,pref!][c,grow 25,fill][c,grow 75,fill]");
JPanel v1Tab = createTabPanel(v1LM);
v1Tab.add(createLabel("Fixed"), "skip");
v1Tab.add(createLabel("Gets 25% of extra space"));
v1Tab.add(createLabel("Gets 75% of extra space"), "wrap");
v1Tab.add(createLabel("new JTextArea(4, 30)"));
v1Tab.add(createTextAreaScroll("", 4, 30, false));
v1Tab.add(createTextAreaScroll("", 4, 30, false));
v1Tab.add(createTextAreaScroll("", 4, 30, false));
// Vertical 2 tab
MigLayout v2LM = new MigLayout("flowy",
"[]15[]",
"[][c,grow 33,fill][c,grow 67,fill]");
JPanel v2Tab = createTabPanel(v2LM);
v2Tab.add(createLabel("Gets 33% of extra space"), "skip");
v2Tab.add(createLabel("Gets 67% of extra space"), "wrap");
v2Tab.add(createLabel("new JTextArea(4, 30)"));
v2Tab.add(createTextAreaScroll("", 4, 30, false));
v2Tab.add(createTextAreaScroll("", 4, 30, false));
tabbedPane.addTab("All", allTab);
tabbedPane.addTab("Half", halfTab);
tabbedPane.addTab("Percent 1", p1Tab);
tabbedPane.addTab("Percent 2", p2Tab);
tabbedPane.addTab("Vertical 1", v1Tab);
tabbedPane.addTab("Vertical 2", v2Tab);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// All tab\n" +
"MigLayout allLM = new MigLayout(\"\",\n" +
" \"[pref!][grow,fill]\",\n" +
" \"[]15[]\");\n" +
"JPanel allTab = createTabPanel(allLM);\n" +
"allTab.add(createLabel(\"Fixed\"));\n" +
"allTab.add(createLabel(\"Gets all extra space\"), \"wrap\");\n" +
"allTab.add(createTextField(5));\n" +
"allTab.add(createTextField(5));\n" +
"\n" +
"// Half tab\n" +
"MigLayout halfLM = new MigLayout(\"\",\n" +
" \"[pref!][grow,fill]\",\n" +
" \"[]15[]\");\n" +
"JPanel halfTab = createTabPanel(halfLM);\n" +
"halfTab.add(createLabel(\"Fixed\"));\n" +
"halfTab.add(createLabel(\"Gets half of extra space\"));\n" +
"halfTab.add(createLabel(\"Gets half of extra space\"), \"wrap\");\n" +
"halfTab.add(createTextField(5));\n" +
"halfTab.add(createTextField(5));\n" +
"halfTab.add(createTextField(5));\n" +
"\n" +
"// Percent 1 tab\n" +
"MigLayout p1LM = new MigLayout(\"\",\n" +
" \"[pref!][0:0,grow 25,fill][0:0,grow 75,fill]\",\n" +
" \"[]15[]\");\n" +
"JPanel p1Tab = createTabPanel(p1LM);\n" +
"p1Tab.add(createLabel(\"Fixed\"));\n" +
"p1Tab.add(createLabel(\"Gets 25% of extra space\"), \"\");\n" +
"p1Tab.add(createLabel(\"Gets 75% of extra space\"), \"wrap\");\n" +
"p1Tab.add(createTextField(5));\n" +
"p1Tab.add(createTextField(5));\n" +
"p1Tab.add(createTextField(5));\n" +
"\n" +
"// Percent 2 tab\n" +
"MigLayout p2LM = new MigLayout(\"\",\n" +
" \"[0:0,grow 33,fill][0:0,grow 67,fill]\",\n" +
" \"[]15[]\");\n" +
"JPanel p2Tab = createTabPanel(p2LM);\n" +
"p2Tab.add(createLabel(\"Gets 33% of extra space\"), \"\");\n" +
"p2Tab.add(createLabel(\"Gets 67% of extra space\"), \"wrap\");\n" +
"p2Tab.add(createTextField(5));\n" +
"p2Tab.add(createTextField(5));\n" +
"\n" +
"// Vertical 1 tab\n" +
"MigLayout v1LM = new MigLayout(\"flowy\",\n" +
" \"[]15[]\",\n" +
" \"[][c,pref!][c,grow 25,fill][c,grow 75,fill]\");\n" +
"JPanel v1Tab = createTabPanel(v1LM);\n" +
"v1Tab.add(createLabel(\"Fixed\"), \"skip\");\n" +
"v1Tab.add(createLabel(\"Gets 25% of extra space\"));\n" +
"v1Tab.add(createLabel(\"Gets 75% of extra space\"), \"wrap\");\n" +
"v1Tab.add(createLabel(\"new JTextArea(4, 30)\"));\n" +
"v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
"v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
"v1Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
"\n" +
"// Vertical 2 tab\n" +
"MigLayout v2LM = new MigLayout(\"flowy\",\n" +
" \"[]15[]\",\n" +
" \"[][c,grow 33,fill][c,grow 67,fill]\");\n" +
"JPanel v2Tab = createTabPanel(v2LM);\n" +
"v2Tab.add(createLabel(\"Gets 33% of extra space\"), \"skip\");\n" +
"v2Tab.add(createLabel(\"Gets 67% of extra space\"), \"wrap\");\n" +
"v2Tab.add(createLabel(\"new JTextArea(4, 30)\"));\n" +
"v2Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
"v2Tab.add(createTextAreaScroll(\"\", 4, 30, false));\n" +
"\n" +
"tabbedPane.addTab(\"All\", allTab);\n" +
"tabbedPane.addTab(\"Half\", halfTab);\n" +
"tabbedPane.addTab(\"Percent 1\", p1Tab);\n" +
"tabbedPane.addTab(\"Percent 2\", p2Tab);\n" +
"tabbedPane.addTab(\"Vertical 1\", v1Tab);\n" +
"tabbedPane.addTab(\"Vertical 2\", v2Tab);");
return tabbedPane;
}
public JComponent createBasic_Sizes()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Horizontal tab
MigLayout horLM = new MigLayout("",
"[]15[75px]25[min]25[]",
"[]15");
JPanel horTab = createTabPanel(horLM);
horTab.add(createLabel("75px"), "skip");
horTab.add(createLabel("Min"));
horTab.add(createLabel("Pref"), "wrap");
horTab.add(createLabel("new TextField(15)"));
horTab.add(createTextField(15));
horTab.add(createTextField(15));
horTab.add(createTextField(15));
// Vertical tab 1
MigLayout verLM = new MigLayout("flowy,wrap",
"[]15[]",
"[]15[c,45px]15[c,min]15[c,pref]");
JPanel verTab = createTabPanel(verLM);
verTab.add(createLabel("45px"), "skip");
verTab.add(createLabel("Min"));
verTab.add(createLabel("Pref"));
verTab.add(createLabel("new JTextArea(10, 40)"));
verTab.add(createTextArea("", 10, 40));
verTab.add(createTextArea("", 10, 40));
verTab.add(createTextArea("", 10, 40));
// Componentsized/Baseline 2
MigLayout verLM2 = new MigLayout("flowy,wrap",
"[]15[]",
"[]15[baseline]15[baseline]15[baseline]");
JPanel verTab2 = createTabPanel(verLM2);
verTab2.add(createLabel("45px"), "skip");
verTab2.add(createLabel("Min"));
verTab2.add(createLabel("Pref"));
verTab2.add(createLabel("new JTextArea(10, 40)"));
verTab2.add(createTextArea("", 10, 40), "height 45");
verTab2.add(createTextArea("", 10, 40), "height min");
verTab2.add(createTextArea("", 10, 40), "height pref");
tabbedPane.addTab("Horizontal - Column size set", horTab);
tabbedPane.addTab("Vertical - Row sized", verTab);
tabbedPane.addTab("Vertical - Component sized + Baseline", verTab2);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Horizontal tab\n" +
"MigLayout horLM = new MigLayout(\"\",\n" +
" \"[]15[75px]25[min]25[]\",\n" +
" \"[]15\");\n" +
"JPanel horTab = createTabPanel(horLM);\n" +
"horTab.add(createLabel(\"75px\"), \"skip\");\n" +
"horTab.add(createLabel(\"Min\"));\n" +
"horTab.add(createLabel(\"Pref\"), \"wrap\");\n" +
"\n" +
"horTab.add(createLabel(\"new TextField(15)\"));\n" +
"horTab.add(createTextField(15));\n" +
"horTab.add(createTextField(15));\n" +
"horTab.add(createTextField(15));\n" +
"\n" +
"// Vertical tab 1\n" +
"MigLayout verLM = new MigLayout(\"flowy,wrap\",\n" +
" \"[]15[]\",\n" +
" \"[]15[c,45px]15[c,min]15[c,pref]\");\n" +
"JPanel verTab = createTabPanel(verLM);\n" +
"verTab.add(createLabel(\"45px\"), \"skip\");\n" +
"verTab.add(createLabel(\"Min\"));\n" +
"verTab.add(createLabel(\"Pref\"));\n" +
"\n" +
"verTab.add(createLabel(\"new JTextArea(10, 40)\"));\n" +
"verTab.add(createTextArea(\"\", 10, 40));\n" +
"verTab.add(createTextArea(\"\", 10, 40));\n" +
"verTab.add(createTextArea(\"\", 10, 40));\n" +
"\n" +
"// Componentsized/Baseline 2\n" +
"MigLayout verLM2 = new MigLayout(\"flowy,wrap\",\n" +
" \"[]15[]\",\n" +
" \"[]15[baseline]15[baseline]15[baseline]\");\n" +
"JPanel verTab2 = createTabPanel(verLM2);\n" +
"verTab2.add(createLabel(\"45px\"), \"skip\");\n" +
"verTab2.add(createLabel(\"Min\"));\n" +
"verTab2.add(createLabel(\"Pref\"));\n" +
"\n" +
"verTab2.add(createLabel(\"new JTextArea(10, 40)\"));\n" +
"verTab2.add(createTextArea(\"\", 10, 40), \"height 45\");\n" +
"verTab2.add(createTextArea(\"\", 10, 40), \"height min\");\n" +
"verTab2.add(createTextArea(\"\", 10, 40), \"height pref\");\n" +
"\n" +
"tabbedPane.addTab(\"Horizontal - Column size set\", horTab);\n" +
"tabbedPane.addTab(\"Vertical - Row sized\", verTab);\n" +
"tabbedPane.addTab(\"Vertical - Component sized + Baseline\", verTab2);");
return tabbedPane;
}
public JComponent createAlignments()
{
JTabbedPane tabbedPane = new JTabbedPane();
// Horizontal tab
MigLayout horLM = new MigLayout("wrap",
"[label]15[left]15[center]15[right]15[fill]15[]",
"[]15[]");
String[] horLabels = new String[] {"[label]", "[left]", "[center]", "[right]", "[fill]", "[] (Default)"};
JPanel horTab = createTabPanel(horLM);
String[] horNames = new String[] {"First Name", "Phone Number", "Facsmile", "Email", "Address", "Other"};
for (int c = 0; c < horLabels.length; c++)
horTab.add(createLabel(horLabels[c]));
for (int r = 0; r < horLabels.length; r++) {
for (int c = 0; c < horNames.length; c++)
horTab.add(c == 0 ? createLabel(horNames[r] + ":") : createButton(horNames[r]));
}
// Vertical tab
MigLayout verLM = new MigLayout("wrap,flowy",
"[]unrel[]rel[]",
"[top]15[center]15[bottom]15[fill]15[fill,baseline]15[baseline]15[]");
String[] verLabels = new String[] {"[top]", "[center]", "[bottom]", "[fill]", "[fill,baseline]", "[baseline]", "[] (Default)"};
JPanel verTab = createTabPanel(verLM);
String[] verNames = benchRuns == 0 ? new String[] {"<html>One</html>", "<html>One<br>Two</html>"} : new String[] {"One", "One/Two"};
for (int c = 0; c < verLabels.length; c++)
verTab.add(createLabel(verLabels[c]));
for (int r = 0; r < verNames.length; r++) {
for (int c = 0; c < verLabels.length; c++)
verTab.add(createButton(verNames[r]));
}
for (int c = 0; c < verLabels.length; c++)
verTab.add(createTextField("JTextFied"));
for (int c = 0; c < verLabels.length; c++)
verTab.add(createTextArea("JTextArea", 1, 8));
for (int c = 0; c < verLabels.length; c++)
verTab.add(createTextArea("JTextArea\nwith two lines", 1, 10));
for (int c = 0; c < verLabels.length; c++)
verTab.add(createTextAreaScroll("Scrolling JTextArea\nwith two lines", 1, 15, true));
tabbedPane.addTab("Horizontal", horTab);
tabbedPane.addTab("Vertical", verTab);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// Horizontal tab\n" +
"MigLayout horLM = new MigLayout(\"wrap\",\n" +
" \"[left]15[center]15[right]15[fill]15[]\",\n" +
" \"rel[]rel\");\n" +
"\n" +
"String[] horLabels = new String[] {\"[left]\", \"[center]\", \"[right]\", \"[fill]\", \"[] (Default)\"};\n" +
"JPanel horTab = createTabPanel(horLM);\n" +
"String[] horNames = new String[] {\"First Name\", \"Phone Number\", \"Facsmile\", \"Email\", \"Address\"};\n" +
"for (int c = 0; c < horLabels.length; c++)\n" +
"\thorTab.add(createLabel(horLabels[c]));\n" +
"\n" +
"for (int r = 0; r < horLabels.length; r++) {\n" +
"\tfor (int c = 0; c < horNames.length; c++)\n" +
"\t\thorTab.add(createButton(horNames[r]));\n" +
"}\n" +
"\n" +
"// Vertical tab\n" +
"MigLayout verLM = new MigLayout(\"wrap,flowy\",\n" +
" \"[]unrel[]rel[]\",\n" +
" \"[top]15[center]15[bottom]15[fill]15[fill,baseline]15[baseline]15[]\");\n" +
"\n" +
"String[] verLabels = new String[] {\"[top]\", \"[center]\", \"[bottom]\", \"[fill]\", \"[fill,baseline]\", \"[baseline]\", \"[] (Default)\"};\n" +
"JPanel verTab = createTabPanel(verLM);\n" +
"\n" +
"String[] verNames = new String[] {\"<html>One</html>\", \"<html>One<br>Two</html>\"};\n" +
"for (int c = 0; c < verLabels.length; c++)\n" +
"\tverTab.add(createLabel(verLabels[c]));\n" +
"\n" +
"for (int r = 0; r < verNames.length; r++) {\n" +
"\tfor (int c = 0; c < verLabels.length; c++)\n" +
"\t\tverTab.add(createButton(verNames[r]));\n" +
"}\n" +
"\n" +
"for (int c = 0; c < verLabels.length; c++)\n" +
"\tverTab.add(createTextField(\"JTextFied\"));\n" +
"\n" +
"for (int c = 0; c < verLabels.length; c++)\n" +
"\tverTab.add(createTextArea(\"JTextArea\", 1, 8));\n" +
"\n" +
"for (int c = 0; c < verLabels.length; c++)\n" +
"\tverTab.add(createTextArea(\"JTextArea\\nwith two lines\", 1, 10));\n" +
"\n" +
"for (int c = 0; c < verLabels.length; c++)\n" +
"\tverTab.add(createTextAreaScroll(\"Scrolling JTextArea\\nwith two lines\", 1, 15, true));\n" +
"\n" +
"tabbedPane.addTab(\"Horizontal\", horTab);\n" +
"tabbedPane.addTab(\"Vertical\", verTab);");
return tabbedPane;
}
public JComponent createQuick_Start()
{
JTabbedPane tabbedPane = new JTabbedPane();
JPanel p = createTabPanel(new MigLayout("inset 20"));
addSeparator(p, "General");
p.add(createLabel("Company"), "gap para");
p.add(createTextField(""), "span, growx");
p.add(createLabel("Contact"), "gap para");
p.add(createTextField(""), "span, growx, wrap para");
addSeparator(p, "Propeller");
p.add(createLabel("PTI/kW"), "gap para");
p.add(createTextField(10));
p.add(createLabel("Power/kW"),"gap para");
p.add(createTextField(10), "wrap");
p.add(createLabel("R/mm"), "gap para");
p.add(createTextField(10));
p.add(createLabel("D/mm"), "gap para");
p.add(createTextField(10));
tabbedPane.addTab("Quick Start", p);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"JPanel p = createTabPanel(new MigLayout());\n" +
"\n" +
"addSeparator(p, \"General\");\n" +
"\n" +
"p.add(createLabel(\"Company\"), \"gap para\");\n" +
"p.add(createTextField(\"\"), \"span, growx, wrap\");\n" +
"p.add(createLabel(\"Contact\"), \"gap para\");\n" +
"p.add(createTextField(\"\"), \"span, growx, wrap para\");\n" +
"\n" +
"addSeparator(p, \"Propeller\");\n" +
"\n" +
"p.add(createLabel(\"PTI/kW\"), \"gap para\");\n" +
"p.add(createTextField(10));\n" +
"p.add(createLabel(\"Power/kW\"),\"gap para\");\n" +
"p.add(createTextField(10), \"wrap\");\n" +
"p.add(createLabel(\"R/mm\"), \"gap para\");\n" +
"p.add(createTextField(10));\n" +
"p.add(createLabel(\"D/mm\"), \"gap para\");\n" +
"p.add(createTextField(10));\n" +
"\n" +
"tabbedPane.addTab(\"Quick Start\", p);");
return tabbedPane;
}
public JComponent createGrow_Shrink()
{
JTabbedPane tabbedPane = new JTabbedPane();
// shrink tab
MigLayout slm = new MigLayout("nogrid");
JPanel sPanel = createTabPanel(slm);
JScrollPane sDescrText = createTextAreaScroll("Use the slider to see how the components shrink depending on the constraints set on them.\n\n'shp' means Shrink Priority. " +
"Lower values will be shrunk before higer ones and the default value is 100.\n\n'shrink' means Shrink Weight. " +
"Lower values relative to other's means they will shrink less when space is scarse. " +
"Shrink Weight is only relative to components with the same Shrink Priority. Default Shrink Weight is 100.\n\n" +
"The component's minimum size will always be honored.", 0, 0, true);
sDescrText.setOpaque(OPAQUE);
sDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));
((JTextArea) sDescrText.getViewport().getView()).setOpaque(OPAQUE);
sDescrText.getViewport().setOpaque(OPAQUE);
JSplitPane sSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sPanel, sDescrText);
sSplitPane.setOpaque(OPAQUE);
sSplitPane.setBorder(null);
sPanel.add(createTextField("shp 110", 12), "shp 110");
sPanel.add(createTextField("Default (100)", 12), "");
sPanel.add(createTextField("shp 90", 12), "shp 90");
sPanel.add(createTextField("shrink 25", 20), "newline,shrink 25");
sPanel.add(createTextField("shrink 75", 20), "shrink 75");
sPanel.add(createTextField("Default", 20), "newline");
sPanel.add(createTextField("Default", 20), "");
sPanel.add(createTextField("shrink 0", 40), "newline,shrink 0");
sPanel.add(createTextField("shp 110", 12), "newline,shp 110");
sPanel.add(createTextField("shp 100,shrink 25", 12), "shp 100,shrink 25");
sPanel.add(createTextField("shp 100,shrink 75", 12), "shp 100,shrink 75");
tabbedPane.addTab("Shrink", sSplitPane);
// Grow tab
MigLayout glm = new MigLayout("nogrid", "[grow]", "");
JPanel gPanel = createTabPanel(glm);
JScrollPane gDescrText = createTextAreaScroll("'gp' means Grow Priority. " +
"Higher values will be grown before lower ones and the default value is 100.\n\n'grow' means Grow Weight. " +
"Higher values relative to other's means they will grow more when space is up for takes. " +
"Grow Weight is only relative to components with the same Grow Priority. Default Grow Weight is 0 which means " +
"components will normally not grow. \n\nNote that the buttons in the first and last row have max width set to 170 to " +
"emphasize Grow Priority.\n\nThe component's maximum size will always be honored.", 0, 0, true);
gDescrText.setOpaque(OPAQUE);
gDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));
((JTextArea) gDescrText.getViewport().getView()).setOpaque(OPAQUE);
gDescrText.getViewport().setOpaque(OPAQUE);
JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, gPanel, gDescrText);
gSplitPane.setOpaque(OPAQUE);
gSplitPane.setBorder(null);
gPanel.add(createButton("gp 110,grow"), "gp 110,grow,wmax 170");
gPanel.add(createButton("Default (100),grow"), "grow,wmax 170");
gPanel.add(createButton("gp 90,grow"), "gp 90,grow,wmax 170");
gPanel.add(createButton("Default Button"), "newline");
gPanel.add(createButton("growx"), "newline,growx,wrap");
gPanel.add(createButton("gp 110,grow"), "gp 110,grow,wmax 170");
gPanel.add(createButton("gp 100,grow 25"), "gp 100,grow 25,wmax 170");
gPanel.add(createButton("gp 100,grow 75"), "gp 100,grow 75,wmax 170");
tabbedPane.addTab("Grow", gSplitPane);
// Disregard. Just forgetting the source code text close to the source code.
setSource("JTabbedPane tabbedPane = new JTabbedPane();\n" +
"\n" +
"// shrink tab\n" +
"MigLayout slm = new MigLayout(\"nogrid\");\n" +
"JPanel sPanel = createTabPanel(slm);\n" +
"\n" +
"JScrollPane sDescrText = createTextAreaScroll(\"Use the slider to see how the components shrink depending on the constraints set on them.\\n\\n'shp' means Shrink Priority. \" +\n" +
" \"Lower values will be shrunk before higer ones and the default value is 100.\\n\\n'shrink' means Shrink Weight. \" +\n" +
" \"Lower values relative to other's means they will shrink less when space is scarse. \" +\n" +
" \"Shrink Weight is only relative to components with the same Shrink Priority. Default Shrink Weight is 100.\\n\\n\" +\n" +
" \"The component's minimum size will always be honored.\", 0, 0, true);\n" +
"\n" +
"sDescrText.setOpaque(OPAQUE);\n" +
"sDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
"((JTextArea) sDescrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
"sDescrText.getViewport().setOpaque(OPAQUE);\n" +
"\n" +
"JSplitPane sSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, sPanel, sDescrText);\n" +
"sSplitPane.setOpaque(OPAQUE);\n" +
"sSplitPane.setBorder(null);\n" +
"\n" +
"sPanel.add(createTextField(\"shp 110\", 12), \"shp 110\");\n" +
"sPanel.add(createTextField(\"Default (100)\", 12), \"\");\n" +
"sPanel.add(createTextField(\"shp 90\", 12), \"shp 90\");\n" +
"\n" +
"sPanel.add(createTextField(\"shrink 25\", 20), \"newline,shrink 25\");\n" +
"sPanel.add(createTextField(\"shrink 75\", 20), \"shrink 75\");\n" +
"\n" +
"sPanel.add(createTextField(\"Default\", 20), \"newline\");\n" +
"sPanel.add(createTextField(\"Default\", 20), \"\");\n" +
"\n" +
"sPanel.add(createTextField(\"shrink 0\", 40), \"newline,shrink 0\");\n" +
"\n" +
"sPanel.add(createTextField(\"shp 110\", 12), \"newline,shp 110\");\n" +
"sPanel.add(createTextField(\"shp 100,shrink 25\", 12), \"shp 100,shrink 25\");\n" +
"sPanel.add(createTextField(\"shp 100,shrink 75\", 12), \"shp 100,shrink 75\");\n" +
"tabbedPane.addTab(\"Shrink\", sSplitPane);\n" +
"\n" +
"// Grow tab\n" +
"MigLayout glm = new MigLayout(\"nogrid\", \"[grow]\", \"\");\n" +
"JPanel gPanel = createTabPanel(glm);\n" +
"\n" +
"JScrollPane gDescrText = createTextAreaScroll(\"'gp' means Grow Priority. \" +\n" +
" \"Higher values will be grown before lower ones and the default value is 100.\\n\\n'grow' means Grow Weight. \" +\n" +
" \"Higher values relative to other's means they will grow more when space is up for takes. \" +\n" +
" \"Grow Weight is only relative to components with the same Grow Priority. Default Grow Weight is 0 which means \" +\n" +
" \"components will normally not grow. \\n\\nNote that the buttons in the first and last row have max width set to 170 to \" +\n" +
" \"emphasize Grow Priority.\\n\\nThe component's maximum size will always be honored.\", 0, 0, true);\n" +
"\n" +
"gDescrText.setOpaque(OPAQUE);\n" +
"gDescrText.setBorder(new EmptyBorder(10, 10, 10, 10));\n" +
"((JTextArea) gDescrText.getViewport().getView()).setOpaque(OPAQUE);\n" +
"gDescrText.getViewport().setOpaque(OPAQUE);\n" +
"\n" +
"JSplitPane gSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, gPanel, gDescrText);\n" +
"gSplitPane.setOpaque(OPAQUE);\n" +
"gSplitPane.setBorder(null);\n" +
"\n" +
"gPanel.add(createButton(\"gp 110,grow\"), \"gp 110,grow,wmax 170\");\n" +
"gPanel.add(createButton(\"Default (100),grow\"), \"grow,wmax 170\");\n" +
"gPanel.add(createButton(\"gp 90,grow\"), \"gp 90,grow,wmax 170\");\n" +
"\n" +
"gPanel.add(createButton(\"Default Button\"), \"newline\");\n" +
"\n" +
"gPanel.add(createButton(\"growx\"), \"newline,growx,wrap\");\n" +
"\n" +
"gPanel.add(createButton(\"gp 110,grow\"), \"gp 110,grow,wmax 170\");\n" +
"gPanel.add(createButton(\"gp 100,grow 25\"), \"gp 100,grow 25,wmax 170\");\n" +
"gPanel.add(createButton(\"gp 100,grow 75\"), \"gp 100,grow 75,wmax 170\");\n" +
"tabbedPane.addTab(\"Grow\", gSplitPane);");
return tabbedPane;
}
public JComponent createPlainApi()
{
JTabbedPane tabbedPane = new JTabbedPane();
MigLayout lm = new MigLayout(new LC(), null, null);
JPanel panel = createTabPanel(lm);
addSeparator(panel, "Manufacturer");
panel.add(createLabel("Company"));
panel.add(createTextField(""), "span,growx");
panel.add(createLabel("Contact"));
panel.add(createTextField(""), "span,growx");
panel.add(createLabel("Order No"));
panel.add(createTextField(15), "wrap");
addSeparator(panel, "Inspector");
panel.add(createLabel("Name"));
panel.add(createTextField(""), "span,growx");
panel.add(createLabel("Reference No"));
panel.add(createTextField(""), "wrap");
panel.add(createLabel("Status"));
panel.add(createCombo(new String[] {"In Progress", "Finnished", "Released"}), "wrap");
addSeparator(panel, "Ship");
panel.add(createLabel("Shipyard"));
panel.add(createTextField(""), "span,growx");
panel.add(createLabel("Register No"));
panel.add(createTextField(""));
panel.add(createLabel("Hull No"), "right");
panel.add(createTextField(15), "wrap");
panel.add(createLabel("Project StructureType"));
panel.add(createCombo(new String[] {"New Building", "Convention", "Repair"}));
tabbedPane.addTab("Plain", panel);
return tabbedPane;
}
// **********************************************************
// * Helper Methods
// **********************************************************
private final ToolTipListener toolTipListener = new ToolTipListener();
private final ConstraintListener constraintListener = new ConstraintListener();
private JLabel createLabel(String text)
{
return createLabel(text, SwingConstants.LEADING);
}
private JLabel createLabel(String text, int align)
{
final JLabel b = new JLabel(text, align);
configureActiveComponet(b);
return b;
}
public JComboBox createCombo(String[] items)
{
JComboBox combo = new JComboBox(items);
if (PlatformDefaults.getCurrentPlatform() == PlatformDefaults.MAC_OSX)
combo.setOpaque(false);
return combo;
}
private JTextField createTextField(int cols)
{
return createTextField("", cols);
}
private JTextField createTextField(String text)
{
return createTextField(text, 0);
}
private JTextField createTextField(String text, int cols)
{
final JTextField b = new JTextField(text, cols);
configureActiveComponet(b);
return b;
}
private static final Font BUTT_FONT = new Font("monospaced", Font.PLAIN, 12);
private JButton createButton()
{
return createButton("");
}
private JButton createButton(String text)
{
return createButton(text, false);
}
private JButton createButton(String text, boolean bold)
{
JButton b = new JButton(text) {
public void addNotify()
{
super.addNotify();
if (benchRuns == 0) { // Since this does not exist in the SWT version
if (getText().length() == 0) {
String lText = (String) ((MigLayout) getParent().getLayout()).getComponentConstraints(this);
setText(lText != null && lText.length() > 0 ? lText : "<Empty>");
}
} else {
setText("Benchmark Version");
}
}
};
if (bold)
b.setFont(b.getFont().deriveFont(Font.BOLD));
configureActiveComponet(b);
b.setOpaque(buttonOpaque); // Or window's buttons will have strange border
b.setContentAreaFilled(contentAreaFilled);
return b;
}
private JToggleButton createToggleButton(String text)
{
JToggleButton b = new JToggleButton(text);
// configureActiveComponet(b);
b.setOpaque(buttonOpaque); // Or window's buttons will have strange border
return b;
}
private JCheckBox createCheck(String text)
{
JCheckBox b = new JCheckBox(text);
configureActiveComponet(b);
b.setOpaque(OPAQUE); // Or window's checkboxes will have strange border
return b;
}
private JPanel createTabPanel(LayoutManager lm)
{
JPanel panel = new JPanel(lm);
configureActiveComponet(panel);
panel.setOpaque(OPAQUE);
return panel;
}
private JComponent createPanel()
{
return createPanel("");
}
private JComponent createPanel(String s)
{
JLabel panel = new JLabel(s, SwingConstants.CENTER) {
public void addNotify()
{
super.addNotify();
if (benchRuns == 0) { // Since this does not exist in the SWT version
if (getText().length() == 0) {
String lText = (String) ((MigLayout) getParent().getLayout()).getComponentConstraints(this);
setText(lText != null && lText.length() > 0 ? lText : "<Empty>");
}
}
}
};
panel.setBorder(new EtchedBorder());
panel.setOpaque(true);
configureActiveComponet(panel);
return panel;
}
private JTextArea createTextArea(String text, int rows, int cols)
{
JTextArea ta = new JTextArea(text, rows, cols);
ta.setBorder(UIManager.getBorder("TextField.border"));
ta.setFont(UIManager.getFont("TextField.font"));
ta.setWrapStyleWord(true);
ta.setLineWrap(true);
configureActiveComponet(ta);
return ta;
}
private JScrollPane createTextAreaScroll(String text, int rows, int cols, boolean hasVerScroll)
{
JTextArea ta = new JTextArea(text, rows, cols);
ta.setFont(UIManager.getFont("TextField.font"));
ta.setWrapStyleWord(true);
ta.setLineWrap(true);
JScrollPane scroll = new JScrollPane(
ta,
hasVerScroll ? ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED : ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
return scroll;
}
private JComponent configureActiveComponet(JComponent c)
{
if (benchRuns == 0) {
c.addMouseMotionListener(toolTipListener);
c.addMouseListener(constraintListener);
}
return c;
}
static final Color LABEL_COLOR = new Color(0, 70, 213);
private void addSeparator(JPanel panel, String text)
{
JLabel l = createLabel(text);
l.setForeground(LABEL_COLOR);
panel.add(l, "gapbottom 1, span, split 2, aligny center");
panel.add(configureActiveComponet(new JSeparator()), "gapleft rel, growx");
}
private class ConstraintListener extends MouseAdapter
{
public void mousePressed(MouseEvent e)
{
if (e.isPopupTrigger())
react(e);
}
public void mouseReleased(MouseEvent e)
{
if (e.isPopupTrigger())
react(e);
}
public void react(MouseEvent e)
{
JComponent c = (JComponent) e.getSource();
LayoutManager lm = c.getParent().getLayout();
if (lm instanceof MigLayout == false)
lm = c.getLayout();
if (lm instanceof MigLayout) {
MigLayout layout = (MigLayout) lm;
boolean isComp = layout.isManagingComponent(c);
Object compConstr = isComp ? layout.getComponentConstraints(c) : null;
if (isComp && compConstr == null)
compConstr = "";
Object rowsConstr = isComp ? null : layout.getRowConstraints();
Object colsConstr = isComp ? null : layout.getColumnConstraints();
Object layoutConstr = isComp ? null : layout.getLayoutConstraints();
ConstraintsDialog cDlg = new ConstraintsDialog(SwingDemo.this,
layoutConstr instanceof LC ? IDEUtil.getConstraintString((LC) layoutConstr, false) : (String) layoutConstr,
rowsConstr instanceof AC ? IDEUtil.getConstraintString((AC) rowsConstr, false, false) : (String) rowsConstr,
colsConstr instanceof AC ? IDEUtil.getConstraintString((AC) colsConstr, false, false) : (String) colsConstr,
compConstr instanceof CC ? IDEUtil.getConstraintString((CC) compConstr, false) : (String) compConstr);
cDlg.pack();
cDlg.setLocationRelativeTo(c);
if (cDlg.showDialog()) {
try {
if (isComp) {
String constrStr = cDlg.componentConstrTF.getText().trim();
layout.setComponentConstraints(c, constrStr);
if (c instanceof JButton) {
c.setFont(BUTT_FONT);
((JButton) c).setText(constrStr.length() == 0 ? "<Empty>" : constrStr);
}
} else {
layout.setLayoutConstraints(cDlg.layoutConstrTF.getText());
layout.setRowConstraints(cDlg.rowsConstrTF.getText());
layout.setColumnConstraints(cDlg.colsConstrTF.getText());
}
} catch(Exception ex) {
StringWriter sw = new StringWriter();
ex.printStackTrace(new PrintWriter(sw));
JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor(c), sw.toString(), "Error parsing Constraint!", JOptionPane.ERROR_MESSAGE);
return;
}
c.invalidate();
c.getParent().validate();
}
}
}
}
private static class ToolTipListener extends MouseMotionAdapter
{
public void mouseMoved(MouseEvent e)
{
JComponent c = (JComponent) e.getSource();
LayoutManager lm = c.getParent().getLayout();
if (lm instanceof MigLayout) {
Object constr = ((MigLayout) lm).getComponentConstraints(c);
if (constr instanceof String)
c.setToolTipText((constr != null ? ("\"" + constr + "\"") : "null"));
}
}
}
private static class ConstraintsDialog extends JDialog implements ActionListener, KeyEventDispatcher
{
private static final Color ERROR_COLOR = new Color(255, 180, 180);
private final JPanel mainPanel = new JPanel(new MigLayout("fillx,flowy,ins dialog",
"[fill]",
"2[]2"));
final JTextField layoutConstrTF;
final JTextField rowsConstrTF;
final JTextField colsConstrTF;
final JTextField componentConstrTF;
private final JButton okButt = new JButton("OK");
private final JButton cancelButt = new JButton("Cancel");
private boolean okPressed = false;
public ConstraintsDialog(Frame owner, String layoutConstr, String rowsConstr, String colsConstr, String compConstr)
{
super(owner, (compConstr != null ? "Edit Component Constraints" : "Edit Container Constraints"), true);
layoutConstrTF = createConstraintField(layoutConstr);
rowsConstrTF = createConstraintField(rowsConstr);
colsConstrTF = createConstraintField(colsConstr);
componentConstrTF = createConstraintField(compConstr);
if (componentConstrTF != null) {
mainPanel.add(new JLabel("Component Constraints"));
mainPanel.add(componentConstrTF);
}
if (layoutConstrTF != null) {
mainPanel.add(new JLabel("Layout Constraints"));
mainPanel.add(layoutConstrTF);
}
if (colsConstrTF != null) {
mainPanel.add(new JLabel("Column Constraints"), "gaptop unrel");
mainPanel.add(colsConstrTF);
}
if (rowsConstrTF != null) {
mainPanel.add(new JLabel("Row Constraints"), "gaptop unrel");
mainPanel.add(rowsConstrTF);
}
mainPanel.add(okButt, "tag ok,split,flowx,gaptop 15");
mainPanel.add(cancelButt, "tag cancel,gaptop 15");
setContentPane(mainPanel);
okButt.addActionListener(this);
cancelButt.addActionListener(this);
}
public void addNotify()
{
super.addNotify();
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(this);
}
public void removeNotify()
{
KeyboardFocusManager.getCurrentKeyboardFocusManager().removeKeyEventDispatcher(this);
super.removeNotify();
}
public boolean dispatchKeyEvent(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
dispose();
return false;
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == okButt)
okPressed = true;
dispose();
}
private JTextField createConstraintField(String text)
{
if (text == null)
return null;
final JTextField tf = new JTextField(text, 50);
tf.setFont(new Font("monospaced", Font.PLAIN, 12));
tf.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
okButt.doClick();
return;
}
javax.swing.Timer timer = new Timer(50, new ActionListener() {
public void actionPerformed(ActionEvent e)
{
String constr = tf.getText();
try {
if (tf == layoutConstrTF) {
ConstraintParser.parseLayoutConstraint(constr);
} else if (tf == rowsConstrTF) {
ConstraintParser.parseRowConstraints(constr);
} else if (tf == colsConstrTF) {
ConstraintParser.parseColumnConstraints(constr);
} else if (tf == componentConstrTF) {
ConstraintParser.parseComponentConstraint(constr);
}
tf.setBackground(Color.WHITE);
okButt.setEnabled(true);
} catch(Exception ex) {
tf.setBackground(ERROR_COLOR);
okButt.setEnabled(false);
}
}
});
timer.setRepeats(false);
timer.start();
}
});
return tf;
}
private boolean showDialog()
{
setVisible(true);
return okPressed;
}
}
}