mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
17.26.2015 88f16d892d54fd8c3e190cc1f6363638b11ae1a3
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
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License, Version 1.0 only
 * (the "License").  You may not use this file except in compliance
 * with the License.
 *
 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
 * or http://forgerock.org/license/CDDLv1.0.html.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at legal-notices/CDDLv1_0.txt.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information:
 *      Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 *
 *
 *      Copyright 2006-2010 Sun Microsystems, Inc.
 *      Portions Copyright 2013-2015 ForgeRock AS.
 */
 
package org.opends.quicksetup.ui;
 
import org.forgerock.i18n.LocalizableMessage;
 
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.text.JTextComponent;
import javax.swing.text.html.HTMLEditorKit;
import java.awt.*;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.util.HashMap;
 
import org.forgerock.i18n.slf4j.LocalizedLogger;
 
import static org.opends.messages.QuickSetupMessages.*;
 
 
/**
 * This class provides constants an methods to create Swing objects and to
 * generate UI elements with a common look and feel.
 *
 * When we want to change a color, a background or a font this is the class
 * that should be modified.
 *
 */
public class UIFactory
{
  private static boolean initialized;
 
  private static String parentPackagePath;
 
  private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
 
  /**
   * Specifies the horizontal insets between buttons.
   */
  public static final int HORIZONTAL_INSET_BETWEEN_BUTTONS = 5;
 
  /**
   * Specifies the top inset for the steps.
   */
  public static final int TOP_INSET_STEP = 15;
 
  /**
   * Specifies the left inset for the steps.
   */
  public static final int LEFT_INSET_STEP = 5;
 
  /**
   * Specifies the extra left inset for the sub-steps.
   */
  public static final int LEFT_INSET_SUBSTEP = 20;
  /**
   * Specifies the top inset for the instructions sub panel.
   */
  public static final int TOP_INSET_INSTRUCTIONS_SUBPANEL = 5;
 
  /**
   * Specifies the top inset for input subpanel.
   */
  public static final int TOP_INSET_INPUT_SUBPANEL = 10;
 
  /**
   * Specifies the top inset for a primary field.
   */
  public static final int TOP_INSET_PRIMARY_FIELD = 10;
 
  /**
   * Specifies the top inset for a secondary field.
   */
  public static final int TOP_INSET_SECONDARY_FIELD = 5;
 
  /**
   * Specifies the top inset for a radio button.
   */
  public static final int TOP_INSET_RADIOBUTTON = 0;
 
  /**
   * Specifies the top inset for a radio button subordinate panel.
   */
  public static final int TOP_INSET_RADIO_SUBORDINATE = 0;
 
  /**
   * Specifies the top inset for the progress bar.
   */
  public static final int TOP_INSET_PROGRESS_BAR = 5;
 
  /**
   * Specifies the top inset for the progress text area.
   */
  public static final int TOP_INSET_PROGRESS_TEXTAREA = 4;
 
  /**
   * Specifies the top inset for the background image.
   */
  public static final int TOP_INSET_BACKGROUND = 70;
 
  /**
   * Specifies the top inset for the error message.
   */
  public static final int TOP_INSET_ERROR_MESSAGE = 10;
 
  /**
   * Specifies the top inset for the browse button.
   */
  public static final int TOP_INSET_BROWSE = 5;
 
  /**
   * Specifies the right inset for background image.
   */
  public static final int RIGHT_INSET_BACKGROUND = 20;
 
  /**
   * Specifies the left inset for the primary field.
   */
  public static final int LEFT_INSET_PRIMARY_FIELD = 10;
 
  /**
   * Specifies the left inset for the browse button.
   */
  public static final int LEFT_INSET_BROWSE = 10;
 
  /**
   * Specifies the left inset for radio subordinate panel.
   */
  public static final int LEFT_INSET_RADIO_SUBORDINATE = 35;
 
  /**
   * Specifies the left inset for the secondary field.
   */
  public static final int LEFT_INSET_SECONDARY_FIELD = 5;
 
  /**
   * Specifies the left inset for the background image.
   */
  public static final int LEFT_INSET_BACKGROUND = 20;
 
  /**
   * Specifies the left inset for the copy url button.
   */
  public static final int LEFT_INSET_COPY_BUTTON = 10;
 
  /**
   * Specifies the left inset for a subordinate subpanel.
   */
  public static final int LEFT_INSET_SUBPANEL_SUBORDINATE = 30;
 
  /**
   * Specifies the left inset for the progress bar.
   */
  public static final int BOTTOM_INSET_PROGRESS_BAR = 10;
 
  /**
   * Specifies the bottom inset for the background image.
   */
  public static final int BOTTOM_INSET_BACKGROUND = 30;
 
  /**
   * Specifies the top inset for a secondary field.
   */
  public static final int BOTTOM_INSET_SECONDARY_FIELD = 5;
 
  /**
   * Specifies the number of columns of a text field for a path.
   */
  public static final int PATH_FIELD_SIZE = 20;
 
  /**
   * Specifies the number of columns of a text field for a relative path.
   */
  public static final int RELATIVE_PATH_FIELD_SIZE = 10;
 
  /**
   * Specifies the number of columns of a text field for a host name.
   */
  public static final int HOST_FIELD_SIZE = 20;
 
  /**
   * Specifies the number of columns of a text field for a UID.
   */
  public static final int UID_FIELD_SIZE = 15;
 
  /**
   * Specifies the number of columns of a text field for a port.
   */
  public static final int PORT_FIELD_SIZE = 5;
 
  /**
   * Specifies the number of columns of a text field for a dn.
   */
  public static final int DN_FIELD_SIZE = 20;
 
  /**
   * Specifies the number of columns of a text field for a password.
   */
  public static final int PASSWORD_FIELD_SIZE = 15;
 
  /**
   * Specifies the number of columns of a text field for the number of entries.
   */
  public static final int NUMBER_ENTRIES_FIELD_SIZE = 7;
 
  /**
   * Specifies the number of points for the width of the progress bar.
   */
  public static final int PROGRESS_BAR_SIZE = 220;
 
  /**
   * Specifies the number of extra points that we add to the minimum size of
   * the dialog.
   */
  public static final int EXTRA_DIALOG_HEIGHT = 75;
 
  private static final Insets BUTTONS_PANEL_INSETS = new Insets(5, 0, 5, 10);
 
  private static final Insets STEPS_PANEL_INSETS = new Insets(15, 10, 5, 10);
 
