File: ssgui.java

package info (click to toggle)
suitesparse 1%3A7.10.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 254,920 kB
  • sloc: ansic: 1,134,743; cpp: 46,133; makefile: 4,875; fortran: 2,087; java: 1,826; sh: 996; ruby: 725; python: 495; asm: 371; sed: 166; awk: 44
file content (2525 lines) | stat: -rw-r--r-- 91,155 bytes parent folder | download | duplicates (6)
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
//------------------------------------------------------------------------------
// ssget/ssgui.java: Java GUI interface to the SuiteSparse Matrix Collection
//------------------------------------------------------------------------------

// ssget, Copyright (c) 2009-2022, Timothy A. Davis. All Rights Reserved.
// SPDX-License-Identifier: BSD-3-clause

//------------------------------------------------------------------------------

// ssgui: a Java GUI interface for viewing, selecting, and downloading matrices
// from the SuiteSparse Matrix Collection.  To compile this program, type the
// following in your OS command window:
//
//      javac ssgui.java
//      jar cfe ssgui.jar ssgui *.class sshelp.html
//
// You can then delete the *.class files.  To run the program, type:
// 
//      java -jar ssgui.jar
//
// In all platforms except Windows (Mac, Linux, Solaris, ...) compile with:
//
//      make
//
// and run with
//
//      make run
//
//------------------------------------------------------------------------------
// Changing the default parameters for ssgui:
//------------------------------------------------------------------------------
//
// The following parameters of ssgui can be changed by editing this file and
// recompiling (see the comments "default settings" below in the code).
// Each setting is a string:
//
//      sssite: URL for the SuiteSparse Matrix Collection
//      default is sssite = "https://sparse.tamu.edu" ;
//
//      ssarchive: directory containing your copy of the collection.
//      If blank, then it defaults to the directory containing ssgui.
//
//      refresh: refresh time, in days, for updating the index.  use INF to
//      never refresh
//
//      proxy_server: HTTP proxy server. If none (default), then leave blank.
//
//      proxy port: default is 80 if left blank
//
// See sshelp.html for the license, and for help on how to use this program, or
// click "Help" in the GUI.

//------------------------------------------------------------------------------

import java.io.* ;
import java.util.* ;
import java.text.* ;
import java.net.* ;
import javax.swing.* ;
import javax.swing.table.* ;
import javax.swing.event.* ;
import java.awt.* ;
import java.awt.event.* ;

public class ssgui extends JFrame
{

    //--------------------------------------------------------------------------
    // private variables, accessible to all methods in this class
    //--------------------------------------------------------------------------

    private static final String
        ssstats = "files/ssstats.csv",
        ssindex = "files/ss_index.mat",
        all_kinds = "(all kinds)", all_groups = "(all groups)" ;
    private static final int K = 1024, M = K*K, buffersize = K,
        MSEC_PER_DAY = 86400000 ;

    private static long INF = Long.MAX_VALUE ;

    private long refresh ;
    private int nselected ;
    private int [ ] download_ids = null ;
    private boolean gui_ready, downloading, cancel, get_icons ;
    private boolean debug = false ;

    private matrix_Table_Model matrix_model = null ;

    private File mat, MM, RB, iconDir ;
    private String [ ] Kinds, Groups ;
    private Object [ ][ ] Stats ;

    private Date today, last_download ;

    // files and input/output streams
    private static String ftemp_name = null ;
    private static BufferedOutputStream ftemp_out = null ;
    private static BufferedInputStream url_in = null ;
    private static BufferedReader in_reader = null ;
    private static PrintWriter print_out = null ;
    private static String sssite, ssarchive, proxy_server, proxy_port ;

    // Java Swing components available to all methods in this class:
    private JTable matrix_Table ;
    private JButton download_Button, cancel_Button ;
    private JTextField minrow_Field, maxrow_Field, mincol_Field, maxcol_Field,
        minnentries_Field, maxnentries_Field, minpsym_Field, maxpsym_Field,
        minnsym_Field, maxnsym_Field ;
    private JRadioButton posdef_yes_Button, posdef_no_Button,
        posdef_either_Button, nd_yes_Button, nd_no_Button, nd_either_Button,
        real_yes_Button, real_no_Button, real_either_Button,
        shape_square_Button, shape_rect_Button, shape_either_Button ;
    private JLabel nselected_Label, progress_size_Label, icon_Label ;
    private JCheckBox format_mat_Button, format_mm_Button, format_rb_Button ;
    private JProgressBar progress1_Bar, progress2_Bar ;
    private JFileChooser chooser ;
    private JList Group_List, Kind_List ;

    //--------------------------------------------------------------------------
    // create the GUI
    //--------------------------------------------------------------------------

    private ssgui ( )
    {
        gui_ready = false ;
        downloading = false ;
        cancel = false ;
        final Font plain_Font = new Font ("SansSerif", Font.PLAIN, 12) ;
        final Font small_Font = new Font ("SansSerif", Font.PLAIN, 10) ;
        today = new Date ( ) ;
        last_download = new Date ( ) ;

        //----------------------------------------------------------------------
        // default settings.  Edit this file and recompile to change them.
        //----------------------------------------------------------------------

        // If ssarchive is blank, then it defaults to the current directory.
        ssarchive = "" ;

        // URL for the SuiteSparse Matrix Collection
        sssite = "https://sparse.tamu.edu" ;

        // refresh time, in days.  use INF to never refresh
        refresh = 30 ;   

        // HTTP proxy server. If none (default), then leave blank.
        proxy_server = "" ;

        // proxy port (default is 80 if left blank)
        proxy_port = "" ;

        //----------------------------------------------------------------------
        //----------------------------------------------------------------------

        // set up the HTTP proxy
        if (proxy_server.length ( ) > 0)
        {
            if (proxy_port.length ( ) == 0)
            {
                proxy_port = "80" ;
            }
            // set the proxy server and port
            System.setProperty ("proxySet", "true" ) ;
            System.setProperty ("http.proxyHost", proxy_server) ;
            System.setProperty ("http.proxyPort", proxy_port) ;
        }

        // ssarchive defaults to current working directory, if empty
        if (ssarchive.length ( ) == 0)
        {
            ssarchive = System.getProperty ("user.dir") ;
        }
        ssarchive = ssarchive.replace ('\\', File.separatorChar) ;
        ssarchive = ssarchive.replace ('/', File.separatorChar) ;
        char c = ssarchive.charAt (ssarchive.length ( ) - 1) ;
        if (c != File.separatorChar)
        {
            ssarchive += File.separatorChar ;
        }

        if (debug)
        {
            System.out.println ("") ;
            System.out.println ("ssgui, debugging enabled.") ;
            System.out.println ("local archive: [" + ssarchive    + "]") ;
            System.out.println ("ss url:        [" + sssite       + "]") ;
            System.out.println ("refresh:       [" + refresh      + "]") ;
            System.out.println ("proxy server:  [" + proxy_server + "]") ;
            System.out.println ("proxy port:    [" + proxy_port   + "]") ;
        }

        //----------------------------------------------------------------------
        // make sure the top-level directories exist

        mat = CheckDir ("mat") ;
        MM = CheckDir ("MM") ;
        RB = CheckDir ("RB") ;
        iconDir = CheckDir ("files") ;

        //----------------------------------------------------------------------
        // read in the matrix statistics

        Stats = load_ssstats ( ) ;

        if (Stats == null ||
            ((today.getTime ( ) - last_download.getTime ( )) / MSEC_PER_DAY
            > refresh))
        {
            // ssstats file is missing, or old.  Download both
            // files/ssstats.csv and mat/ss_index.mat.
            Stats = download_matrix_stats ( ) ;
            if (debug) System.out.println ("downloading new ssstats.csv file") ;
        }

        if (Stats == null)
        {
            // display error dialog and quit
            JOptionPane.showMessageDialog (this,
                "Download of matrix statistics file failed.",
                "Error", JOptionPane.ERROR_MESSAGE) ;
            System.exit (-1) ;
        }

        //----------------------------------------------------------------------
        // set the title, and close on [x]

        setTitle ("ssgui: SuiteSparse Matrix Collection") ;
        setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE) ;

        //----------------------------------------------------------------------
        // selection buttons

        JPanel select_Button_Panel = new JPanel ( ) ;

        JButton select_Button = new JButton ("Select") ;
        JButton unselect_Button = new JButton ("Deselect") ;
        JButton reset_Button = new JButton ("Reset criteria") ;
        JButton clear_Button = new JButton ("Clear selections") ;
        JButton help_Button = new JButton ("Help") ;

        select_Button_Panel.add (select_Button) ;
        select_Button_Panel.add (unselect_Button) ;
        select_Button_Panel.add (reset_Button) ;
        select_Button_Panel.add (clear_Button) ;
        select_Button_Panel.add (help_Button) ;

        select_Button.setToolTipText
        ("Click to add matrices that fit the criteria to your selection.") ;
        unselect_Button.setToolTipText ("Click to remove matrices " +
            "that fit the criteria from your selection.") ;
        reset_Button.setToolTipText ("Click to reset criteria, above.  " +
            "Prior selections, below, are not cleared.") ;
        clear_Button.setToolTipText ("Click to clear selections, below.  " +
            "Criteria, above, is not reset).") ;
        help_Button.setToolTipText ("For help, click here") ;