  private static final Insets CURRENT_STEP_PANEL_INSETS =
      new Insets(15, 15, 15, 15);
 
  private static final Insets EMPTY_INSETS = new Insets(0, 0, 0, 0);
 
  /**
   * Specifies the default background color.
   */
  public static final Color DEFAULT_BACKGROUND =
          getColor(INFO_DEFAULT_BACKGROUND_COLOR.get());
 
  /**
   * Specifies the current step background color.
   */
  public static final Color CURRENT_STEP_PANEL_BACKGROUND =
          getColor(INFO_CURRENT_STEP_PANEL_BACKGROUND_COLOR.get());
 
  /**
   * Specifies the default label color.
   */
  public static final Color DEFAULT_LABEL_COLOR =
          getColor(INFO_DEFAULT_LABEL_COLOR.get());
 
  /**
   * Specifies the valid field color.
   */
  public static final Color FIELD_VALID_COLOR =
          getColor(INFO_FIELD_VALID_COLOR.get());
 
  /**
   * Specifies the invalid field color.
   */
  public static final Color FIELD_INVALID_COLOR =
          getColor(INFO_FIELD_INVALID_COLOR.get());
 
  /**
   * Specifies the read only text color.
   */
  public static final Color READ_ONLY_COLOR =
          getColor(INFO_READ_ONLY_COLOR.get());
 
  /**
   * Specifies the check box text color.
   */
  public static final Color CHECKBOX_COLOR =
          getColor(INFO_CHECKBOX_COLOR.get());
 
  /**
   * Specifies the progress text color.
   */
  public static final Color PROGRESS_COLOR =
          getColor(INFO_PROGRESS_COLOR.get());
 
  /**
   * Specifies the instructions text color.
   */
  public static final Color INSTRUCTIONS_COLOR =
          getColor(INFO_INSTRUCTIONS_COLOR.get());
 
  /**
   * Specifies the text field text color.
   */
  public static final Color TEXTFIELD_COLOR =
          getColor(INFO_TEXTFIELD_COLOR.get());
 
  /**
   * Specifies the password field text color.
   */
  public static final Color PASSWORDFIELD_COLOR =
          getColor(INFO_PASSWORDFIELD_COLOR.get());
 
  /**
   * Specifies the in-line help text color.
   */
  public static final Color INLINE_HELP_COLOR =
          getColor(INFO_INLINE_HELP_COLOR.get());
 
  /**
   * Specifies the panel border color.
   */
  public static final Color PANEL_BORDER_COLOR =
          getColor(INFO_PANEL_BORDER_COLOR.get());
 
  /**
   * Specifies the current step panel border.
   */
  public static final Border CURRENT_STEP_PANEL_BORDER =
          BorderFactory.createMatteBorder(0, 2, 2, 0, PANEL_BORDER_COLOR);
 
  /**
   * Specifies the text area border.
   */
  public static final Border TEXT_AREA_BORDER =
          BorderFactory.createMatteBorder(1, 1, 1, 1,
                  getColor(INFO_TEXT_AREA_BORDER_COLOR.get()));
 
  /**
   * Specifies the dialog border.
   */
  public static final Border DIALOG_PANEL_BORDER =
    BorderFactory.createMatteBorder(0, 0, 2, 0, PANEL_BORDER_COLOR);
 
  private static Font defaultFont;
  static
  {
    try
    {
      defaultFont = UIManager.getFont("Label.font").deriveFont(Font.PLAIN).
      deriveFont(12f);
    }
    catch (Throwable t)
    {
      defaultFont = Font.decode("SansSerif-PLAIN-12");
    }
  }
 
 
  /**
   * Specifies the font for the step which is not the current one in the steps
   * panel.
   */
  public static final Font NOT_CURRENT_STEP_FONT = defaultFont.deriveFont(14f);
 
  /**
   * Specifies the font for the step which is the current one in the steps
   * panel.
   */
  public static final Font CURRENT_STEP_FONT =
    defaultFont.deriveFont(14f).deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the title of the current panel.
   */
  public static final Font TITLE_FONT =
    defaultFont.deriveFont(14f).deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the instructions of the current panel.
   */
  public static final Font INSTRUCTIONS_FONT = defaultFont;
 
  /**
   * Specifies the font for the instructions of the current panel.
   */
  public static final Font INSTRUCTIONS_MONOSPACE_FONT =
    Font.decode("Monospaced-PLAIN-14");
 
  /**
   * Specifies the font for the primary valid field.
   */
  public static final Font PRIMARY_FIELD_VALID_FONT =
    defaultFont.deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the secondary valid field.
   */
  public static final Font SECONDARY_FIELD_VALID_FONT = defaultFont;
 
  /**
   * Specifies the font for the primary invalid field.
   */
  public static final Font PRIMARY_FIELD_INVALID_FONT =
    defaultFont.deriveFont(Font.BOLD | Font.ITALIC);
 
  /**
   * Specifies the font for the secondary invalid field.
   */
  public static final Font SECONDARY_FIELD_INVALID_FONT =
    defaultFont.deriveFont(Font.ITALIC);
 
  /**
   * Specifies the font for the secondary status field.
   */
  public static final Font SECONDARY_STATUS_FONT =
    defaultFont.deriveFont(Font.ITALIC);
 
  /**
   * Specifies the font for read only text.
   */
  public static final Font READ_ONLY_FONT = defaultFont;
 
  /**
   * Specifies the font for the check box text.
   */
  public static final Font CHECKBOX_FONT = defaultFont;
 
  /**
   * Specifies the font for the progress text.
   */
  public static final Font PROGRESS_FONT = defaultFont;
 
  /**
   * Specifies the font for the text field text.
   */
  public static final Font TEXTFIELD_FONT = defaultFont;
 
  /**
   * Specifies the font for the password field text.
   */
  public static final Font PASSWORD_FIELD_FONT = defaultFont;
 
  /**
   * Specifies the font for the points '....' in the progress panel.
   */
  public static final Font PROGRESS_POINTS_FONT =
    defaultFont.deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the done text 'Done' in the progress panel.
   */
  public static final Font PROGRESS_DONE_FONT = PROGRESS_POINTS_FONT;
 
  /**
   * Specifies the font for the log messages in the progress panel.
   */
  public static final Font PROGRESS_LOG_FONT =
      Font.decode("Monospaced-PLAIN-12");
 
  /**
   * Specifies the font for the error log messages in the progress panel.
   */
  public static final Font PROGRESS_LOG_ERROR_FONT =
      Font.decode("Monospaced-PLAIN-12");
 
  /**
   * Specifies the font for the error messages in the progress panel.
   */
  public static final Font PROGRESS_ERROR_FONT =
    defaultFont.deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the warning messages in the progress panel.
   */
  public static final Font PROGRESS_WARNING_FONT =
    defaultFont.deriveFont(Font.BOLD);
 
  /**
   * Specifies the font for the stack trace in the progress panel.
   */
  public static final Font STACK_FONT = defaultFont;
 
  /**
   * Specifies the font for the text in the WebBrowserErrorDialog.
   */
  public static final Font ERROR_DIALOG_FONT = defaultFont;
 
  /**
   * Specifies the font for the text in the in-line help.
   */
  public static final Font INLINE_HELP_FONT = defaultFont.deriveFont(
      (float)(defaultFont.getSize() - 2));
 
  private static final String SPAN_CLOSE = "</span>";
 
  private static final String DIV_CLOSE = "</div>";
 
  private static final String DIV_OPEN_ERROR_BACKGROUND =
    "<div style=\"color:#"+
    INFO_DIV_OPEN_ERROR_BACKGROUND_1_COLOR.get()+
    ";background-color:#"+
    INFO_DIV_OPEN_ERROR_BACKGROUND_2_COLOR.get()+
    ";padding:10px 10px 10px 10px;"+
    "border-style:solid;border-width:3px;border-color:#"+
    INFO_DIV_OPEN_ERROR_BACKGROUND_3_COLOR.get()+
    ";vertical-align:middle;text-align:left\">";
 
  private static final String DIV_OPEN_WARNING_BACKGROUND =
      DIV_OPEN_ERROR_BACKGROUND;
 
  private static final String DIV_OPEN_SUCCESSFUL_BACKGROUND =
    "<div style=\"color:#"+
    INFO_DIV_OPEN_SUCCESSFUL_BACKGROUND_1_COLOR.get()+
    ";background-color:#"+
    INFO_DIV_OPEN_SUCCESSFUL_BACKGROUND_2_COLOR.get()+
    ";padding:10px 10px 10px 10px;"+
    "border-style:solid;border-width:3px;border-color:#"+
    INFO_DIV_OPEN_SUCCESSFUL_BACKGROUND_3_COLOR.get()+
    ";vertical-align:middle;text-align:left\">";
 
  /**
   * An HTML separator text that can be used in the progress panel.
   */
  public static final String HTML_SEPARATOR =
    "<div style=\"font-size:1px;background-color:#"+
    INFO_HTML_SEPARATOR_COLOR.get()+
    ";margin:10px 5px 10px 5px;\"></div>";
 
  private static final HashMap<IconType, ImageIcon> hmIcons =
      new HashMap<IconType, ImageIcon>();
 
  /**
   * The following enumeration contains the different icons that we can have.
   *
   */
  public enum IconType
  {
    /**
     * Splash Icon.
     */
    SPLASH,
    /**
     * Current Step Icon.
     */
    CURRENT_STEP,
    /**
     * The icon displayed by the OS when the dialog is minimized.
     */
    MINIMIZED,
    /**
     * The icon displayed by the Mac OS when the dialog is minimized.
     */
    MINIMIZED_MAC,
    /**
     * The background icon.
     */
    BACKGROUND,
    /**
     * The warning icon.
     */
    WARNING,
    /**
     * The warning large icon.
     */
    WARNING_LARGE,
    /**
     * The error icon.
     */
    ERROR,
    /**
     * The error large icon.
     */
    ERROR_LARGE,
    /**
     * The information icon.
     */
    INFORMATION,
    /**
     * The information large icon.
     */
    INFORMATION_LARGE,
    /**
     * Icon to create subsection title in Status Panel.
     */
    SUBSECTION_LEFT,
    /**
     * Icon to create subsection title in Status Panel.
     */
    SUBSECTION_RIGHT,
    /**
     * Question icon.
     */
    HELP_SMALL,
 
    /**
     * Hourglass to display when the user must wait.
     */
    WAIT,
 
    /**
     * 8 x 8 Hourglass to display when the user must wait.
     */
    WAIT_TINY,
 
    /**
     * No icon.
     */
    NO_ICON
  }
 
  /**
   * The following enumeration contains the different text styles that we can
   * have.  A text style basically specifies the font and color to be used to
   * render the text.
   *
   */
  public enum TextStyle
  {
    /**
     * Current Step label style for the steps panel.
     */
    CURRENT_STEP,
    /**
     * Not current Step label style for the steps panel.
     */
    NOT_CURRENT_STEP,
    /**
     * Title label style for the current step panel.
     */
    TITLE,
    /**
     * Primary field valid label style for the current step panel.
     */
    PRIMARY_FIELD_VALID,
    /**
     * Primary field invalid text style for the current step panel.
     */
    PRIMARY_FIELD_INVALID,
    /**
     * Secondary field valid text style for the current step panel.
     */
    SECONDARY_FIELD_VALID,
    /**
     * Secondary field invalid text style for the current step panel.
     */
    SECONDARY_FIELD_INVALID,
 
    /**
     * Status messages that appear near components.
     */
    SECONDARY_STATUS,
 
    /**
     * Textfield text style for the current step panel.
     */
    TEXTFIELD,
    /**
     * Password text style for the current step panel.
     */
    PASSWORD_FIELD,
 
    /**
     * Read only text style for the current step panel.
     */
    READ_ONLY,
    /**
     * Check box text text style for the current step panel.
     */
    CHECKBOX,
    /**
     * Progress messages text style for the current step panel.
     */
    PROGRESS,
    /**
     * Text style for the instructions.
     */
    INSTRUCTIONS,
    /**
     * In-line help style.
     */
    INLINE_HELP,
    /**
     * No text style.
     */
    NO_STYLE
  }
 
  /**
   * This method initialize the look and feel.
   * @throws Throwable if there is a problem initializing the look and feel.
   */
  public static void initializeLookAndFeel() throws Throwable
  {
    final Throwable[] ts = {null};
    Runnable r = new Runnable()
    {
      public void run()
      {
        System.setProperty("swing.aatext", "true");
        try
        {
          String lf = UIManager.getSystemLookAndFeelClassName();
          if (lf.equalsIgnoreCase(
              "com.sun.java.swing.plaf.motif.MotifLookAndFeel"))
          {
            lf = UIManager.getCrossPlatformLookAndFeelClassName();
          }
          UIManager.setLookAndFeel(lf);
        } catch (Throwable t)
        {
          ts[0] = t;
        }
        JFrame.setDefaultLookAndFeelDecorated(false);
      }
    };
    if (SwingUtilities.isEventDispatchThread())
    {
      r.run();
    }
    else
    {
      try
      {
        SwingUtilities.invokeAndWait(r);
      }
      catch (Throwable t)
      {
        ts[0] = t;
      }
    }
    if (ts[0] != null)
    {
      throw ts[0];
    }
  }
 