        select_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    make_selection (true) ;
                }
            }
        ) ;

        unselect_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    make_selection (false) ;
                }
            }
        ) ;

        reset_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    reset_Button_action (e) ;
                }
            }
        ) ;

        clear_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    clear_Button_action (e) ;
                }
            }
        ) ;

        help_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    help_Button_action (e) ;
                }
            }
        ) ;

        //----------------------------------------------------------------------
        // download button and format options

        JPanel format_Panel = new JPanel ( ) ;

        format_mat_Button = new JCheckBox ("MATLAB (mat)") ;
        format_mm_Button = new JCheckBox ("Matrix Market (MM)") ;
        format_rb_Button = new JCheckBox ("Rutherford/Boeing (RB)    ") ;

        format_mat_Button.setSelected (true) ;

        format_mat_Button.setToolTipText ("Download in MATLAB *.mat format.") ;
        format_mm_Button.setToolTipText ("Download in Matrix Market.") ;
        format_rb_Button.setToolTipText
            ("Download in Rutherford/Boeing format.") ;

        nselected = 0 ;
        nselected_Label = new JLabel ( ) ;
        download_Button = new JButton ("Download") ;

        format_Panel.add (download_Button) ;
        format_Panel.add (format_mat_Button) ;
        format_Panel.add (format_mm_Button) ;
        format_Panel.add (format_rb_Button) ;
        format_Panel.add (nselected_Label) ;
        format_Panel.setMaximumSize (new Dimension (0,0)) ;

        // progress bar and cancel button
        FlowLayout progress_Layout = new FlowLayout (FlowLayout.LEADING) ;
        JPanel progress_Panel = new JPanel (progress_Layout) ;

        cancel_Button = new JButton ("Cancel") ;
        cancel_Button.setEnabled (false) ;
        progress1_Bar = new JProgressBar ( ) ;
        progress2_Bar = new JProgressBar ( ) ;
        progress_size_Label = new JLabel ("") ;
        progress1_Bar.setMinimumSize (new Dimension (200,16)) ;
        progress2_Bar.setMinimumSize (new Dimension (200,16)) ;
        progress_Panel.add (cancel_Button) ;
        progress_Panel.add (new JLabel ("   Overall progress:")) ;
        progress_Panel.add (progress1_Bar) ;
        progress_Panel.add (new JLabel ("   Current file:")) ;
        progress_Panel.add (progress2_Bar) ;
        progress_Panel.add (progress_size_Label) ;
        progress_Panel.setMaximumSize (new Dimension (0,0)) ;
        cancel_Button.setToolTipText ("No downloads in progress.") ;

        download_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    download_Button_action (e) ;
                }
            }
        ) ;

        cancel_Button.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    cancel_Button_action (e) ;
                }
            }
        ) ;

        JPanel download_Panel = new JPanel ( ) ;
        GroupLayout layout3 = new GroupLayout (download_Panel) ;
        download_Panel.setLayout (layout3) ;

        layout3.setAutoCreateGaps (true) ;
        layout3.setAutoCreateContainerGaps (false) ;

        layout3.setHorizontalGroup
        (
            layout3.createParallelGroup (GroupLayout.Alignment.LEADING)
                .addComponent (format_Panel)
                .addComponent (progress_Panel)
        ) ;

        layout3.setVerticalGroup
        (
            layout3.createSequentialGroup ( )
                .addComponent (format_Panel)
                .addComponent (progress_Panel)
        ) ;

        download_Panel.setBorder
            (BorderFactory.createTitledBorder ("download")) ;
        download_Panel.setMaximumSize (new Dimension (0,0)) ;

        //----------------------------------------------------------------------
        // panel for m, n, nentries, psym, and nsym

        // # of rows
        minrow_Field = new JTextField ("") ;
        JLabel rowlabel = new JLabel (" \u2264 number of rows \u2264 ") ;
        maxrow_Field = new JTextField ("") ;
        minrow_Field.setColumns (16) ;
        maxrow_Field.setColumns (16) ;
        minrow_Field.setToolTipText ("Leave blank for 'zero'.") ;
        maxrow_Field.setToolTipText ("Leave blank for 'infinite'.") ;
        minrow_Field.setMinimumSize (new Dimension (120,0)) ;
        maxrow_Field.setMinimumSize (new Dimension (120,0)) ;

        // # of columns
        mincol_Field = new JTextField ("") ;
        JLabel collabel = new JLabel (" \u2264 number of columns \u2264 ") ;
        maxcol_Field = new JTextField ("") ;
        mincol_Field.setColumns (16) ;
        maxcol_Field.setColumns (16) ;
        mincol_Field.setToolTipText ("Leave blank for 'zero'.") ;
        maxcol_Field.setToolTipText ("Leave blank for 'infinite'.") ;
        mincol_Field.setMinimumSize (new Dimension (120,0)) ;
        maxcol_Field.setMinimumSize (new Dimension (120,0)) ;

        // # of entries
        minnentries_Field = new JTextField ("") ;
        JLabel nentrieslabel = new JLabel (" \u2264 number of entries \u2264 ");
        maxnentries_Field = new JTextField ("") ;
        minnentries_Field.setColumns (16) ;
        maxnentries_Field.setColumns (16) ;
        minnentries_Field.setToolTipText ("Leave blank for 'zero'.") ;
        maxnentries_Field.setToolTipText ("Leave blank for 'infinite'.") ;
        minnentries_Field.setMinimumSize (new Dimension (120,0)) ;
        maxnentries_Field.setMinimumSize (new Dimension (120,0)) ;

        // pattern symmetry
        minpsym_Field = new JTextField ("0.0") ;
        JLabel psymlabel = new JLabel (" \u2264 pattern symmetry \u2264 ") ;
        maxpsym_Field = new JTextField ("1.0") ;
        minpsym_Field.setColumns (16) ;
        maxpsym_Field.setColumns (16) ;
        maxpsym_Field.setToolTipText (
        "Refers to position of entries, not their values.\n" +
        "1 = perfectly symmetric pattern, 0 = perfectly unsymmetric pattern.") ;
        minpsym_Field.setMinimumSize (new Dimension (120,0)) ;
        maxpsym_Field.setMinimumSize (new Dimension (120,0)) ;

        // numerical symmetry
        minnsym_Field = new JTextField ("0.0") ;
        JLabel nsymlabel = new JLabel (" \u2264 numerical symmetry \u2264 ") ;
        maxnsym_Field = new JTextField ("1.0") ;
        minnsym_Field.setColumns (16) ;
        maxnsym_Field.setColumns (16) ;
        maxnsym_Field.setToolTipText (
        "1 means A=A', 0 means no nonzero entry A(i,j) = A(j,i).") ;
        minnsym_Field.setMinimumSize (new Dimension (120,0)) ;
        maxnsym_Field.setMinimumSize (new Dimension (120,0)) ;

        JPanel range_Panel = new JPanel ( ) ;
        GroupLayout layout5 = new GroupLayout (range_Panel) ;
        range_Panel.setLayout (layout5) ;
        layout5.setAutoCreateGaps (false) ;
        layout5.setAutoCreateContainerGaps (false) ;

        layout5.setHorizontalGroup
        (
            layout5.createSequentialGroup ( )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (minrow_Field)
                        .addComponent (mincol_Field)
                        .addComponent (minnentries_Field)
                        .addComponent (minpsym_Field)
                        .addComponent (minnsym_Field)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (rowlabel)
                        .addComponent (collabel)
                        .addComponent (nentrieslabel)
                        .addComponent (psymlabel)
                        .addComponent (nsymlabel)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (maxrow_Field)
                        .addComponent (maxcol_Field)
                        .addComponent (maxnentries_Field)
                        .addComponent (maxpsym_Field)
                        .addComponent (maxnsym_Field)
                )
        ) ;

        layout5.setVerticalGroup
        (
            layout5.createSequentialGroup ( )

                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (minrow_Field)
                        .addComponent (rowlabel)
                        .addComponent (maxrow_Field)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (mincol_Field)
                        .addComponent (collabel)
                        .addComponent (maxcol_Field)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (minnentries_Field)
                        .addComponent (nentrieslabel)
                        .addComponent (maxnentries_Field)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (minpsym_Field)
                        .addComponent (psymlabel)
                        .addComponent (maxpsym_Field)
                )
                .addGroup
                (
                    layout5.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (minnsym_Field)
                        .addComponent (nsymlabel)
                        .addComponent (maxnsym_Field)
                )

        ) ;

        range_Panel.setMaximumSize (new Dimension (0,0)) ;
        // range_Panel.setBorder (BorderFactory.createTitledBorder ("range")) ;

        //----------------------------------------------------------------------
        // checkbox panel for posdef, ND, real, and format

        // square or rectangular
        JLabel shape_label = new JLabel ("shape ") ;
        shape_square_Button = new JRadioButton ("square   ") ;
        shape_rect_Button = new JRadioButton ("rectangular   ") ;
        shape_either_Button = new JRadioButton ("either   ") ;
        shape_either_Button.setSelected (true) ;
        ButtonGroup shape_group = new ButtonGroup ( ) ;
        shape_group.add (shape_square_Button) ;
        shape_group.add (shape_rect_Button) ;
        shape_group.add (shape_either_Button) ;
        shape_square_Button.setToolTipText
            ("Select 'yes' for square matrices.") ;
        shape_rect_Button.setToolTipText
            ("Select 'no' for rectangular matrices only.") ;
        shape_either_Button.setToolTipText
            ("Select 'either' for any matrix.") ;

        // positive definite
        JLabel posdef_label = new JLabel ("positive definite? ") ;
        posdef_yes_Button = new JRadioButton ("yes") ;
        posdef_no_Button = new JRadioButton ("no") ;
        posdef_either_Button = new JRadioButton ("either") ;
        posdef_either_Button.setSelected (true) ;
        ButtonGroup posdef_group = new ButtonGroup ( ) ;
        posdef_group.add (posdef_yes_Button) ;
        posdef_group.add (posdef_no_Button) ;
        posdef_group.add (posdef_either_Button) ;

        posdef_yes_Button.setToolTipText
            ("Select 'yes' for symmetric positive definite matrices only.") ;
        posdef_no_Button.setToolTipText
            ("Select 'no' for non-positive definite matrices only.") ;
        posdef_either_Button.setToolTipText
            ("Select 'either' for any matrix.") ;

        // 2D/3D
        JLabel nd_label = new JLabel ("2D/3D discretization?    ") ;
        nd_yes_Button = new JRadioButton ("yes") ;
        nd_no_Button = new JRadioButton ("no") ;
        nd_either_Button = new JRadioButton ("either") ;
        nd_either_Button.setSelected (true) ;
        ButtonGroup nd_group = new ButtonGroup ( ) ;
        nd_group.add (nd_yes_Button) ;
        nd_group.add (nd_no_Button) ;
        nd_group.add (nd_either_Button) ;

        nd_yes_Button.setToolTipText
            ("Select 'yes' for matrices " +
            "arising from 2D or 3D discretizations only.") ;
        nd_no_Button.setToolTipText
            ("Select 'no' to exclude matrices " +
            "arising from 2D or 3D discretizations.") ;
        nd_either_Button.setToolTipText ("Select 'either' for any matrix.") ;

        // real or complex
        JLabel real_label = new JLabel ("real or complex? ") ;
        real_yes_Button = new JRadioButton ("real") ;
        real_no_Button = new JRadioButton ("complex") ;
        real_either_Button = new JRadioButton ("either") ;
        real_either_Button.setSelected (true) ;
        ButtonGroup real_group = new ButtonGroup ( ) ;
        real_group.add (real_yes_Button) ;
        real_group.add (real_no_Button) ;
        real_group.add (real_either_Button) ;

        real_yes_Button.setToolTipText
            ("Select 'real' for real matrices only (includes integer and binary).") ;
        real_no_Button.setToolTipText
            ("Select 'complex' for complex matrices only.") ;
        real_either_Button.setToolTipText
            ("Select 'either' for any matrix.") ;

        JPanel check_Panel = new JPanel ( ) ;
        GroupLayout layout4 = new GroupLayout (check_Panel) ;
        check_Panel.setLayout (layout4) ;
        layout4.setAutoCreateGaps (false) ;
        layout4.setAutoCreateContainerGaps (false) ;

        layout4.setHorizontalGroup
        (
            layout4.createSequentialGroup ( )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (shape_label)
                        .addComponent (posdef_label)
                        .addComponent (nd_label)
                        .addComponent (real_label)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (shape_square_Button)
                        .addComponent (posdef_yes_Button)
                        .addComponent (nd_yes_Button)
                        .addComponent (real_yes_Button)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (shape_rect_Button)
                        .addComponent (posdef_no_Button)
                        .addComponent (nd_no_Button)
                        .addComponent (real_no_Button)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (shape_either_Button)
                        .addComponent (posdef_either_Button)
                        .addComponent (nd_either_Button)
                        .addComponent (real_either_Button)
                )
        ) ;

        layout4.setVerticalGroup
        (
            layout4.createSequentialGroup ( )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (shape_label)
                        .addComponent (shape_square_Button)
                        .addComponent (shape_rect_Button)
                        .addComponent (shape_either_Button)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (posdef_label)
                        .addComponent (posdef_yes_Button)
                        .addComponent (posdef_no_Button)
                        .addComponent (posdef_either_Button)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (nd_label)
                        .addComponent (nd_yes_Button)
                        .addComponent (nd_no_Button)
                        .addComponent (nd_either_Button)
                )
                .addGroup
                (
                    layout4.createParallelGroup (GroupLayout.Alignment.LEADING)
                        .addComponent (real_label)
                        .addComponent (real_yes_Button)
                        .addComponent (real_no_Button)
                        .addComponent (real_either_Button)
                )
        ) ;

        check_Panel.setMaximumSize (new Dimension (0,0)) ;

        //----------------------------------------------------------------------
        // Group and Kind lists

        Kinds = FindKinds ( ) ;
        Groups = FindGroups ( ) ;

        // Group_List = new JList ((Object [ ]) Groups) ;
        // Kind_List = new JList ((Object [ ]) Kinds) ;
        Group_List = new JList<String> (Groups) ;
        Kind_List = new JList<String> (Kinds) ;

        JScrollPane Group_Pane = new JScrollPane (Group_List) ;
        JScrollPane Kind_Pane = new JScrollPane (Kind_List) ;

        Kind_Pane.setBorder (BorderFactory.createTitledBorder ("kind")) ;
        Group_Pane.setBorder (BorderFactory.createTitledBorder ("group")) ;

        Group_List.setFont (plain_Font) ;
        Kind_List.setFont (plain_Font) ;

        Group_Pane.setVerticalScrollBarPolicy
            (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) ;
        Kind_Pane.setVerticalScrollBarPolicy
            (ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) ;

        Group_List.setVisibleRowCount (5) ;
        Kind_List.setVisibleRowCount (5) ;

        JPanel list_Panel = new JPanel ( ) ;
        GroupLayout layout9 = new GroupLayout (list_Panel) ;
        list_Panel.setLayout (layout9) ;

        layout9.setAutoCreateGaps (true) ;
        layout9.setAutoCreateContainerGaps (false) ;

        layout9.setHorizontalGroup
        (
            layout9.createSequentialGroup ( )
                .addComponent (Group_Pane)
                .addComponent (Kind_Pane)
        ) ;

        layout9.setVerticalGroup
        (
            layout9.createParallelGroup (GroupLayout.Alignment.LEADING)
                .addComponent (Group_Pane)
                .addComponent (Kind_Pane)
        ) ;

        list_Panel.setMinimumSize (new Dimension (450,150)) ;

        //----------------------------------------------------------------------
        // selection panel
        JPanel selection_Panel = new JPanel ( ) ;
        GroupLayout layout2 = new GroupLayout (selection_Panel) ;
        selection_Panel.setLayout (layout2) ;
        layout2.setAutoCreateGaps (true) ;
        layout2.setAutoCreateContainerGaps (false) ;
        layout2.setHorizontalGroup
        (
            layout2.createParallelGroup (GroupLayout.Alignment.LEADING)
                .addComponent (range_Panel)
                .addComponent (check_Panel)
                .addComponent (list_Panel)
                .addComponent (select_Button_Panel)
        ) ;
        layout2.setVerticalGroup
        (
            layout2.createSequentialGroup ( )
                .addComponent (range_Panel)
                .addComponent (check_Panel)
                .addComponent (list_Panel)
                .addComponent (select_Button_Panel)
        ) ;
        selection_Panel.setBorder
            (BorderFactory.createTitledBorder ("selection criteria")) ;
        selection_Panel.setMaximumSize (new Dimension (0,0)) ;

        //----------------------------------------------------------------------
        // create the table of matrices

        matrix_model = new matrix_Table_Model ( ) ;
        matrix_Table = new JTable (matrix_model)
        {
            // table header tool tips
            protected JTableHeader createDefaultTableHeader ( )
            {
                return new JTableHeader (columnModel)
                {
                    public String getToolTipText (MouseEvent e)
                    {
                        String tip = null ;
                        java.awt.Point p = e.getPoint ( ) ;
                        int i = columnModel.getColumnIndexAtX (p.x) ;
                        int j = columnModel.getColumn (i).getModelIndex ( ) ;
                        return matrix_column_tooltips [j] ;
                    }
                } ;
            }
        } ;

        JTableHeader header = matrix_Table.getTableHeader ( ) ;
        final TableCellRenderer hr = header.getDefaultRenderer ( ) ;
        header.setDefaultRenderer
        (
            new TableCellRenderer ( )
            {
                public Component getTableCellRendererComponent (JTable table,
                    Object value, boolean isSelected, boolean hasFocus,
                    int row, int column)
                {
                    Component co = hr.getTableCellRendererComponent (
                        table, value, isSelected, hasFocus, row, column) ;
                    co.setFont (small_Font) ;
                    return (co) ;
                }
            }
        ) ;

        matrix_model.load_data (Stats) ;

        //----------------------------------------------------------------------
        // popup menu for the table

        JPopupMenu popup = new JPopupMenu ( ) ;

        JMenuItem select_menuItem =
            new JMenuItem ("Select highlighted matrices") ;
        select_menuItem.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    popup_action (e, true) ;
                }
            }
        ) ;

        JMenuItem unselect_menuItem =
            new JMenuItem ("Deselect highlighted matrices") ;
        unselect_menuItem.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    popup_action (e, false) ;
                }
            }
        ) ;

        JMenuItem exportcsv_menuItem =
            new JMenuItem ("Export selected matrices as CSV file") ;
        exportcsv_menuItem.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    export_list_action (e, true) ;
                }
            }
        ) ;

        JMenuItem exportm_menuItem =
            new JMenuItem ("Export selected matrices as MATLAB *.m file") ;
        exportm_menuItem.addActionListener
        (
            new ActionListener ( )
            {
                public void actionPerformed (ActionEvent e)
                {
                    export_list_action (e, false) ;
                }
            }
        ) ;

        popup.add (select_menuItem) ;
        popup.add (unselect_menuItem) ;
        popup.add (exportcsv_menuItem) ;
        popup.add (exportm_menuItem) ;

        // Add listener to components that can bring up popup menus.
        matrix_Table.addMouseListener (new matrix_Table_PopupListener (popup)) ;

        //----------------------------------------------------------------------
        // set default column widths

        int [ ] columnwidth = {
            40,     // 0:select
            30,     // 1:mat
            25,     // 2:MM
            25,     // 3:RB
            38,     // 4:id
            110,    // 5:Group
            150,    // 6:Name
            70,     // 7:nrows
            70,     // 8:ncols
            70,     // 9:nentries
            40,     // 10:isReal
            40,     // 11:isBinary
            40,     // 12:isND
            40,     // 13:posdef
            50,     // 14:psym
            50,     // 15:nsym
            200 } ; // 16:kind

        TableColumn column = null ;
        for (int col = 0 ; col < 17 ; col++)
        {
            column = matrix_Table.getColumnModel ( ).getColumn (col) ;
            column.setPreferredWidth (columnwidth [col]) ;
        }

        //----------------------------------------------------------------------
        // set the view size, sort by id, and add the table to a scroll pane

        matrix_Table.setPreferredScrollableViewportSize
            (new Dimension (500,70)) ;
        matrix_Table.setFillsViewportHeight (true) ;
        matrix_Table.setAutoCreateRowSorter (true) ;

        matrix_Table.getSelectionModel ( )
            .addListSelectionListener (new matrix_Table_RowListener ( )) ;

        // sort by id
        java.util.List <RowSorter.SortKey> sortKeys =
            new ArrayList<RowSorter.SortKey> ( ) ;
        sortKeys.add (new RowSorter.SortKey (4, SortOrder.ASCENDING)) ;
        (matrix_Table.getRowSorter ( )).setSortKeys (sortKeys) ; 

        matrix_Table.getTableHeader ( ).setReorderingAllowed (false) ;
        JScrollPane scroll_Pane = new JScrollPane (matrix_Table) ;
        scroll_Pane.setBorder (BorderFactory.createTitledBorder (ssarchive)) ;

        //----------------------------------------------------------------------
        // create the icon and display the default matrix

        icon_Label = new JLabel ( ) ;
        icon_Label.setFont (plain_Font) ;
        icon_Label.setVerticalTextPosition (JLabel.BOTTOM) ;
        icon_Label.setHorizontalTextPosition (JLabel.CENTER) ;
        icon_Label.setBorder (BorderFactory.createTitledBorder ("matrix icon"));
        update_icon ("HB/west0479") ;

        //----------------------------------------------------------------------
        // create the top panel (selection panel and icon)

        JPanel top_Panel = new JPanel ( ) ;
        GroupLayout layout8 = new GroupLayout (top_Panel) ;
        top_Panel.setLayout (layout8) ;

        layout8.setAutoCreateGaps (true) ;
        layout8.setAutoCreateContainerGaps (false) ;

        layout8.setHorizontalGroup
        (
            layout8.createSequentialGroup ( )
                .addComponent (selection_Panel)
                .addComponent (icon_Label)
        ) ;

        layout8.setVerticalGroup
        (
            layout8.createParallelGroup (GroupLayout.Alignment.LEADING)
                .addComponent (selection_Panel)
                .addComponent (icon_Label)
        ) ;

        top_Panel.setMaximumSize (new Dimension (0,0)) ;

        //----------------------------------------------------------------------
        // create the root layout manager

        Container pane = getContentPane ( ) ;
        GroupLayout layout = new GroupLayout (pane) ;
        pane.setLayout (layout) ;
        layout.setAutoCreateGaps (true) ;
        layout.setAutoCreateContainerGaps (false) ;

        layout.setHorizontalGroup
        (
            layout.createParallelGroup (GroupLayout.Alignment.LEADING)
                .addComponent (top_Panel)
                .addComponent (scroll_Pane)
                .addComponent (download_Panel)
        ) ;

        layout.setVerticalGroup
        (
            layout.createSequentialGroup ( )
                .addComponent (top_Panel)
                .addComponent (scroll_Pane)
                .addComponent (download_Panel)
        ) ;

        setSize (1100,750) ;

        //----------------------------------------------------------------------
        // create the file chooser; not shown until "export" is chosen

        chooser = new JFileChooser ( ) ;
        chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES) ;

        gui_ready = true ;
        set_selected_label (true) ;

        //----------------------------------------------------------------------
        // start a thread to download any icons not present

        get_all_icons ( ) ;
    }

    //--------------------------------------------------------------------------
    // yes/no/unknown
    //--------------------------------------------------------------------------

    private String yes_no (int k)
    {
        if (k < 0)
        {
            return ("?") ;
        }
        else if (k == 0)
        {
            return ("no") ;
        }
        else
        {
            return ("yes") ;
        }
    }

    //--------------------------------------------------------------------------
    // ternary
    //--------------------------------------------------------------------------

    private int ternary (String s)
    {
        long k = Long.parseLong (s) ;
        if (k < 0)
        {
            return (-1) ;
        }
        else if (k == 0)
        {
            return (0) ;
        }
        else
        {
            return (1) ;
        }
    }

    //--------------------------------------------------------------------------
    // read the ssstats file
    //--------------------------------------------------------------------------

    private Object [ ][ ] load_ssstats ( )
    {
        if (debug) System.out.println ("reading ssstats.csv file") ;
        Object [ ][ ] S = null ;
        int nmatrices = 0 ;
        in_reader = null ;
        try
        {
            // get the number of matrices in the ss Sparse Matrix Collection
            in_reader = new BufferedReader (new FileReader
                (fix_name (ssstats))) ;
            nmatrices = Integer.parseInt (in_reader.readLine ( )) ;
            // skip past the creation date and time
            String ignore = in_reader.readLine ( ) ;
            // get the time of last download from the file modification time
            last_download =
                new Date (new File (fix_name (ssstats)).lastModified ( )) ;
        }
        catch (Exception e)
        {
            // this is OK, for now, since we can try to download a new one
            if (debug) System.out.println ("reading ssstats.csv file failed") ;
            return (null) ;
        }
        try
        {
            // read the rest of the file
            S = new Object [nmatrices][13] ;
            for (int id = 1 ; id <= nmatrices ; id++)
            {
                // split the tokens by comma
                String [ ] r = (in_reader.readLine ( )).split (",") ;
                S [id-1][0]  = id ;                             // id
                S [id-1][1]  = r [0] ;                          // Group
                S [id-1][2]  = r [1] ;                          // Name
                S [id-1][3]  = Long.parseLong (r [2]) ;         // nrows
                S [id-1][4]  = Long.parseLong (r [3]) ;         // ncols
                // NOTE: r [4] = nnz is now ignored, and r [12] used instead
                S [id-1][5]  = Long.parseLong (r [12]) ;        // nentries

                S [id-1][6]  = ternary (r [5]) ;                // isReal
                S [id-1][7]  = ternary (r [6]) ;                // isBinary
                S [id-1][8]  = ternary (r [7]) ;                // isND
                S [id-1][9]  = ternary (r [8]) ;                // posdef

                S [id-1][10] = Double.parseDouble (r [9]) ;     // psym
                S [id-1][11] = Double.parseDouble (r [10]) ;    // nsym
                S [id-1][12] = r [11] ;                         // kind
            }
        }
        catch (Exception e)
        {
            // this is OK, for now, since we can try to download a new one
            if (debug) System.out.println ("reading ssstats.csv file failed") ;
            return (null) ;
        }
        finally
        {
            close_reader (in_reader) ;
        }
        return (S) ;
    }

    //--------------------------------------------------------------------------
    // tool tips for each column of the matrix table
    //--------------------------------------------------------------------------

    protected String [ ] matrix_column_tooltips =
    {
        // 0:select:
        "Click to select a matrix.  This is the only column you can edit.",
        "'x' if MAT format already downloaded",                 // 1:mat
        "'x' if MM format already downloaded",                  // 2:MM
        "'x' if RB format already downloaded",                  // 3:MM
        "matrix id",                                        // 4:id
        "matrix group (typically a person or organization)",// 5:Group
        "matrix name (full name is Group/Name)",            // 6:Name
        "# of rows in the matrix",                          // 7:nrows
        "# of columns in the matrix",                       // 8:ncols
        "# of entries in the matrix (both nonzeros and explicit zeros)",
                                                            // 9:nentries
        "if the matrix is real (not complex)",              // 10:isReal
        "if the matrix is binary",                          // 11:isBinary
        "if the matrix arises from a 2D/3D discretization", // 12:isND
        "if the matrix is symmetric positive definite",     // 13:posdef
        // 14:psym:
        "symmetry of pattern (0: none, 1: pattern(A)=pattern(A')",
        "symmetry of nonzero values (0: none, 1: A=A'",     // 15:nsym
        // 16:kind:
        "the matrix 'kind' is the problem domain from which it arises" 
    } ;

    //--------------------------------------------------------------------------
    // control whether changes to the table cause updates to fire
    //--------------------------------------------------------------------------

    public boolean fire_status = true ;

    public void fire_updates (boolean fire)
    {
        fire_status = fire ;
        if (fire)
        {
            // touch the table to force a fire
            set_table_value (get_table_value (1, 0), 1, 0) ;
        }
    }

    //--------------------------------------------------------------------------
    // table of matrix statistics
    //--------------------------------------------------------------------------

    class matrix_Table_Model extends AbstractTableModel
    {
        private String [ ] columnNames =
            {
            "select", "mat", "MM", "RB",
            "id", "Group", "Name", "# rows", "# cols", "# entries", "real",
            "binary", "2D/3D", "posdef", "psym", "nsym", "kind" } ;

        private Object [ ][ ] data = null ;

        public int getColumnCount ( )
        {
            return (columnNames.length) ;
        }

        public int getRowCount ( )
        {
            return (data.length) ;
        }

        public String getColumnName (int col)
        {
            return (columnNames [col]) ;
        }

        public Object getValueAt (int row, int col)
        {
            return (data [row][col]) ;
        }

        public boolean isCellEditable (int row, int col)
        {
            // only the "select" column is edittable
            return (col == 0) ;
        }

        public void setValueAt (Object value, int row, int col)
        {
            if (col == 0 && gui_ready && ((Boolean) data [row][0]) != value)
            {
                if ((Boolean) value == false)
                {
                    // changing from selected to unselected
                    nselected-- ;
                }
                else
                {
                    // changing from unselected to selected
                    nselected++ ;
                }
                set_selected_label (download_Button.isEnabled ( )) ;
            }
            data [row][col] = value ;
            if (fire_status) fireTableDataChanged ( ) ;
        }

        public Class getColumnClass (int col)
        {
            return (getValueAt (0, col).getClass ( )) ;
        }

        public void load_data (Object [ ][ ] newstats)
        {
            // load the matrix table with all matrix statistics
            data = new Object [newstats.length][17] ;
            nselected = 0 ;
            for (int i = 0 ; i < newstats.length ; i++)
            {
                // i and j are in terms of the view, but the table is not yet
                // sorted because it is not yet visible
                data [i][0] = false ;   // select column is false
                for (int j = 1 ; j < 4 ; j++)
                {
                    // mat, MM, and RB, which can change later:
                    data [i][j] = "-" ;
                }
                for (int j = 0 ; j < 13 ; j++)
                {
                    // matrix stats, which do not change:
                    // 4:id, 5:Group, 6:Name, 7:nrows, 8:ncols, 9:nentries,
                    // 10:isreal, 11:isBinary, 12:isND, 13:posdef, 14: psym,
                    // 15:nsym, 16:kind
                    if (j >= 6 && j <= 9)
                    {
                        int k = (Integer) newstats [i][j] ;
                        if (k < 0)
                        {
                            data [i][j+4] = " ?" ;
                        }
                        else if (k == 0)
                        {
                            data [i][j+4] = " no" ;
                        }
                        else
                        {
                            data [i][j+4] = " yes" ;
                        }
                    }
                    else
                    {
                        data [i][j+4] = newstats [i][j] ;
                    }
                }
            }
            fireTableDataChanged ( ) ;
        }
    }

    //--------------------------------------------------------------------------
    // get a value from the matrix table
    //--------------------------------------------------------------------------

    private Object get_table_value (int id, int j)
    {
        // id is in the range 1 to Stats.length.  The model index is id-1.
        // Convert this to the row index of the view and then get the data.
        // j is in the range 0 to 16, and is the same in the view and the
        // model, since column rearranging is never done.

        int i = matrix_Table.convertRowIndexToView (id-1) ;
        return (matrix_Table.getValueAt (i, j)) ;
    }

    //--------------------------------------------------------------------------
    // set a value in the matrix table
    //--------------------------------------------------------------------------

    private void set_table_value (Object value, int id, int j)
    {
        // just like get_table_value, setting the data instead of getting it

        int i = matrix_Table.convertRowIndexToView (id-1) ;
        matrix_Table.setValueAt (value, i, j) ;
    }

    //--------------------------------------------------------------------------
    // get ids of highlighted matrices
    //--------------------------------------------------------------------------

    private int [ ] get_highlighted_ids ( )
    {
        // return a list of highlighted matrix id's

        // get the highlighted row indices in the current view
        int [ ] highlighted = matrix_Table.getSelectedRows ( ) ;
        // convert the row view indices to matrix id's
        for (int k = 0 ; k < highlighted.length ; k++)
        {
            int i = highlighted [k] ;
            int id = 1 + matrix_Table.convertRowIndexToModel (i) ;
            highlighted [k] = id ;
        }
        return (highlighted) ;
    }

    //--------------------------------------------------------------------------
    // get ids of matrices selected for download
    //--------------------------------------------------------------------------

    private int [ ] get_download_ids ( )
    {
        // get the list of ids to download, in view order
        nselected = 0 ;
        for (int i = 0 ; i < Stats.length ; i++)
        {
            if ((Boolean) matrix_Table.getValueAt (i, 0))
            {
                nselected++ ;
            }
        }
        int [ ] downloads = new int [nselected] ;
        int k = 0 ;
        for (int i = 0 ; i < Stats.length ; i++)
        {
            if ((Boolean) matrix_Table.getValueAt (i, 0))
            {
                int id = 1 + matrix_Table.convertRowIndexToModel (i) ;
                downloads [k++] = id ;
            }
        }
        return (downloads) ;
    }

    //--------------------------------------------------------------------------
    // set "Matrices selected:" label and download tool tip
    //--------------------------------------------------------------------------

    private void set_selected_label (boolean enabled)
    {
        if (gui_ready)
        {
            nselected_Label.setText
                ("   Matrices selected: " + nselected + "   ") ;
            download_Button.setEnabled (enabled) ;
            if (enabled)
            {
                if (nselected == 0)
                {
                    download_Button.setToolTipText
                        ("No matrices have been selected for download") ;
                }
                else if (nselected == 1)
                {
                    download_Button.setToolTipText
                        ("Click to download the single selected matrix") ;
                }
                else
                {
                    download_Button.setToolTipText
                        ("Click to download the " + nselected +
                        " selected matrices") ;
                }
            }
            else
            {
                download_Button.setToolTipText ("Download in progress.") ;
            }
        }
    }

    //--------------------------------------------------------------------------
    // show matrix icon
    //--------------------------------------------------------------------------

    private void show_highlighted_icon ( )
    {
        // show icon of last entry in the highlighted list
        int [ ] highlighted = get_highlighted_ids ( ) ;
        int n = highlighted.length ;
        if (n > 0)
        {
            int id = highlighted [n-1] ;
            String Group = (String) Stats [id-1][1] ;
            String Name  = (String) Stats [id-1][2] ;
            update_icon (Group + "/" + Name) ;
        }
    }

    //--------------------------------------------------------------------------
    // matrix table popup listener
    //--------------------------------------------------------------------------

    private class matrix_Table_PopupListener extends MouseAdapter
    {
        JPopupMenu pop ;

        matrix_Table_PopupListener (JPopupMenu popupMenu)
        {
            pop = popupMenu ;
        }

        public void mousePressed (MouseEvent e)
        {
            maybeShowPopup (e) ;
        }

        public void mouseReleased (MouseEvent e)
        {
            maybeShowPopup (e) ;
        }

        private void maybeShowPopup (MouseEvent e)
        {
            if (e.isPopupTrigger ( ))
            {
                pop.show (e.getComponent ( ), e.getX ( ), e.getY ( )) ;
            }
        }
    }

    //--------------------------------------------------------------------------
    // matrix table row listener
    //--------------------------------------------------------------------------

    private class matrix_Table_RowListener implements ListSelectionListener
    {
        public void valueChanged (ListSelectionEvent event)
        {
            if (event.getValueIsAdjusting ( ))
            {
                return ;
            }
            show_highlighted_icon ( ) ;
        }
    }

    //--------------------------------------------------------------------------
    // FindKinds:  determine the set of all Problem kinds
    //--------------------------------------------------------------------------

    private String [ ] FindKinds ( )
    {
        Set<String> KindSet = new TreeSet<String> ( ) ;
        KindSet.add (all_kinds) ;
        for (int id = 1 ; id <= Stats.length ; id++)
        {
            KindSet.add (SimplifyKind ((String) Stats [id-1][12])) ;
        }
        return ((String [ ]) KindSet.toArray (new String [0])) ;
    }

    //--------------------------------------------------------------------------
    // FindGroups:  determine the set of all groups
    //--------------------------------------------------------------------------

    private String [ ] FindGroups ( )
    {
        Set<String> GroupSet = new TreeSet<String> ( ) ;
        GroupSet.add (all_groups) ;
        for (int id = 1 ; id <= Stats.length ; id++)
        {
            GroupSet.add ((String) Stats [id-1][1]) ;
        }
        return ((String [ ]) GroupSet.toArray (new String [0])) ;
    }

    //--------------------------------------------------------------------------
    // SimplifyKind: remove extranneous terms from a string
    //--------------------------------------------------------------------------

    private String SimplifyKind (String kind)
    {
        // remove terms from a matrix-kind string
        String result = null ;
        String [ ] token = kind.split (" ") ;
        for (int i = 0 ; i < token.length ; i++)
        {
            if (! (token [i].equals ("subsequent")
                || token [i].equals ("sequence")
                || token [i].equals ("problem")
                || token [i].equals ("duplicate")))
            {
                if (result == null)
                {
                    result = token [i] ;
                }
                else
                {
                    result = result + " " + token [i] ;
                }
            }
        }
        return (result) ;
    }

    //--------------------------------------------------------------------------
    // CheckDir:  return a directory, creating it if it doesn't exist
    //--------------------------------------------------------------------------

    private File CheckDir (String directory_name)
    {
        File dir = new File (fix_name (directory_name)) ;
        if (!dir.isDirectory ( ))
        {
            dir.mkdirs ( ) ;
        }
        return (dir) ;
    }

    //--------------------------------------------------------------------------
    // CheckExistence: determine which files exist in the local file system
    //--------------------------------------------------------------------------

    private void CheckExistence ( )
    {
        // check the existence all matrices in all 3 formats
        fire_updates (false) ;
        for (int id = 1 ; id <= Stats.length ; id++)
        {
            CheckExistence (id) ;
        }
        fire_updates (true) ;
    }

    private boolean [ ] CheckExistence (int id)
    {
        // check the existence of a single file (in all 3 formats)
        boolean [ ] exists = new boolean [4] ;
        boolean [ ] etable = new boolean [3] ;

        String Group = (String) Stats [id-1][1] ;
        String Name  = (String) Stats [id-1][2] ;

        for (int j = 0 ; j < 3 ; j++)
        {
            etable [j] = (((String) get_table_value (id, j+1)).charAt (0) == 'x') ;
        }

        for (int j = 0 ; j < 4 ; j++)
        {
            exists [j] = false ;
        }

        // check for mat/HB/west0067.mat
        File G = new File (mat, Group) ;
        if (G.isDirectory ( ) && (new File (G, Name + ".mat")).exists ( ))
        {
            exists [0] = true ;
        }

        // check for MM/HB/west0067.tar.gz
        G = new File (MM, Group) ;
        if (G.isDirectory ( ) && (new File (G, Name + ".tar.gz")).exists ( ))
        {
            exists [1] = true ;
        }

        // check for MM/HB/west0067.tar.gz
        G = new File (RB, Group) ;
        if (G.isDirectory ( ) && (new File (G, Name + ".tar.gz")).exists ( ))
        {
            exists [2] = true ;
        }

        // check for files/HB/west0067.png
        G = new File (iconDir, Group) ;
        if (G.isDirectory ( ) && (new File (G, Name + ".png")).exists ( ))
        {
            exists [3] = true ;
        }

        // update the matrix table (mat, MM, and RB columns)
        for (int j = 0 ; j < 3 ; j++)
        {
            if (etable [j] != exists [j])
            {
                // only update the table if the existence status has changed
                set_table_value (exists [j] ? "x" : "-", id, j+1) ;
            }
        }
        return (exists) ;
    }

    //-------------------------------------------------------------------------
    // get long from JTextField
    //-------------------------------------------------------------------------

    private long getLong (JTextField tfield, long Default)
    {
        String s = tfield.getText ( ) ;
        long result = Default ;
        if (s.length ( ) > 0)
        {
            try
            {
                result = Long.parseLong (s) ;
            }
            catch (Exception e)
            {
            }
        }
        return (result) ;
    }

    //-------------------------------------------------------------------------
    // get double from JTextField
    //-------------------------------------------------------------------------

    private double getDouble (JTextField tfield, double Default)
    {
        String s = tfield.getText ( ) ;
        double result = Default ;
        if (s.length ( ) > 0)
        {
            try
            {
                result = Double.parseDouble (s) ;
            }
            catch (Exception e)
            {
            }
        }
        return (result) ;
    }

    //-------------------------------------------------------------------------
    // change to a wait cursor
    //-------------------------------------------------------------------------

    private void please_wait ( )
    {
        this.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR)) ;
    }

    //-------------------------------------------------------------------------
    // change to a normal cursor
    //-------------------------------------------------------------------------

    private void the_long_wait_is_over ( )
    {
        this.setCursor (Cursor.getDefaultCursor ( )) ;
    }

    //-------------------------------------------------------------------------
    // make or clear a selection
    //-------------------------------------------------------------------------

    private void make_selection (boolean action)
    {
        // set selections according to controls
        please_wait ( ) ;
        fire_updates (false) ;

        long minrow = getLong (minrow_Field, 0) ;
        long maxrow = getLong (maxrow_Field, INF) ;

        long mincol = getLong (mincol_Field, 0) ;
        long maxcol = getLong (maxcol_Field, INF) ;

        long minnentries = getLong (minnentries_Field, 0) ;
        long maxnentries = getLong (maxnentries_Field, INF) ;

        double minpsym = getDouble (minpsym_Field, 0) ;
        double maxpsym = getDouble (maxpsym_Field, 1.0) ;

        double minnsym = getDouble (minnsym_Field, 0) ;
        double maxnsym = getDouble (maxnsym_Field, 1.0) ;

        boolean shape_square = shape_square_Button.isSelected ( ) ;
        boolean shape_rect   = shape_rect_Button.isSelected ( ) ;
        boolean shape_either = shape_either_Button.isSelected ( ) ;

        boolean posdef_yes    = posdef_yes_Button.isSelected ( ) ;
        boolean posdef_no     = posdef_no_Button.isSelected ( ) ;
        boolean posdef_either = posdef_either_Button.isSelected ( ) ;

        boolean nd_yes    = nd_yes_Button.isSelected ( ) ;
        boolean nd_no     = nd_no_Button.isSelected ( ) ;
        boolean nd_either = nd_either_Button.isSelected ( ) ;

        boolean real_yes    = real_yes_Button.isSelected ( ) ;
        boolean real_no     = real_no_Button.isSelected ( ) ;
        boolean real_either = real_either_Button.isSelected ( ) ;

        // create HashSet for the selected groups
        Set<String> Gset = null ;
        Object [ ] Gsel = Group_List.getSelectedValuesList ( ).toArray ( ) ;
        int ngroups = Gsel.length ;
        if (ngroups > 0)
        {
            for (int i = 0 ; i < ngroups ; i++)
            {
                if (((String) Gsel [i]).equals (all_groups)) ngroups = 0 ;
            }
            Gset = new HashSet<String> ( ) ;
            for (int i = 0 ; i < ngroups ; i++)
            {
                Gset.add ((String) Gsel [i]) ;
                if (debug) System.out.println ("Group: " + (String) Gsel [i]) ;
            }
        }

        // create HashSet for the selected kinds
        Set<String> Kset = null ;
        Object [ ] Ksel = Kind_List.getSelectedValuesList ( ).toArray ( ) ;
        int nkinds = Ksel.length ;
        if (nkinds > 0)
        {
            for (int i = 0 ; i < nkinds ; i++)
            {
                if (((String) Ksel [i]).equals (all_kinds)) nkinds = 0 ;
            }
            Kset = new HashSet<String> ( ) ;
            for (int i = 0 ; i < nkinds ; i++)
            {
                Kset.add ((String) Ksel [i]) ;
                if (debug) System.out.println ("Kind: " + ((String) Ksel [i])) ;
            }
        }

        for (int id = 1 ; id <= Stats.length ; id++)
        {

            // look at the matrix properties to see if it fits the selection
            long nrows = (Long) Stats [id-1][3] ;
            long ncols = (Long) Stats [id-1][4] ;
            long nentries = (Long) Stats [id-1][5] ;

            int isReal   = (Integer) Stats [id-1][6] ;
            int isBinary = (Integer) Stats [id-1][7] ;
            int isND     = (Integer) Stats [id-1][8] ;
            int posdef   = (Integer) Stats [id-1][9] ;

            double psym = (Double) Stats [id-1][10] ;
            double nsym = (Double) Stats [id-1][11] ;

            boolean choose_group = true ;
            if (ngroups > 0)
            {
                String group = (String) Stats [id-1][1] ;
                choose_group = Gset.contains (group) ;
            }

            boolean choose_kind = true ;
            if (nkinds > 0)
            {
                String kind = SimplifyKind ((String) Stats [id-1][12]) ;
                choose_kind = Kset.contains (kind) ;
            }

            if ((minrow <= nrows && nrows <= maxrow) &&
                (mincol <= ncols && ncols <= maxcol) &&
                (minnentries <= nentries && nentries <= maxnentries) &&
                (minpsym <= psym && psym <= maxpsym) &&
                (minnsym <= nsym && nsym <= maxnsym) &&
                (posdef_either ||
                    (posdef_yes && posdef == 1) ||
                    (posdef_no && posdef == 0)) &&
                (nd_either ||
                    (nd_yes && isND == 1) ||
                    (nd_no && isND == 0)) &&
                (real_either ||
                    (real_yes && isReal == 1) ||
                    (real_no && isReal == 0)) &&
                (shape_either ||
                    (shape_square && nrows == ncols) ||
                    (shape_rect && nrows != ncols)) &&
                choose_group && choose_kind)
            {
                // change the selection box for this matrix id
                set_table_value (action, id, 0) ;
            }
        }
        fire_updates (true) ;
        progress1_Bar.setValue (0) ;
        progress2_Bar.setValue (0) ;
        the_long_wait_is_over ( ) ;
    }

    //-------------------------------------------------------------------------
    // reset button
    //-------------------------------------------------------------------------

    private void reset_Button_action (ActionEvent e)
    {
        // reset the selection criteria to the defaults
        minrow_Field.setText ("") ;
        maxrow_Field.setText ("") ;

        mincol_Field.setText ("") ;
        maxcol_Field.setText ("") ;

        minnentries_Field.setText ("") ;
        maxnentries_Field.setText ("") ;

        minpsym_Field.setText ("0.0") ;
        maxpsym_Field.setText ("1.0") ;

        minnsym_Field.setText ("0.0") ;
        maxnsym_Field.setText ("1.0") ;

        shape_either_Button.setSelected (true) ;
        posdef_either_Button.setSelected (true) ;
        nd_either_Button.setSelected (true) ;
        real_either_Button.setSelected (true) ;

        Group_List.clearSelection ( ) ;
        Kind_List.clearSelection ( ) ;

        progress1_Bar.setValue (0) ;
        progress2_Bar.setValue (0) ;
    }

    //-------------------------------------------------------------------------
    // clear button
    //-------------------------------------------------------------------------

    private void clear_Button_action (ActionEvent e)
    {
        // set selections according to controls
        please_wait ( ) ;
        fire_updates (false) ;

        for (int id = 1 ; id <= Stats.length ; id++)
        {
            // clear the selection box for this matrix id
            set_table_value (false, id, 0) ;
        }
        fire_updates (true) ;
        progress1_Bar.setValue (0) ;
        progress2_Bar.setValue (0) ;
        the_long_wait_is_over ( ) ;
    }

    //-------------------------------------------------------------------------
    // select popup menu item
    //-------------------------------------------------------------------------

    private void popup_action (ActionEvent e, boolean action)
    {
        // select or deselect the highlight matrices
        please_wait ( ) ;
        int [ ] highlighted = get_highlighted_ids ( ) ;
        int n = highlighted.length ;
        for (int k = 0 ; k < n ; k++)
        {
            set_table_value (action, highlighted [k], 0) ;
        }
        the_long_wait_is_over ( ) ;
    }

    //-------------------------------------------------------------------------
    // export popup menu item
    //-------------------------------------------------------------------------

    private void export_list_action (ActionEvent e, boolean csv)
    {
        // export the list in the order of the current view
        if (chooser.showSaveDialog (ssgui.this) == JFileChooser.APPROVE_OPTION)
        {
            please_wait ( ) ;
            print_out = null ;
            try
            {
                print_out = new PrintWriter (chooser.getSelectedFile ( )) ;
                int [ ] ids = get_download_ids ( ) ;
                int n = ids.length ;

                // print the header
                if (csv)
                {
                    print_out.println ("mat, MM, RB, id, Group, Name, rows, " +
                        "cols, entries, real, binary, 2D/3D, posdef, psym, " +
                        "nsym, kind") ;
                }
                else
                {
                    print_out.println ("%% Matrices selected from ssgui:") ;
                    print_out.println ("% Example usage:") ;
                    print_out.println ("% for k = 1:length(ids)") ;
                    print_out.println ("%    Problem = ssget (ids (k))") ;
                    print_out.println ("% end") ;
                    print_out.println ("ids = [")  ;
                }

                for (int k = 0 ; k < n ; k++)
                {
                    // get the matrix id and stats
                    int id = ids [k] ;
                    boolean [ ] exists = CheckExistence (id) ;
                    String Group       = (String)  Stats [id-1][1] ;
                    String Name        = (String)  Stats [id-1][2] ;
                    long nrows         = (Long)    Stats [id-1][3] ;
                    long ncols         = (Long)    Stats [id-1][4] ;
                    long nentries      = (Long)    Stats [id-1][5] ;
                    int isReal         = (Integer) Stats [id-1][6] ;
                    int isBinary       = (Integer) Stats [id-1][7] ;
                    int isND           = (Integer) Stats [id-1][8] ;
                    int posdef         = (Integer) Stats [id-1][9] ;
                    double psym        = (Double)  Stats [id-1][10] ;
                    double nsym        = (Double)  Stats [id-1][11] ;
                    String kind        = (String)  Stats [id-1][12] ;

                    if (csv)
                    {
                        // print the matrix stats in a single CSV line of text
                        print_out.println (
                            exists [0] + ", " + exists [1] + ", " +
                            exists [2] + ", " + id + ", " + Group + ", " +
                            Name + ", " + nrows + ", " + ncols + ", " +
                            nentries + ", " + isReal + ", " + isBinary + ", " +
                            isND + ", " + posdef + ", " + psym + ", " +
                            nsym + ", " + kind) ;
                    }
                    else
                    {
                        // print the matrix id, with a comment for the name
                        print_out.println (id + " % " + Group + "/" + Name) ;
                    }
                }
                if (!csv)
                {
                    print_out.println ("] ;")  ;
                }
            }
            catch (Exception err)
            {
                // display warning dialog
                JOptionPane.showMessageDialog (this, "Export failed.",
                    "Warning", JOptionPane.WARNING_MESSAGE) ;
            }
            finally
            {
                close_printer_stream (print_out) ;
            }
            the_long_wait_is_over ( ) ;
        }
    }

    //-------------------------------------------------------------------------
    // help button
    //-------------------------------------------------------------------------

    private void help_Button_action (ActionEvent e)
    {
        // create the Help window
        please_wait ( ) ;
        JFrame help_Frame = new JFrame ("Help: SuiteSparse Matrix Collection") ;

        // open the HTML help file and put it in an editor pane
        JEditorPane editorPane = new JEditorPane ( ) ;
        editorPane.setEditable (false) ;
        URL helpURL = ssgui.class.getResource ("sshelp.html") ;
        if (helpURL != null)
        {
            try
            {
                editorPane.setPage (helpURL) ;
            }
            catch (IOException error)
            {
                // display warning dialog
                JOptionPane.showMessageDialog (this,
                    "Sorry, Help document sshelp.html not found.",
                    "Warning", JOptionPane.WARNING_MESSAGE) ;
            }
        }

        // Put the editor pane in a scroll pane.
        JScrollPane editorScrollPane = new JScrollPane (editorPane) ;

        // Add the scroll pane to the Help window
        help_Frame.getContentPane ( ).add (editorScrollPane) ;
        help_Frame.setSize (800,600) ;
        help_Frame.setVisible (true) ;

        the_long_wait_is_over ( ) ;
    }

    //-------------------------------------------------------------------------
    // get the icon filename
    //-------------------------------------------------------------------------

    private String icon_file (String fullname)
    {
        return ("files/" + fullname + ".png") ;
    }

    //-------------------------------------------------------------------------
    // update the icon
    //-------------------------------------------------------------------------

    private void update_icon (String fullname)
    {
        // fullname is of the form Group/Name (HB/west0479, for example)
        icon_Label.setText (fullname) ;
        ImageIcon icon = new ImageIcon (fix_name (icon_file (fullname))) ;
        if (icon.getIconWidth ( ) < 0)
        {
            // icon image failed to load; get the image from the web
            icon = new ImageIcon (get_url (sssite +"/"+ icon_file (fullname))) ;
        }
        icon_Label.setIcon (icon) ;
    }

    //--------------------------------------------------------------------------
    // cancel button
    //--------------------------------------------------------------------------

    private void cancel_Button_action (ActionEvent e)
    {
        if (downloading && !cancel)
        {
            cancel = true ;
            cancel_Button.setEnabled (false) ;
            cancel_Button.setToolTipText ("canceling...") ;
        }
    }

    //-------------------------------------------------------------------------
    // get all icons
    //-------------------------------------------------------------------------

    private void get_all_icons ( )
    {
        // get all icons
        start_download_thread (0) ;
    }

    //-------------------------------------------------------------------------
    // download button
    //-------------------------------------------------------------------------

    private void download_Button_action (ActionEvent e)
    {
        // get the selected matrices
        start_download_thread (2) ;
    }

    //-------------------------------------------------------------------------
    // start the downloader thread
    //-------------------------------------------------------------------------

    private void start_download_thread (int what)
    {
        if (!downloading)
        {
            // only allow one active download at a time
            downloading = true ;
            cancel = false ;

            if (gui_ready)
            {
                cancel_Button.setEnabled (true) ;
                cancel_Button.setToolTipText
                    ("Click to cancel the current download.") ;
            }

            if (what == 0)
            {
                // get all the icons
                get_icons = true ;
                download_ids = null ;
            }
            else
            {
                // download one or more matrices
                get_icons = false ;
                download_ids = get_download_ids ( ) ;
            }
            set_selected_label (false) ;
            // start the downloader thread
            ssdownload tt = new ssdownload ( ) ;
        }
    }

    //--------------------------------------------------------------------------
    // downloader thread
    //--------------------------------------------------------------------------

    private class ssdownload implements Runnable
    {

        // constructor starts the downloader thread
        public ssdownload ( )
        {
            Thread thread = new Thread (this) ;
            thread.start ( ) ;
        }

        // thread.start calls the run method
        public void run ( )
        {

            if (get_icons)
            {
                // get all missing icons
                progress1_Bar.setValue (1) ;
                progress1_Bar.setMaximum (Stats.length) ;
                icon_Label.setBorder (BorderFactory.createTitledBorder
                    ("checking for new matrix icons")) ;
                for (int id = 1 ; !cancel && id <= Stats.length ; id++)
                {
                    boolean [ ] exists = CheckExistence (id) ;
                    if (!exists [3])
                    {
                        icon_Label.setBorder (BorderFactory.createTitledBorder
                            ("downloading new matrix icons")) ;
                        String Group = (String) Stats [id-1][1] ;
                        String Name  = (String) Stats [id-1][2] ;
                        String fullname = Group + "/" + Name ;
                        CheckDir ("files/" + Group) ;
                        download_file (icon_file (fullname)) ;
                        update_icon (fullname) ;
                    }
                    progress1_Bar.setValue (id+2) ;
                }
                progress1_Bar.setValue (Stats.length) ;
                icon_Label.setBorder (BorderFactory.createTitledBorder
                    ("matrix icon")) ;
            }

            if (download_ids != null && download_ids.length > 0)
            {
                // download all selected matrices in the requested formats

                // determine which formats to download
                int barmax = download_ids.length + 2 ;

                boolean format_mat = format_mat_Button.isSelected ( ) ;
                boolean format_mm  = format_mm_Button.isSelected ( ) ;
                boolean format_rb  = format_rb_Button.isSelected ( ) ;

                // start the overall progress bar
                progress1_Bar.setValue (1) ;
                progress1_Bar.setMaximum (barmax) ;

                // download all the files
                for (int k = 0 ; !cancel && k < download_ids.length ; k++)
                {
                    int id = download_ids [k] ;

                    // get matrxx
                    String Group = (String) Stats [id-1][1] ;
                    String Name  = (String) Stats [id-1][2] ;
                    String fullname = Group + "/" + Name ;

                    // recheck to see if the matrix exists in the 4 formats
                    boolean [ ] exists = CheckExistence (id) ;

                    if (!exists [3])
                    {
                        // always download the matrix icon if it doesn't exist
                        CheckDir ("files/" + Group) ;
                        download_file (icon_file (fullname)) ;
                        update_icon (fullname) ;
                    }

                    if (!exists [0] && format_mat)
                    {
                        // download the matrix in MATLAB format
                        update_icon (fullname) ;
                        CheckDir ("mat/" + Group) ;
                        download_file ("mat/" + fullname + ".mat") ;
                    }

                    if (!exists [1] && format_mm)
                    {
                        // download the matrix in Matrix Market format
                        update_icon (fullname) ;
                        CheckDir ("MM/" + Group) ;
                        download_file ("MM/" + fullname + ".tar.gz") ;
                    }

                    if (!exists [2] && format_rb)
                    {
                        // download the matrix in Rutherford/Boeing format
                        update_icon (fullname) ;
                        CheckDir ("RB/" + Group) ;
                        download_file ("RB/" + fullname + ".tar.gz") ;
                    }

                    progress1_Bar.setValue (k+2) ;
                }

                // update the mat/MM/RB check boxes
                for (int k = 0 ; k < download_ids.length ; k++)
                {
                    int id = download_ids [k] ;
                    CheckExistence (id) ;
                }

                // finish the overall progress bar
                progress1_Bar.setValue (barmax) ;
            }

            cancel_Button.setEnabled (false) ;
            cancel_Button.setToolTipText ("No downloads in progress.") ;

            set_selected_label (true) ;
            cancel = false ;
            downloading = false ;
        }
    }

    //--------------------------------------------------------------------------
    // get a URL
    //--------------------------------------------------------------------------

    private URL get_url (String urlstring)
    {
        try
        {
            return (new URL (urlstring)) ;
        }
        catch (MalformedURLException e)
        {
            // display warning dialog
            JOptionPane.showMessageDialog (this, "Invalid URL: "
                + urlstring, "Warning", JOptionPane.WARNING_MESSAGE) ;
            return (null) ;
        }
    }

    //--------------------------------------------------------------------------
    // download a file
    //--------------------------------------------------------------------------

    private void download_file (String filename)
    {
        boolean ok = true ;
        if (cancel) return ;
        String urlstring = sssite + "/" + filename ;
        if (debug) System.out.println ("downloading: " + urlstring) ;

        // create the URL
        URL url = get_url (urlstring) ;
        if (url == null) return ;

        // download the file
        url_in = null ;
        ftemp_out = null ;
        ftemp_name = filename + "_IN_PROGREss" ;
        int barmax = 1 ;

        try
        {
            // Follow redirects manually
            int max_redirects = 5;
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            for(int redirect_count = 0; redirect_count < max_redirects; redirect_count++)
            {
                int status = conn.getResponseCode();
                if (status >= 300 && status <= 308)
                {
                    // Redirecting
                    String loc = conn.getHeaderField("Location");
                    url = new URL(loc);
                    conn = (HttpURLConnection) url.openConnection();
                }
                else
                {
                    break;
                }
            }

            // determine the file size (fails for files > 2GB)
            int len = conn.getContentLength();

            // start the progress bar
            if (gui_ready)
            {
                if (len < 0)
                {
                    progress2_Bar.setIndeterminate (true) ;
                    progress_size_Label.setText ("") ;
                }
                else
                {
                    progress2_Bar.setValue (0) ;
                    // display the filesize to the right of the progress bar
                    if (len < M)
                    {
                        barmax = 1 + len / K ;
                        progress_size_Label.setText (((len+K/2) / K) + " KB") ;
                    }
                    else
                    {
                        barmax = 1 + len / M ;
                        progress_size_Label.setText (((len+M/2) / M) + " MB") ;
                    }
                }
                progress2_Bar.setMaximum (barmax) ;
            }

            // open the source and destination files
            //url_in = new BufferedInputStream (url.openStream ( )) ;
            url_in = new BufferedInputStream (conn.getInputStream()) ;
            ftemp_out = new BufferedOutputStream (new FileOutputStream
                (fix_name (ftemp_name)), buffersize) ;

            // transfer the data
            byte buffer [ ] = new byte [buffersize] ;
            long bytes_read = 0 ;
            int count = 0 ;
            while (!cancel && (count = url_in.read (buffer, 0, buffersize)) >= 0)
            {
                if (ftemp_out != null) ftemp_out.write (buffer, 0, count) ;
                bytes_read += count ;
                if (gui_ready && len > 0)
                {
                    if (len < M)
                    {
                        progress2_Bar.setValue ((int) (bytes_read / K)) ;
                    }
                    else
                    {
                        progress2_Bar.setValue ((int) (bytes_read / M)) ;
                    }
                }
            }
        }
        catch (Exception e)
        {
            if (debug)
            {
                System.out.println("Download failed: " + urlstring);
            }
            ok = false ;
        }

        if (gui_ready)
        {
            progress2_Bar.setIndeterminate (false) ;
            progress2_Bar.setValue (barmax) ;
            progress_size_Label.setText ("") ;
        }

        // wrap-up
        if (ok && !cancel)
        {
            // success:  rename the temp file to the permanent filename
            cleanup (false) ;
            File fsrc = new File (fix_name (ftemp_name)) ;
            File fdst = new File (fix_name (filename)) ;
            fsrc.renameTo (fdst) ;
        }
        else
        {
            // cancelled, or something failed:  delete the files if they exist
            cleanup (true) ;
        }
    }

    //--------------------------------------------------------------------------
    // download the latest matrix stats
    //--------------------------------------------------------------------------

    private Object [ ][ ] download_matrix_stats ( )
    {
        download_file (ssindex) ;       // download files/ss_index.mat
        download_file (ssstats) ;       // download files/ssstats.csv
        return (load_ssstats ( )) ;     // load the ssstats.csv file
    }

    //--------------------------------------------------------------------------
    // prepend the ss rchive directory and replace '/' with the file separator
    //--------------------------------------------------------------------------

    private static String fix_name (String s)
    {
        // file separator is '/' on Unix/Solaris/Linux/Mac, and '\' on Windows
        String r = ssarchive ;
        if (s != null)
        {
            r = r + s ;
        }
        return (r.replace ('/', File.separatorChar)) ;
    }

    //--------------------------------------------------------------------------
    // close an output stream
    //--------------------------------------------------------------------------

    private static void close_output (OutputStream out)
    {
        try
        {
            if (out != null) out.close ( ) ;
        }
        catch (IOException e)
        {
        }
    }

    //--------------------------------------------------------------------------
    // close an input stream
    //--------------------------------------------------------------------------

    private static void close_reader (Reader in)
    {
        try
        {
            if (in != null) in.close ( ) ;
        }
        catch (IOException e)
        {
        }
    }

    //--------------------------------------------------------------------------
    // close a printer stream
    //--------------------------------------------------------------------------

    private static void close_printer_stream (PrintWriter out)
    {
        if (out != null) out.close ( ) ;
    }

    //--------------------------------------------------------------------------
    // delete a file
    //--------------------------------------------------------------------------

    private static void delete_file (String filename)
    {
        if (filename != null)
        {
            File ff = new File (fix_name (filename)) ;
            if (ff.exists ( )) ff.delete ( ) ;
        }
    }

    //--------------------------------------------------------------------------
    // cleanup
    //--------------------------------------------------------------------------

    private static void cleanup (boolean delete)
    {
        // close input streams, if any
        try
        {
            if (url_in != null) url_in.close ( ) ;
        }
        catch (IOException e)
        {
        }
        url_in = null ;

        // close temporary file
        close_output (ftemp_out) ;
        ftemp_out = null ; 

        if (delete)
        {
            // delete temporary file
            delete_file (ftemp_name) ;
            ftemp_name = null ;
        }

        // close the printer stream, if any
        close_printer_stream (print_out) ;
        
        // close the reader stream, if any
        close_reader (in_reader) ;
    }

    //--------------------------------------------------------------------------
    // main method
    //--------------------------------------------------------------------------

    public static void main (String args [ ])
    {
        // register a shutdown hook
        Runtime.getRuntime ( ).addShutdownHook
        (
            new Thread ( )
            {
                public void run ( )
                {
                    // delete any temporary files when the ssgui shuts down,
                    // and close any files
                    cleanup (true) ;
                }
            }
        ) ;

        // start the GUI in its own thread
        EventQueue.invokeLater
        (
            new Runnable ( )
            {
                public void run ( )
                {
                    new ssgui ( ).setVisible (true) ;
                }
            }
        ) ;
    }
}