  /**
   * This method initialize the look and feel and UI settings specific to
   * quick setup.
   * @throws Throwable if there is a problem initializing the look and feel.
   */
  public static void initialize() throws Throwable
  {
    if (!initialized)
    {
      try
      {
        UIManager.put("OptionPane.background",
            getColor(INFO_OPTIONPANE_BACKGROUND_COLOR.get()));
        UIManager.put("Panel.background",
            getColor(INFO_PANEL_BACKGROUND_COLOR.get()));
        UIManager.put("ComboBox.background",
            getColor(INFO_COMBOBOX_BACKGROUND_COLOR.get()));
      }
      catch (Throwable t)
      {
        // This might occur when we do not get the display
        logger.warn(LocalizableMessage.raw("Error updating UIManager: "+t, t));
      }
      initializeLookAndFeel();
      initialized = true;
    }
  }
 
  /**
   * Creates a new JPanel.
   * @return JPanel newly created
   */
  public static JPanel makeJPanel() {
    JPanel pnl = new JPanel();
    pnl.setOpaque(false);
    return pnl;
  }
 
  /**
   * Creates a JButton with the given label and tooltip.
   * @param label the text of the button.
   * @param tooltip the tooltip of the button.
   * @return a JButton with the given label and tooltip.
   */
  public static JButton makeJButton(LocalizableMessage label, LocalizableMessage tooltip)
  {
    JButton b = new JButton();
 
    if (label != null)
    {
      b.setText(label.toString());
    }
 
    if (tooltip != null)
    {
      b.setToolTipText(tooltip.toString());
    }
 
    b.setOpaque(false);
 
    return b;
  }
 
  /**
   * Commodity method that returns a JLabel based on a LabelFieldDescriptor.
   * @param desc the LabelFieldDescriptor describing the JLabel.
   * @return a JLabel based on a LabelFieldDescriptor.
   */
  static public JLabel makeJLabel(LabelFieldDescriptor desc)
  {
    UIFactory.TextStyle style;
    if (desc.getLabelType() == LabelFieldDescriptor.LabelType.PRIMARY)
    {
      style = UIFactory.TextStyle.PRIMARY_FIELD_VALID;
    } else
    {
      style = UIFactory.TextStyle.SECONDARY_FIELD_VALID;
    }
    return makeJLabel(UIFactory.IconType.NO_ICON, desc.getLabel(), style);
  }
 
  /**
   * Creates a JLabel with the given icon, text and text style.
   * @param iconName the icon.
   * @param text the label text.
   * @param style the text style.
   * @return a JLabel with the given icon, text and text style.
   */
  public static JLabel makeJLabel(IconType iconName, LocalizableMessage text,
      TextStyle style)
  {
    JLabel l = new JLabel();
 
    if (text != null)
    {
      l.setText(text.toString());
    }
 
    ImageIcon icon = getImageIcon(iconName);
    l.setIcon(icon);
    LocalizableMessage tooltip = getIconTooltip(iconName);
 
    if (tooltip != null)
    {
      l.setToolTipText(tooltip.toString());
    }
 
    setTextStyle(l, style);
    return l;
  }
 
  /**
   * Commodity method that returns a JTextComponent based on a
   * LabelFieldDescriptor.
   * @param desc the LabelFieldDescriptor describing the JTextField.
   * @param defaultValue the default value used to initialize the
   * JTextComponent.
   * @return a JTextComponent based on a
   * LabelFieldDescriptor.
   */
  static public JTextComponent makeJTextComponent(LabelFieldDescriptor desc,
      String defaultValue)
  {
    if (defaultValue == null)
    {
      defaultValue = "";
    }
    JTextComponent field;
    switch (desc.getType())
    {
    case TEXTFIELD:
 
      field =
          makeJTextField(LocalizableMessage.raw(defaultValue), desc.getTooltip(), desc
              .getSize(), TextStyle.TEXTFIELD);
      break;
 
    case PASSWORD:
 
      field =
          makeJPasswordField(LocalizableMessage.raw(defaultValue), desc.getTooltip(), desc
              .getSize(), TextStyle.PASSWORD_FIELD);
      break;
 
    case READ_ONLY:
 
      field =
          makeTextPane(LocalizableMessage.raw(defaultValue), TextStyle.READ_ONLY);
      break;
 
    default:
      throw new IllegalArgumentException("Unknown type: " + desc.getType());
    }
    return field;
  }
 
  /**
   * Creates a JTextField with the given icon, tooltip text, size and text
   * style.
   * @param text the text.
   * @param tooltip the tooltip text.
   * @param size the number of columns of the JTextField.
   * @param style the text style.
   * @return a JTextField with the given icon, tooltip text, size and text
   * style.
   */
  public static JTextField makeJTextField(LocalizableMessage text, LocalizableMessage tooltip,
      int size, TextStyle style)
  {
    JTextField f = new JTextField();
    updateTextFieldComponent(f, text, tooltip, size, style);
    f.addFocusListener(new TextFieldFocusListener(f));
    return f;
  }
 
  /**
   * Creates a JPasswordField with the given icon, tooltip text, size and text
   * style.
   * @param text the text.
   * @param tooltip the tooltip text.
   * @param size the number of columns of the JPasswordField.
   * @param style the text style.
   * @return a JPasswordField with the given icon, tooltip text, size and text
   * style.
   */
  public static JPasswordField makeJPasswordField(LocalizableMessage text, LocalizableMessage tooltip,
      int size, TextStyle style)
  {
    JPasswordField f = new JPasswordField();
    updateTextFieldComponent(f, text, tooltip, size, style);
    f.addFocusListener(new TextFieldFocusListener(f));
    return f;
  }
 
  /**
   * Creates a JRadioButton with the given text, tooltip text and text
   * style.
   * @param text the text of the radio button.
   * @param tooltip the tooltip text.
   * @param style the text style.
   * @return a JRadioButton with the given text, tooltip text and text
   * style.
   */
  public static JRadioButton makeJRadioButton(LocalizableMessage text, LocalizableMessage tooltip,
      TextStyle style)
  {
    JRadioButton rb = new JRadioButton();
    rb.setOpaque(false);
    if (text != null)
    {
      rb.setText(text.toString());
    }
 
    if (tooltip != null)
    {
      rb.setToolTipText(tooltip.toString());
    }
 
    setTextStyle(rb, style);
    return rb;
  }
 
  /**
   * Creates a JCheckBox with the given text, tooltip text and text
   * style.
   * @param text the text of the radio button.
   * @param tooltip the tooltip text.
   * @param style the text style.
   * @return a JCheckBox with the given text, tooltip text and text
   * style.
   */
  public static JCheckBox makeJCheckBox(LocalizableMessage text, LocalizableMessage tooltip,
      TextStyle style)
  {
    JCheckBox cb = new JCheckBox();
    cb.setOpaque(false);
    if (text != null)
    {
      cb.setText(text.toString());
    }
 
    if (tooltip != null)
    {
      cb.setToolTipText(tooltip.toString());
    }
 
    setTextStyle(cb, style);
    return cb;
  }
 
  /**
   * Creates a JList.
   *
   * @param textStyle the style to be used for the renderer.
   * @return a JList.
   */
  public static JList makeJList(TextStyle textStyle)
  {
    JList list = new JList();
    list.setCellRenderer(makeCellRenderer(textStyle));
    return list;
  }
 
  /**
   * Sets the specified text style to the component passed as parameter.
   * @param l the component to update.
   * @param style the text style to use.
   */
  public static void setTextStyle(JComponent l, TextStyle style)
  {
    switch (style)
    {
    case NOT_CURRENT_STEP:
      l.setFont(UIFactory.NOT_CURRENT_STEP_FONT);
      l.setForeground(DEFAULT_LABEL_COLOR);
      break;
 
    case CURRENT_STEP:
      l.setFont(UIFactory.CURRENT_STEP_FONT);
      l.setForeground(DEFAULT_LABEL_COLOR);
      break;
 
    case TITLE:
      l.setFont(UIFactory.TITLE_FONT);
      l.setForeground(DEFAULT_LABEL_COLOR);
      break;
 
    case PRIMARY_FIELD_VALID:
      l.setFont(UIFactory.PRIMARY_FIELD_VALID_FONT);
      l.setForeground(FIELD_VALID_COLOR);
      break;
 
    case PRIMARY_FIELD_INVALID:
      l.setFont(UIFactory.PRIMARY_FIELD_INVALID_FONT);
      l.setForeground(FIELD_INVALID_COLOR);
      break;
 
    case SECONDARY_FIELD_VALID:
      l.setFont(UIFactory.SECONDARY_FIELD_VALID_FONT);
      l.setForeground(FIELD_VALID_COLOR);
      break;
 
    case SECONDARY_FIELD_INVALID:
      l.setFont(UIFactory.SECONDARY_FIELD_INVALID_FONT);
      l.setForeground(FIELD_INVALID_COLOR);
      break;
 
    case SECONDARY_STATUS:
      l.setFont(UIFactory.SECONDARY_STATUS_FONT);
      l.setForeground(FIELD_VALID_COLOR);
      break;
 
    case READ_ONLY:
      l.setFont(UIFactory.READ_ONLY_FONT);
      l.setForeground(READ_ONLY_COLOR);
      break;
 
    case CHECKBOX:
      l.setFont(UIFactory.CHECKBOX_FONT);
      l.setForeground(CHECKBOX_COLOR);
      break;
 
    case PROGRESS:
      l.setFont(UIFactory.PROGRESS_FONT);
      l.setForeground(PROGRESS_COLOR);
      break;
 
    case INSTRUCTIONS:
      l.setFont(INSTRUCTIONS_FONT);
      l.setForeground(INSTRUCTIONS_COLOR);
      break;
 
    case TEXTFIELD:
      l.setFont(UIFactory.TEXTFIELD_FONT);
      l.setForeground(TEXTFIELD_COLOR);
      break;
 
    case PASSWORD_FIELD:
      l.setFont(UIFactory.PASSWORD_FIELD_FONT);
      l.setForeground(PASSWORDFIELD_COLOR);
      break;
 
    case INLINE_HELP:
      l.setFont(INLINE_HELP_FONT);
      l.setForeground(INLINE_HELP_COLOR);
      break;
 
    case NO_STYLE:
      // Do nothing
      break;
 
    default:
      throw new IllegalArgumentException("Unknown textStyle: " + style);
    }
  }
 
  /**
   * Returns the HTML string representing the provided IconType.
   * @param iconType the IconType for which we want the HTML representation.
   * @return the HTML string representing the provided IconType.
   */
  public static String getIconHtml(IconType iconType)
  {
    String url =
        String.valueOf(UIFactory.class.getClassLoader().getResource(
            getIconPath(iconType)));
    LocalizableMessage description = getIconDescription(iconType);
    LocalizableMessage title = getIconTooltip(iconType);
    return "<img src=\"" + url + "\" alt=\"" + description +
    "\" align=\"middle\" title=\"" + title + "\" >";
  }
 
  /**
   * Returns an ImageIcon object for the provided IconType.
   * @param iconType the IconType for which we want to obtain the ImageIcon.
   * @return the ImageIcon.
   */
  public static ImageIcon getImageIcon(IconType iconType)
  {
    if (iconType == null) {
      iconType = IconType.NO_ICON;
    }
    ImageIcon icon = hmIcons.get(iconType);
    if ((icon == null) && (iconType != IconType.NO_ICON))
    {
      String path = getIconPath(iconType);
      LocalizableMessage description = getIconDescription(iconType);
      try
      {
        Image im =
            Toolkit.getDefaultToolkit().createImage(
                UIFactory.class.getClassLoader().getResource(path));
        icon = new ImageIcon(im);
        String ds = description != null ? description.toString() : null;
        icon.setDescription(ds);
 
        hmIcons.put(iconType, icon);
 
      } catch (Exception ex)
      {
        ex.printStackTrace(); // A bug: this should not happen
        throw new IllegalStateException("Could not load icon for path " + path,
            ex);
      }
    }
 
    return icon;
  }
 
  /**
   * Returns a JEditorPane that works with the provided scroll.
   * @see ProgressJEditorPane
   * @param scroll the scroll that will contain the JEditorPane.
   * @return a JEditorPane that works with the provided scroll.
   */
  public static JEditorPane makeProgressPane(JScrollPane scroll)
  {
    return new ProgressJEditorPane(scroll);
  }
 
  /**
   * Returns a read only JEditorPane containing the provided text with the
   * provided font.  The JEditorPane will assume that the text is HTML text.
   * @param text the text to be used to initialize the JEditorPane contents.
   * @param font the font to be used.
   * @return a read only JEditorPane containing the provided text with the
   * provided font.
   */
  public static JEditorPane makeHtmlPane(LocalizableMessage text, Font font)
  {
    return makeHtmlPane(text, null, font);
  }
 
  /**
   * Returns a read only JEditorPane containing the provided text with the
   * provided font.  The JEditorPane will assume that the text is HTML text.
   * @param text the text to be used to initialize the JEditorPane contents.
   * @param ek HTMLEditor kit used for the new HTML pane
   * @param font the font to be used.
   * @return a read only JEditorPane containing the provided text with the
   * provided font.
   */
  public static JEditorPane makeHtmlPane(LocalizableMessage text, HTMLEditorKit ek,
                                         Font font)
  {
    JEditorPane pane = new JEditorPane();
    if (ek != null) pane.setEditorKit(ek);
    pane.setContentType("text/html");
    String s = text != null ? String.valueOf(text) : null;
    pane.setText(applyFontToHtmlWithDiv(s, font));
    pane.setEditable(false);
    pane.setBorder(new EmptyBorder(0, 0, 0, 0));
    return pane;
  }
 
  /**
   * Returns a read only JEditorPane containing the provided text with the
   * provided TextStyle.  The JEditorPane will assume that the text is plain
   * text.
   * @param text the text to be used to initialize the JEditorPane contents.
   * @param style the TextStyle to be used.
   * @return a read only JEditorPane containing the provided text with the
   * provided TextStyle.
   */
  public static JEditorPane makeTextPane(LocalizableMessage text, TextStyle style)
  {
    String s = text != null ? String.valueOf(text) : null;
    JEditorPane pane = new JEditorPane("text/plain", s);
    setTextStyle(pane, style);
    pane.setEditable(false);
    pane.setBorder(new EmptyBorder(0, 0, 0, 0));
    pane.setOpaque(false);
    return pane;
  }
 
  /**
   * Returns a JScrollPane that contains the provided component.  The scroll
   * pane will not contain any border.
   * @param comp the component contained in the scroll pane.
   * @return a JScrollPane that contains the provided component.  The scroll
   * pane will not contain any border.
   */
  public static JScrollPane createBorderLessScrollBar(Component comp)
  {
    JScrollPane scroll = new JScrollPane(comp);
    scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
    scroll.setViewportBorder(new EmptyBorder(0, 0, 0, 0));
    scroll.setOpaque(false);
    scroll.getViewport().setOpaque(false);
    scroll.getViewport().setBackground(DEFAULT_BACKGROUND);
    scroll.setBackground(DEFAULT_BACKGROUND);
    setScrollIncrementUnit(scroll);
    return scroll;
  }
 
  /**
   * Sets the scroll increment unit for the scroll.
   * @param scroll the scroll to be updated.
   */
  public static void setScrollIncrementUnit(JScrollPane scroll)
  {
    if (scroll.getVerticalScrollBar() != null)
    {
      int increment = scroll.getVerticalScrollBar().getUnitIncrement();
      if (increment < 16)
      {
        scroll.getVerticalScrollBar().setUnitIncrement(16);
      }
    }
  }
 
  /**
   * Return empty insets.
   * @return empty insets.
   */
  public static Insets getEmptyInsets()
  {
    return (Insets) EMPTY_INSETS.clone();
  }
 
  /**
   * Returns the insets to be used for the button panel.
   * @return the insets to be used for the button panel.
   */
  public static Insets getButtonsPanelInsets()
  {
    return (Insets) BUTTONS_PANEL_INSETS.clone();
  }
 
  /**
   * Returns the insets to be used for the steps panel.
   * @return the insets to be used for the steps panel.
   */
  public static Insets getStepsPanelInsets()
  {
    return (Insets) STEPS_PANEL_INSETS.clone();
  }
 
  /**
   * Returns the insets to be used for the current step panel.
   * @return the insets to be used for the current step panel.
   */
  public static Insets getCurrentStepPanelInsets()
  {
    return (Insets) CURRENT_STEP_PANEL_INSETS.clone();
  }
 
  /**
   * Returns a String that contains the html passed as parameter with a span
   * applied.  The span style corresponds to the Font specified as parameter.
   * The goal of this method is to be able to specify a font for an HTML string.
   *
   * @param html the original html text.
   * @param font the font to be used to generate the new HTML.
   * @return a string that represents the original HTML with the font specified
   * as parameter.
   */
  public static String applyFontToHtml(String html, Font font)
  {
    StringBuilder buf = new StringBuilder();
 
    buf.append("<span style=\"").append(getFontStyle(font)).append("\">")
        .append(html).append(SPAN_CLOSE);
 
    return buf.toString();
  }
 
  /**
   * Returns a String that contains the html passed as parameter with a div
   * applied.  The div style corresponds to the Font specified as parameter.
   * The goal of this method is to be able to specify a font for an HTML string.
   *
   * @param html the original html text.
   * @param font the font to be used to generate the new HTML.
   * @return a string that represents the original HTML with the font specified
   * as parameter.
   */
  public static String applyFontToHtmlWithDiv(String html, Font font)
  {
    StringBuilder buf = new StringBuilder();
 
    buf.append("<div style=\"").append(getFontStyle(font)).append("\">")
        .append(html).append(DIV_CLOSE);
 
    return buf.toString();
  }
 
  /**
   * Returns the HTML style representation for the given font.
   * @param font the font for which we want to get an HTML style representation.
   * @return the HTML style representation for the given font.
   */
  private static String getFontStyle(Font font)
  {
    StringBuilder buf = new StringBuilder();
 
    buf.append("font-family:")
        .append(font.getName())
        .append(";font-size:")
        .append(font.getSize())
        .append("pt");
 
    if (font.isItalic())
    {
      buf.append(";font-style:italic");
    }
 
    if (font.isBold())
    {
      buf.append(";font-weight:bold;");
    }
 
    return buf.toString();
  }
 
  /**
   * Returns the html text passed as parameter with the error background
   * applied to it.
   * @param html the original html.
   * @return the html text passed as parameter with the error background
   * applied to it.
   */
  public static String applyErrorBackgroundToHtml(String html)
  {
    return DIV_OPEN_ERROR_BACKGROUND + html + DIV_CLOSE;
  }
 
  /**
   * Returns the html text passed as parameter with the warning background
   * applied to it.
   * @param html the original html.
   * @return the html text passed as parameter with the warning background
   * applied to it.
   */
  public static String applyWarningBackgroundToHtml(String html)
  {
    return DIV_OPEN_WARNING_BACKGROUND + html + DIV_CLOSE;
  }
 
 
  /**
   * Returns the html text passed as parameter with the success background
   * applied to it.
   * @param html the original html.
   * @return the html text passed as parameter with the success background
   * applied to it.
   */
  public static String applySuccessfulBackgroundToHtml(String html)
  {
    return DIV_OPEN_SUCCESSFUL_BACKGROUND + html + DIV_CLOSE;
  }
 
 
  /**
   * Returns the html text passed as parameter with some added margin.
   * @param html the original html text.
   * @param top the top margin.
   * @param right the right margin.
   * @param bottom the bottom margin.
   * @param left the left margin.
   * @return the html text passed as parameter with some added margin.
   */
  public static String applyMargin(String html, int top, int right, int bottom,
      int left)
  {
    return "<div style=\"margin:" + top + "px " + right + "px " + bottom + "px "
        + left + "px;\">" + html + DIV_CLOSE;
  }
 
  /**
   * Updates the provided field with all the other arguments.
   * @param field the field to be modified.
   * @param text the new text of the field.
   * @param tooltip the new tooltip text of the field.
   * @param size the new size of the field.
   * @param textStyle the new TextStyle of the field.
   */
  private static void updateTextFieldComponent(JTextField field, LocalizableMessage text,
      LocalizableMessage tooltip, int size, TextStyle textStyle)
  {
    field.setColumns(size);
    if (text != null)
    {
      field.setText(text.toString());
    }
    if (tooltip != null)
    {
      field.setToolTipText(tooltip.toString());
    }
    if (textStyle != null)
    {
      setTextStyle(field, textStyle);
    }
  }
 
  private static Color getColor(LocalizableMessage l)
  {
    String s = String.valueOf(l);
    String[] colors = s.split(",");
    int r = Integer.parseInt(colors[0].trim());
    int g = Integer.parseInt(colors[1].trim());
    int b = Integer.parseInt(colors[2].trim());
 
    return new Color(r, g, b);
  }
 
  /**
   * Returns the parent package path.  This is used to retrieve the icon
   * qualified names.
   * @return the parent package path.
   */
  private static String getParentPackagePath()
  {
    if (parentPackagePath == null)
    {
      String packageName = UIFactory.class.getPackage().getName();
      int lastDot = packageName.lastIndexOf('.');
      String parentPackage = packageName.substring(0, lastDot);
      parentPackagePath = parentPackage.replace(".", "/");
    }
    return parentPackagePath;
  }
 
  /**
   * Returns the path of the icon for the given IconType.
   * @param iconType the IconType for which we want to get the path.
   * @return the path of the icon for the given IconType.
   */
  private static String getIconPath(IconType iconType)
  {
    LocalizableMessage key;
    switch (iconType)
    {
    case CURRENT_STEP:
      key = INFO_CURRENT_STEP_ICON.get();
      break;
 
    case SPLASH:
      key = INFO_SPLASH_ICON.get();
      break;
 
    case BACKGROUND:
      key = INFO_BACKGROUND_ICON.get();
      break;
 
    case MINIMIZED:
      key = INFO_MINIMIZED_ICON.get();
      break;
 
    case MINIMIZED_MAC:
      key = INFO_MINIMIZED_MAC_ICON.get();
      break;
 
    case WARNING:
      key = INFO_WARNING_ICON.get();
      break;
 
    case WARNING_LARGE:
      key = INFO_WARNING_LARGE_ICON.get();
      break;
 
    case INFORMATION:
      key = INFO_INFORMATION_ICON.get();
      break;
 
    case INFORMATION_LARGE:
      key = INFO_INFORMATION_LARGE_ICON.get();
      break;
 
    case SUBSECTION_LEFT:
      key = INFO_SUBSECTION_LEFT_ICON.get();
      break;
 
    case SUBSECTION_RIGHT:
      key = INFO_SUBSECTION_RIGHT_ICON.get();
      break;
 
    case HELP_SMALL:
      key = INFO_HELP_SMALL_ICON.get();
      break;
 
    case ERROR:
      key = INFO_ERROR_ICON.get();
      break;
 
    case ERROR_LARGE:
      key = INFO_ERROR_LARGE_ICON.get();
      break;
 
    case WAIT_TINY:
      key = INFO_WAIT_TINY.get();
      break;
 
    case WAIT:
      key = INFO_WAIT.get();
      break;
 
    default:
      throw new IllegalArgumentException("Unknown iconName: " + iconType);
    }
    return getParentPackagePath() + "/" + key.toString();
  }
 
  /**
   * Returns the icon description for the given IconType.
   * @param iconType the IconType for which we want to get the description.
   * @return the icon description for the given IconType.
   */
  private static LocalizableMessage getIconDescription(IconType iconType)
  {
    LocalizableMessage description;
    switch (iconType)
    {
    case CURRENT_STEP:
      description = INFO_CURRENT_STEP_ICON_DESCRIPTION.get();
      break;
 
    case SPLASH:
      description = INFO_SPLASH_ICON_DESCRIPTION.get();
      break;
 
    case BACKGROUND:
      description = INFO_BACKGROUND_ICON_DESCRIPTION.get();
      break;
 
    case MINIMIZED:
      description = INFO_MINIMIZED_ICON_DESCRIPTION.get();
      break;
 
    case MINIMIZED_MAC:
      description = INFO_MINIMIZED_ICON_DESCRIPTION.get();
      break;
 
    case WARNING:
      description = INFO_WARNING_ICON_DESCRIPTION.get();
      break;
 
    case WARNING_LARGE:
      description = INFO_WARNING_ICON_DESCRIPTION.get();
      break;
 
    case ERROR:
      description = INFO_ERROR_ICON_DESCRIPTION.get();
      break;
 
    case ERROR_LARGE:
      description = INFO_ERROR_ICON_DESCRIPTION.get();
      break;
 
    case INFORMATION:
      description = INFO_INFORMATION_ICON_DESCRIPTION.get();
      break;
 
    case INFORMATION_LARGE:
      description = INFO_INFORMATION_ICON_DESCRIPTION.get();
      break;
 
    case SUBSECTION_LEFT:
      description = INFO_SUBSECTION_LEFT_ICON_DESCRIPTION.get();
      break;
 
    case SUBSECTION_RIGHT:
      description = INFO_SUBSECTION_RIGHT_ICON_DESCRIPTION.get();
      break;
 
    case HELP_SMALL:
      description = INFO_HELP_SMALL_ICON_DESCRIPTION.get();
      break;
 
    case WAIT_TINY:
      description = INFO_HELP_WAIT_DESCRIPTION.get();
      break;
 
    case WAIT:
      description = INFO_HELP_WAIT_DESCRIPTION.get();
      break;
 
    case NO_ICON:
      description = null;
      break;
 
    default:
      throw new IllegalArgumentException("Unknown iconName: " + iconType);
    }
 
    return description;
  }
 
  /**
   * Returns the icon tooltip text for the given IconType.
   * @param iconType the IconType for which we want to get the tooltip text.
   * @return the icon tooltip text for the given IconType.
   */
  private static LocalizableMessage getIconTooltip(IconType iconType)
  {
    if (iconType == null) {
      iconType = IconType.NO_ICON;
    }
    LocalizableMessage tooltip;
    switch (iconType)
    {
    case CURRENT_STEP:
      tooltip = INFO_CURRENT_STEP_ICON_TOOLTIP.get();
      break;
 
    case SPLASH:
      tooltip = INFO_SPLASH_ICON_TOOLTIP.get();
      break;
 
    case BACKGROUND:
      tooltip = INFO_BACKGROUND_ICON_TOOLTIP.get();
      break;
 
    case MINIMIZED:
      tooltip = INFO_MINIMIZED_ICON_TOOLTIP.get();
      break;
 
    case MINIMIZED_MAC:
      tooltip = INFO_MINIMIZED_ICON_TOOLTIP.get();
      break;
 
    case WARNING:
      tooltip = INFO_WARNING_ICON_TOOLTIP.get();
      break;
 
    case WARNING_LARGE:
      tooltip = INFO_WARNING_ICON_TOOLTIP.get();
      break;
 
    case ERROR:
      tooltip = INFO_ERROR_ICON_TOOLTIP.get();
      break;
 
    case ERROR_LARGE:
      tooltip = INFO_ERROR_ICON_TOOLTIP.get();
      break;
 
    case INFORMATION:
      tooltip = INFO_INFORMATION_ICON_TOOLTIP.get();
      break;
 
    case INFORMATION_LARGE:
      tooltip = INFO_INFORMATION_ICON_TOOLTIP.get();
      break;
 
    case SUBSECTION_LEFT:
      tooltip = null;
      break;
 
    case SUBSECTION_RIGHT:
      tooltip = null;
      break;
 
    case HELP_SMALL:
      tooltip = null;
      break;
 
    case WAIT_TINY:
      tooltip = null;
      break;
 
    case WAIT:
      tooltip = null;
      break;
 
    case NO_ICON:
      tooltip = null;
      break;
 
    default:
      throw new IllegalArgumentException("Unknown iconName: " + iconType);
    }
 
    return tooltip;
  }
 
  private static ListCellRenderer makeCellRenderer(final TextStyle textStyle)
  {
    return new ListCellRenderer()
    {
      public Component getListCellRendererComponent(JList list,
          Object value,
          int index,
          boolean isSelected,
          boolean cellHasFocus)
      {
        JLabel l =
            makeJLabel(IconType.NO_ICON, LocalizableMessage.raw(value
                .toString()), textStyle);
        l.setBorder(new EmptyBorder(TOP_INSET_SECONDARY_FIELD, 0, 0, 0));
        return l;
      }
    };
  }
}
 
/**
 * This class has been written to have a better behaviour with the scroll pane
 * than the one we have by default in the case of the progress panel.
 *
 * With the default scroll pane behaviour when we set a new text in a
 * JEditorPane the scroll bar goes systematically up.  With this implementation
 * the expected behaviour is:
 *
 * If the scroll bar is at the bottom we will display the latest text contained
 * in the pane.
 *
 * If the scroll bar is not at the bottom we will keep on displaying the same
 * thing that the user is viewing.
 *
 * This behaviour allows the user to check the log content even when the
 * installation/uninstallation is still running and sending new log messages.
 *
 */
class ProgressJEditorPane extends JEditorPane
{
  private static final long serialVersionUID = 1221976708322628818L;
 
  private JScrollPane scroll;
 
  private boolean ignoreScrollToVisible;
 
  /**
   * Constructor for the ProgressJEditorPane.
   * @param scroll the JScrollPane that will contain this editor pane.
   */
  public ProgressJEditorPane(JScrollPane scroll)
  {
    super("text/html", null);
    this.scroll = scroll;
    setEditable(false);
    setBorder(new EmptyBorder(3, 3, 3, 3));
  }
 
  /**
   * {@inheritDoc}
   */
  @Override
  public void setText(String text)
  {
    // Scroll can be null in constructor
    if (scroll != null)
    {
      /* We apply the following policy: if the user is displaying the latest
       * part of the JTextArea we assume that when we add text (s)he wants
       * to see the text that is added, if not we assume that (s)he want to keep
       * viewing what is visible and so we ignore the next scrollRectToVisible
       * call (that will be done inside JTextArea.setText method).
       */
      JScrollBar vBar = scroll.getVerticalScrollBar();
      ignoreScrollToVisible =
          (vBar != null)
              && ((vBar.getValue() + vBar.getVisibleAmount()) < 0.97 * vBar
                  .getMaximum());
      super.setText(text);
    }
  }
 
  /**
   * {@inheritDoc}
   */
  @Override
  public void scrollRectToVisible(Rectangle rect)
  {
    if (!ignoreScrollToVisible)
    {
      super.scrollRectToVisible(rect);
      ignoreScrollToVisible = false;
    }
  }
}
 
/**
 * A class used to be able to select the contents of the text field when
 * it gets the focus.
 *
 */
class TextFieldFocusListener implements FocusListener
{
  private JTextField tf;
  /**
   * The constructor for this listener.
   * @param tf the text field associated with this listener.
   */
  TextFieldFocusListener(JTextField tf)
  {
    this.tf = tf;
  }
  /**
   * {@inheritDoc}
   */
  public void focusGained(FocusEvent e)
  {
    if ((tf.getText() == null) || "".equals(tf.getText()))
    {
      tf.setText(" ");
      tf.selectAll();
      tf.setText("");
    }
    else
    {
      tf.selectAll();
    }
  }
 
  /**
   * {@inheritDoc}
   */
  public void focusLost(FocusEvent e)
  {
  }
}