File: JiveFactory.java

package info (click to toggle)
herold 8.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,304 kB
  • sloc: java: 40,460; xml: 513; makefile: 37; sh: 29
file content (1399 lines) | stat: -rw-r--r-- 33,053 bytes parent folder | download | duplicates (3)
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
/* 
 * Copyright (C) 2001-2013 Michael Fuchs
 *
 * This file is part of herold.
 * 
 * herold is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * herold is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with herold.  If not, see <http://www.gnu.org/licenses/>.  
 */
package org.dbdoclet.jive;

import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontFormatException;
import java.awt.Frame;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.help.CSH;
import javax.help.HelpBroker;
import javax.help.HelpSet;
import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.JTree;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import javax.swing.text.JTextComponent;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
import javax.swing.tree.TreeModel;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.dbdoclet.Identifier;
import org.dbdoclet.jive.action.ActionSetLookAndFeel;
import org.dbdoclet.jive.model.SpinnerDistanceModel;
import org.dbdoclet.jive.sheet.Sheet;
import org.dbdoclet.jive.sheet.SheetContainer;
import org.dbdoclet.jive.widget.GridPanel;
import org.dbdoclet.jive.widget.IdentifierTextField;
import org.dbdoclet.jive.widget.LanguageListBox;
import org.dbdoclet.jive.widget.MimeTypeListBox;
import org.dbdoclet.jive.widget.NumberTextField;
import org.dbdoclet.jive.widget.PathList;
import org.dbdoclet.jive.widget.RichLabel;
import org.dbdoclet.jive.widget.SpinnerDistanceEditor;
import org.dbdoclet.jive.widget.UpperCaseTextField;
import org.dbdoclet.service.ResourceServices;
import org.dbdoclet.service.StringServices;
import org.dbdoclet.unit.Length;

/**
 * Fabrikklasse zu Erzeugung von Swing-Komponenten. JiveFactory ist eine
 * Singleton-Klasse die es nur einmal innerhalb einer Swing-Applikation geben
 * darf. Alle erzeugten Komponenten werden in einer Hashtabelle gespeichert und
 * können so von überall unter ihrem Namen angesprochen werden.
 * 
 * @author michael
 */
public final class JiveFactory implements ItemListener, DocumentListener,
		ActionListener, ChangeListener {

	private static Log logger = LogFactory.getLog(JiveFactory.class);
	private static JiveFactory singleton;

	private ImageIcon applicationIcon;
	private URL backgroundImageUrl = null;
	private Font defaultFont = null;
	private Color defaultForeground;
	private Color helpAreaBackground = null;
	private Border helpAreaBorder = null;
	private HelpBroker helpBroker;
	private HelpSet helpSet;
	private final Locale locale;
	private ResourceBundle res = ResourceBundle
			.getBundle("org/dbdoclet/jive/Resources");
	private ArrayList<JComponent> saveWidgetList;
	private final HashMap<Identifier, JComponent> widgetMap;
	private Color defaultBackground;

	/**
	 * Erzeugt eine neue Instanz der Klasse <code>JiveFactory</code>. Da es nur
	 * eine Instanz dieser Klasse geben darf ist der Konstruktur für andere
	 * Objekte nicht sichtbar.
	 * 
	 * @param locale
	 */
	private JiveFactory(Locale locale) {

		if (locale == null) {
			throw new IllegalArgumentException(
					"The argument locale must not be null!");
		}

		this.locale = locale;
		widgetMap = new HashMap<Identifier, JComponent>();
		res = ResourceBundle.getBundle("org/dbdoclet/jive/Resources", locale);
	}

	/**
	 * Ermittelt die Objektinstanz des Fensterrahmens innerhalb dessen sich die
	 * übergebene Kompontente befindet.
	 * 
	 * @param comp
	 * @return Frame
	 */
	public static Frame findParentFrame(JComponent comp) {

		if (comp == null) {
			return null;
		}

		Container parent = comp.getParent();

		while (parent != null) {

			if (parent instanceof Frame) {
				return (Frame) parent;
			}

			parent = parent.getParent();
		}

		return null;
	}

	/**
	 * Liefert die Instanz der Fabrikklasse.
	 * 
	 * @return JiveFactory
	 */
	public static JiveFactory getInstance() {

		if (singleton == null) {
			singleton = getInstance(Locale.getDefault());
		}

		return singleton;
	}

	/**
	 * Liefert eine Instanz der Fabrikklasse mit der angegebenen Lokalisierung.
	 * 
	 * @param locale
	 * @return JiveFactory
	 */
	public static JiveFactory getInstance(Locale locale) {

		System.setProperty("swing.aatext", "true");

		if (singleton != null) {

			logger.warn("Changing locale of global singleton WidgetMap to "
					+ locale.toString());
			singleton.setLocale(locale);

		} else {

			singleton = new JiveFactory(locale);
		}

		return singleton;
	}

	/**
	 * Wird derzeit nur zum Zweck des Debuggens verwendet.
	 */
	public void actionPerformed(ActionEvent event) {

		logger.debug("event=" + event);
		logger.debug("ActionEvent: \n" + "  Source        = '"
				+ event.getSource().getClass().getName() + "'\n"
				+ "  ID            = '" + event.getID() + "'\n"
				+ "  ActionCommand = '" + event.getActionCommand() + "'\n");
	}

	/**
	 * Fügt eine Komponente der Liste der Speicher-Komponenten hinzu.
	 * 
	 * @param widget
	 */
	public void addSaveWidget(JComponent widget) {

		if (saveWidgetList == null) {
			saveWidgetList = new ArrayList<JComponent>();
		}

		if (widget != null && saveWidgetList.contains(widget) == false) {
			saveWidgetList.add(widget);
		}
	}

	public void changedUpdate(DocumentEvent documentEvent) {
		enableSaveWidgets();
	}

	/**
	 * Erzeugt einen Button mit der ID <code>key</code> und der angegebenen
	 * <code>action</code>.
	 * 
	 * @param key
	 * @param action
	 * @return JButton
	 */
	public JButton createButton(Identifier key, AbstractAction action) {

		JButton button = new JButton(action);
		addWidget(key, button);

		return button;
	}

	/**
	 * Erzeugt einen Button mit der ID <code>key</code> und der angegebenen
	 * Aufschrift.
	 * 
	 * @param key
	 * @param text
	 * @return JButton
	 */
	public JButton createButton(Identifier key, String text) {
		return createButton(key, text, null);
	}

	public JButton createButton(Identifier key, String text, String icon) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		URL url = null;

		if (icon != null && icon.length() > 0) {

			String location = "toolbarButtonGraphics/" + icon + "24.gif";
			url = ClassLoader.getSystemResource(location);

			if (url == null) {
				url = getClass().getResource(location);
			}
		}

		JButton button;

		if (url != null) {
			button = new JButton(text, new ImageIcon(url));
		} else {
			button = new JButton(text);
		}

		addWidget(key, button);

		return button;
	}

	public JButton createButton(String label) {
		return createButton(null, label);
	}

	public JCheckBox createCheckBox() {
		return createCheckBox(null, null);
	}

	public JCheckBox createCheckBox(Identifier key, String label) {

		JCheckBox checkBox = new JCheckBox(label);
		checkBox.addItemListener(this);

		addWidget(key, checkBox);

		return checkBox;
	}

	public JCheckBox createCheckBox(String label) {
		return createCheckBox(null, label);
	}

	public <T> JComboBox<T> createComboBox(Identifier key) {
		return createComboBox(key, null);
	}

	public <T> JComboBox<T> createComboBox(Identifier key, T[] list) {

		JComboBox<T> comboBox;

		if (list == null) {
			comboBox = new JComboBox<T>();
		} else {
			comboBox = new JComboBox<T>(list);
		}

		comboBox.addItemListener(this);
		addWidget(key, comboBox);

		return comboBox;
	}

	public JSpinner createDistanceSpinner() {
		return createDistanceSpinner(null, null);
	}

	public JSpinner createDistanceSpinner(Identifier key) {
		return createDistanceSpinner(key, null, true);
	}

	public JSpinner createDistanceSpinner(Identifier key, boolean excludePercent) {
		return createDistanceSpinner(key, null, excludePercent);
	}

	public JSpinner createDistanceSpinner(Identifier key, Length distance) {
		return createDistanceSpinner(key, distance, true);
	}

	public JSpinner createDistanceSpinner(Identifier key, Length distance,
			boolean excludePercent) {

		SpinnerDistanceModel model = new SpinnerDistanceModel(getLocale());
		model.setExcludePercent(excludePercent);

		JSpinner spinner = new JSpinner(model);

		if (distance != null) {
			spinner.setValue(distance);
		}

		Dimension preferredSize = spinner.getPreferredSize();

		if (preferredSize.width < 100) {
			preferredSize.width = 100;
		}

		spinner.setPreferredSize(preferredSize);
		spinner.setEditor(new SpinnerDistanceEditor(spinner));
		spinner.addChangeListener(this);

		addWidget(key, spinner);

		return spinner;
	}

	public JSpinner createDistanceSpinner(Length length) {
		return createDistanceSpinner(null, length);
	}

	public JLabel createEntryHelp(String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		text = createToolTipText(text);

		JLabel label = new JLabel("Help24", JiveServices.getJlfgrIcon(
				"general", "Help24.gif"), SwingConstants.CENTER);

		label.setToolTipText(text);
		label.setForeground(new Color(0, 0, 205));

		return label;
	}

	public JTextComponent createErrorArea(Identifier key, JComponent parent) {
		return createErrorArea(key, parent, "<html>");
	}

	public JTextComponent createErrorArea(Identifier key, JComponent parent,
			String text) {

		if (parent == null) {
			throw new IllegalArgumentException(
					"The argument parent must not be null!");
		}

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JEditorPane errorArea = new JEditorPane();
		errorArea.setEditable(false);
		errorArea.setFocusable(false);
		errorArea.setBackground(Color.white);
		errorArea.setBorder(BorderFactory.createCompoundBorder(
				BorderFactory.createLineBorder(new Color(139, 0, 0)),
				BorderFactory.createEmptyBorder(5, 5, 5, 5)));

		if (text.toLowerCase().startsWith("<html>") == true) {

			errorArea.setContentType("text/html");
			Document doc = errorArea.getDocument();

			if (doc instanceof HTMLDocument) {

				HTMLDocument htmlDoc = (HTMLDocument) doc;
				StyleSheet styleSheet = htmlDoc.getStyleSheet();

				Font defaultFont = parent.getFont();
				String fontFamily = defaultFont.getFamily();
				int fontSize = defaultFont.getSize();

				styleSheet.addRule("body {" + " color: #8b0000;"
						+ " font-family: " + fontFamily + ";" + " font-size: "
						+ fontSize + ";" + "}");

				styleSheet.addRule("h1, h2 {" + " font-family: " + fontFamily
						+ ";" + " font-size: " + fontSize + ";"
						+ " margin: 2px;" + "}");

				styleSheet.addRule("p {" + " text-indent: 8px;"
						+ " margin: 2px;" + "}");

				errorArea.setText(text);
			}

		} else {

			errorArea.setContentType("text/plain");
			errorArea.setText(text);
		}

		addWidget(key, errorArea);

		return errorArea;
	}

	public JTextComponent createErrorArea(JComponent parent, String text) {
		return createErrorArea(null, parent, text);
	}

	public JLabel createHeading(Identifier key, String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JLabel label = new JLabel(text);

		Font font = label.getFont();

		String fontName = font.getName();
		int fontSize = (int) (font.getSize() * 1.6);
		Font headingFont = new Font(fontName, Font.BOLD, fontSize);

		label.setFont(headingFont);
		label.setForeground(new Color(01, 48, 114));

		addWidget(key, label);

		return label;
	}

	public JTextComponent createHelpArea(Identifier key, JComponent parent) {
		return createHelpArea(key, parent, "<html>");
	}

	public JTextComponent createHelpArea(Identifier key, JComponent parent,
			String text) {

		if (parent == null) {
			throw new IllegalArgumentException(
					"The argument parent must not be null!");
		}

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JEditorPane helpArea = new JEditorPane();
		helpArea.setEditable(false);
		helpArea.setFocusable(false);

		if (helpAreaBackground == null) {
			helpArea.setBackground(parent.getBackground());
		} else {
			helpArea.setBackground(helpAreaBackground);
		}

		if (helpAreaBorder == null) {
			helpArea.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
		} else {
			helpArea.setBorder(helpAreaBorder);
		}

		// helpArea.setMinimumSize(new Dimension(400, 100));
		// helpArea.setPreferredSize(new Dimension(400, 100));

		if (text.toLowerCase().startsWith("<html>") == true) {

			helpArea.setContentType("text/html");
			Document doc = helpArea.getDocument();

			if (doc instanceof HTMLDocument) {

				HTMLDocument htmlDoc = (HTMLDocument) doc;
				StyleSheet styleSheet = htmlDoc.getStyleSheet();

				Font defaultFont = parent.getFont();
				String fontFamily = defaultFont.getFamily();
				int fontSize = defaultFont.getSize();

				styleSheet.addRule("body {" + " font-family: " + fontFamily
						+ ";" + " font-size: " + (fontSize - 2) + ";" + "}");

				styleSheet.addRule("h1, h2 {" + " font-family: " + fontFamily
						+ ";" + " font-size: " + (fontSize - 1) + ";"
						+ " color: #031071;" + " margin: 2px;" + "}");

				styleSheet.addRule("p {"
				// + " text-indent: 8px;"
						+ " margin: 2px;" + "}");

				styleSheet.addRule("p.error {" + " color: red;" + "}");

				helpArea.setText(text);
			}

		} else {

			helpArea.setContentType("text/plain");
			helpArea.setText(text);
		}

		addWidget(key, helpArea);

		return helpArea;
	}

	public JTextComponent createHelpArea(JComponent parent) {
		return createHelpArea(null, parent, "<html>");
	}

	public JTextComponent createHelpArea(JComponent parent, String text) {
		return createHelpArea(null, parent, text);
	}

	public JEditorPane createHtmlArea(Identifier key, JComponent parent,
			String text) {

		if (parent == null) {
			throw new IllegalArgumentException(
					"The argument parent must not be null!");
		}

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JEditorPane htmlArea = new JEditorPane("text/html", text);
		htmlArea.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		htmlArea.setEditable(false);
		// htmlArea.setFocusable(false);

		htmlArea.setMinimumSize(new Dimension(200, 100));

		addWidget(key, htmlArea);

		if (text.toLowerCase().startsWith("<html>") == true) {

			htmlArea.setContentType("text/html");
			Document doc = htmlArea.getDocument();

			if (doc instanceof HTMLDocument) {

				HTMLDocument htmlDoc = (HTMLDocument) doc;
				StyleSheet styleSheet = htmlDoc.getStyleSheet();

				Font defaultFont = parent.getFont();
				String fontFamily = defaultFont.getFamily();
				int fontSize = defaultFont.getSize();

				styleSheet.addRule("body {" + " font-family: " + fontFamily
						+ ";" + " font-size: " + fontSize + ";" + "}");
			}
		}

		return htmlArea;
	}

	public JButton createIconButton(Identifier key, ImageIcon icon) {

		if (icon == null) {
			throw new IllegalArgumentException(
					"The argument icon must not be null!");
		}

		JButton button = new JButton(icon);
		button.setActionCommand("icon-button");
		button.addActionListener(this);

		addWidget(key, button);

		return button;
	}

	public IdentifierTextField createIdentifierTextField(Identifier key,
			int width) {

		IdentifierTextField textfield = new IdentifierTextField(width);
		addWidget(key, textfield);

		return textfield;
	}

	public IdentifierTextField createIdentifierTextField(int width) {
		return createIdentifierTextField(null, width);
	}

	public JLabel createLabel(Identifier key, String text) {
		return createLabel(key, text, Font.BOLD);
	}

	public JLabel createLabel(Identifier key, String text, int style) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JLabel label = new JLabel(text);

		Font font = label.getFont();
		label.setFont(font.deriveFont(style));
		addWidget(key, label);

		return label;
	}

	public JLabel createLabel(String text) {
		return createLabel(null, text, Font.BOLD);
	}

	public JLabel createLabel(String text, int style) {
		return createLabel(null, text, style);
	}

	public LanguageListBox createLanguageListBox(Identifier key, Locale locale) {

		LanguageListBox llb = new LanguageListBox(locale);
		addWidget(key, llb);
		return llb;
	}

	public <T> JList<T> createList(Identifier key) {

		JList<T> list = new JList<T>();
		addWidget(key, list);

		if (defaultBackground != null) {
			list.setBackground(defaultBackground.brighter());
		}

		return list;
	}

	public JMenu createLookAndFeelMenu(ArrayList<Component> componentList) {

		if (componentList == null) {
			throw new IllegalArgumentException(
					"The argument frame must not be null!");
		}

		JMenuItem menuItem;

		JMenu menu = new JMenu(ResourceServices.getString(res,
				"C_LOOK_AND_FEEL"));

		LookAndFeelInfo[] infoList = UIManager.getInstalledLookAndFeels();

		for (int i = 0; i < infoList.length; i++) {

			menuItem = new JMenuItem(infoList[i].getName());
			menuItem.setAction(new ActionSetLookAndFeel(infoList[i].getName(),
					infoList[i], componentList));
			menu.add(menuItem);
		}

		return menu;
	}

	public JMenu createMenu(Identifier key, String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JMenu menu = new JMenu(text);
		// menu.setFont(font);

		addWidget(key, menu);

		return menu;
	}

	public JMenu createMenu(String text) {
		return createMenu(null, text);
	}

	/**
	 * Erzeugt einen Menüeintrag.
	 * 
	 * @param key
	 * @param action
	 * @return JMenuItem
	 */
	public JMenuItem createMenuItem(Identifier key, AbstractAction action) {

		JMenuItem menuItem = new JMenuItem(action);
		addWidget(key, menuItem);
		return menuItem;
	}

	public JMenuItem createMenuItem(Identifier key, String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		JMenuItem menuitem = new JMenuItem(text);
		addWidget(key, menuitem);

		return menuitem;
	}

	public MimeTypeListBox createMimeTypeListBox(Identifier key) {

		MimeTypeListBox mtlb = new MimeTypeListBox();
		addWidget(key, mtlb);
		return mtlb;
	}

	public JSpinner createNumberSpinner(Identifier key, int value, int min,
			int max, int step) {

		JSpinner spinner = new JSpinner(new SpinnerNumberModel(value, min, max,
				step));
		addWidget(key, spinner);
		return spinner;
	}

	public NumberTextField createNumberTextField(Identifier key, int width) {

		NumberTextField textfield = new NumberTextField(width);

		textfield.getDocument().addDocumentListener(this);
		textfield.addActionListener(this);

		addWidget(key, textfield);

		return textfield;
	}

	public NumberTextField createNumberTextField(int width) {
		return createNumberTextField(null, width);
	}

	public JPanel createPanel(Identifier key) {
		return createPanel(key, null);
	}

	public JPanel createPanel(Identifier key, LayoutManager layoutManager) {

		JPanel panel;

		if (layoutManager != null) {
			panel = new JPanel(layoutManager);
		} else {
			panel = new JPanel();
		}

		addWidget(key, panel);
		return panel;
	}

	public JPasswordField createPasswordField(Identifier key, int width) {

		JPasswordField passwordfield = new JPasswordField(width);
		passwordfield.setMinimumSize(passwordfield.getPreferredSize());

		addWidget(key, passwordfield);

		return passwordfield;
	}

	public PathList createPathList(Identifier key, int filterMask) {

		PathList pathlist = new PathList(this, filterMask);
		addWidget(key, pathlist);

		return pathlist;
	}

	public JRadioButton createRadioButton(Identifier key, ImageIcon icon) {

		JRadioButton button = new JRadioButton(icon);
		addWidget(key, button);

		return button;
	}

	public JRadioButton createRadioButton(Identifier key, String label) {

		JRadioButton button = new JRadioButton(label);
		addWidget(key, button);

		return button;
	}

	public RichLabel createRichLabel(String text) {

		RichLabel label = new RichLabel(text);
		addWidget(null, label);

		if (defaultForeground != null) {
			label.setForeground(defaultForeground);
		}

		if (defaultFont != null) {
			label.setFont(defaultFont.deriveFont(Font.BOLD));
		}

		return label;
	}

	public JScrollPane createScrollPane(Component client) {
		return createScrollPane(null, client);
	}

	public JScrollPane createScrollPane(Identifier key, Component client) {

		if (client == null) {
			throw new IllegalArgumentException(
					"The argument client must not be null!");
		}

		JScrollPane scrollPane = new JScrollPane(client);
		addWidget(key, scrollPane);

		return scrollPane;
	}

	public Sheet createSheet(SheetContainer container) {
		return new Sheet(container, res);
	}

	public JSplitPane createSplitPane(Identifier key) {

		JSplitPane splitPane = new JSplitPane();
		addWidget(key, splitPane);

		return splitPane;
	}

	public JTabbedPane createTabbedPane() {
		return createTabbedPane(null);
	}

	public JTabbedPane createTabbedPane(Identifier key) {

		JTabbedPane tabbedPane = new JTabbedPane();
		addWidget(key, tabbedPane);
		return tabbedPane;
	}

	public JTable createTable(Identifier key) {

		JTable table = new JTable();
		addWidget(key, table);
		return table;
	}

	// public JTextField createTextField(int width) {
	//
	// return createTextField(null, width);
	// }

	public JTextArea createTextArea(Identifier key) {

		JTextArea textarea = new JTextArea();
		textarea.getDocument().addDocumentListener(this);

		addWidget(key, textarea);

		return textarea;
	}

	public JTextArea createTextArea(Identifier key, int rows, int cols) {

		JTextArea textarea = new JTextArea(rows, cols);

		textarea.getDocument().addDocumentListener(this);

		addWidget(key, textarea);

		return textarea;
	}

	public JTextField createTextField(Identifier key, int width) {

		JTextField textfield = new JTextField(width);

		textfield.getDocument().addDocumentListener(this);
		textfield.addActionListener(this);
		textfield.setMinimumSize(textfield.getPreferredSize());

		addWidget(key, textfield);

		return textfield;
	}

	public JTextPane createTextPane() {
		return createTextPane(null);
	}

	public JTextPane createTextPane(Identifier key) {

		JTextPane textPane = new JTextPane();
		addWidget(key, textPane);
		return textPane;
	}

	public JToggleButton createToggleButton(Identifier key, String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument icon must not be null!");
		}

		JToggleButton button = new JToggleButton(text);
		button.setActionCommand("toggle-button");
		button.addActionListener(this);

		addWidget(key, button);

		return button;
	}

	public JToolBar createToolBar(Identifier key) {

		JToolBar toolbar = new JToolBar();
		addWidget(key, toolbar);

		return toolbar;
	}

	public String createToolTipText(String text) {

		if (text == null) {
			throw new IllegalArgumentException(
					"The argument text must not be null!");
		}

		text = text.trim();
		text = StringServices.splitAt(text, " ", 40, "<br>");

		if (text.startsWith("<html>") == false) {
			text = "<html>" + text;
		}

		return text;
	}

	public JTree createTree(Identifier key) {
		return createTree(key, null);
	}

	public JTree createTree(Identifier key, TreeModel model) {

		JTree tree;

		if (model != null) {
			tree = new JTree(model);
		} else {
			tree = new JTree();
		}

		addWidget(key, tree);
		return tree;
	}

	public UpperCaseTextField createUpperCaseTextField(Identifier key, int width) {

		UpperCaseTextField textfield = new UpperCaseTextField(width);

		addWidget(key, textfield);

		return textfield;
	}

	public JSpinner createWidthSpinner(Identifier key) {
		return createWidthSpinner(key, null);
	}

	public JSpinner createWidthSpinner(Identifier key, Length width) {

		JSpinner spinner = new JSpinner(new SpinnerDistanceModel(getLocale()));

		if (width != null) {
			spinner.setValue(width);
		}

		Dimension preferredSize = spinner.getPreferredSize();

		if (preferredSize.width < 75) {
			preferredSize.width = 75;
		}

		spinner.setPreferredSize(preferredSize);
		spinner.setEditor(new SpinnerDistanceEditor(spinner));
		spinner.addChangeListener(this);

		addWidget(key, spinner);

		return spinner;
	}

	/**
	 * Deaktiviert die Komponente <code>comp</code> und alle in ihr enthaltenen
	 * Kindkomponenten. Kindkomponenten, die aktiv waren und deaktiviert wurden
	 * werden markiert. Dadurch weiß die Methode {@link #enableAll} welche
	 * Komponenten aktiviert werden müssen und welche bereits beim Aufruf von
	 * <code>disableAll</code> deaktiviert waren und deshalb nicht verändert
	 * werden dürfen. müssen. Nach der Ausführung der Methoden
	 * <code>disableAll</code> und <code>enableAll</code> soll der
	 * Ausgangszustand möglichst genau wiederhergestellt werden. Dazu gehört
	 * auch, dass keine Komponente plötzlich aktiviert wurde, die es vorher
	 * nicht war.
	 * 
	 * @param comp
	 */
	public void disableAll(Component comp) {

		if (comp == null) {
			return;
		}

		if (comp instanceof Container) {

			Container parent = (Container) comp;

			Component[] compList = parent.getComponents();

			for (int i = 0; i < compList.length; i++) {

				disableAll(compList[i]);
			}
		}

		String name;

		if (comp instanceof AbstractButton || comp instanceof JComboBox
				|| comp instanceof JTextComponent) {

			name = comp.getName();

			if (name == null) {
				name = "";
			}

			logger.debug("disable name = " + name);

			if (comp.isEnabled() == true) {

				logger.debug("disabling name = " + name);
				comp.setEnabled(false);

				if (name.endsWith("toggled") == false) {
					comp.setName(name + ":toggled");
				}
			}
		}
	}

	public void disableSaveWidgets() {

		if (saveWidgetList != null && saveWidgetList.size() > 0) {

			JComponent comp;
			Iterator<JComponent> iterator = saveWidgetList.iterator();

			while (iterator.hasNext()) {

				comp = iterator.next();
				comp.setEnabled(false);
			}
		}
	}

	public void enableAll(Component comp) {

		if (comp == null) {
			return;
		}

		if (comp instanceof Container) {

			Container parent = (Container) comp;

			Component[] compList = parent.getComponents();

			for (int i = 0; i < compList.length; i++) {

				enableAll(compList[i]);
			}
		}

		String name;

		if (comp instanceof AbstractButton || comp instanceof JComboBox
				|| comp instanceof JTextComponent) {

			name = comp.getName();

			if (name == null) {
				name = "";
			}

			logger.debug("enable name = " + name);

			if (comp.isEnabled() == false) {

				if (name.endsWith(":toggled") == true) {

					logger.debug("enabling name = " + name);
					comp.setEnabled(true);

				} else {

					comp.setName(name + ":enabled");
				}
			}
		}
	}

	public void enableSaveWidgets() {

		if (saveWidgetList != null && saveWidgetList.size() > 0) {

			JComponent comp;
			Iterator<JComponent> iterator = saveWidgetList.iterator();

			while (iterator.hasNext()) {

				comp = iterator.next();
				comp.setEnabled(true);
			}
		}
	}

	public ImageIcon getApplicationIcon() {
		return applicationIcon;
	}

	public URL getBackgroundImageUrl() {
		return backgroundImageUrl;
	}

	public HelpBroker getHelpBroker() {
		return helpBroker;
	}

	public Color getLabelForeground() {
		return defaultForeground;
	}

	public Locale getLocale() {
		return locale;
	}

	// public void setLookandFeel(String laf) {
	//
	// }

	public ResourceBundle getResourceBundle() {
		return res;
	}

	public JComponent getWidget(Identifier key) {
		return widgetMap.get(key);
	}

	public void insertUpdate(DocumentEvent documentEvent) {
		enableSaveWidgets();
	}

	public void itemStateChanged(ItemEvent itemEvent) {
		enableSaveWidgets();
	}

	public Font registerEuterpeFont() {

		try {

			InputStream instr = ResourceServices.getResourceAsStream(
					"/fonts/Euterpe.ttf", JiveFactory.class.getClassLoader());

			if (instr != null) {
				Font font = Font.createFont(Font.TRUETYPE_FONT, instr);
				// GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font);
				// return new Font("Euterpe", Font.PLAIN, 12);
				return font;
			}

		} catch (FontFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	public void removeUpdate(DocumentEvent documentEvent) {
		enableSaveWidgets();
	}

	public void setApplicationIcon(ImageIcon applicationIcon) {
		this.applicationIcon = applicationIcon;
	}

	public void setBackgroundImageUrl(URL backgroundImageUrl) {
		this.backgroundImageUrl = backgroundImageUrl;
	}

	public void setDefaultForeground(Color foreground) {
		this.defaultForeground = foreground;
	}

	public void setDefaultFont(Font defaultFont) {

		if (defaultFont == null) {
			throw new IllegalArgumentException(
					"Parameter font must not be null!");
		}

		this.defaultFont = defaultFont;
	}

	public void setHelpAreaBackground(Color helpAreaBackground) {
		this.helpAreaBackground = helpAreaBackground;
	}

	public void setHelpAreaBorder(Border helpAreaBorder) {
		this.helpAreaBorder = helpAreaBorder;
	}

	public void setHelpBroker(HelpBroker helpBroker) {
		this.helpBroker = helpBroker;

	}

	public void setHelpSet(HelpSet helpSet) {
		this.helpSet = helpSet;
	}

	public void setLocale(Locale locale) {

		if (locale == null) {
			throw new IllegalArgumentException(
					"The argument locale must not be null!");
		}

		res = ResourceBundle.getBundle("org/dbdoclet/jive/Resources", locale);
	}

	public void stateChanged(ChangeEvent e) {
		enableSaveWidgets();
	}

	private void addContextSensitiveHelp(Identifier key, JComponent comp) {

		if (helpBroker != null && helpSet != null) {

			try {

				CSH.setHelpIDString(comp, key.getValue());
				CSH.setHelpSet(comp, helpSet);
				helpBroker.enableHelpKey(comp, key.getValue(), helpSet,
						"javax.help.Popup", "popup");

				// comp.setToolTipText(key);

			} catch (Throwable oops) {
				// logger.fatal("Can't add context sensitive help of key " +
				// key, oops);
			}
		}

		comp.setName(key.getValue());
	}

	/**
	 * Fügt eine Oberflächenkomponente zur globalen Hashtabelle hinzu. Der
	 * Identifikator wird auch verwendet um den Namen der Komponente (
	 * {@link Component#setName(String)}) und den Schlüssel für die
	 * kontext-sensitive Hilfe zu setzen.
	 * 
	 * Falls bereits eine Komponente mit gleichem Namen in der Hashtabelle
	 * existiert, wird die bereits vorhandene Komponente überschrieben.
	 * 
	 * @param key
	 * @param comp
	 */
	private void addWidget(Identifier key, JComponent comp) {

		if (defaultFont != null) {
			Font compFont = comp.getFont();
			comp.setFont(defaultFont.deriveFont(compFont.getStyle()));
		}

		if (defaultForeground != null) {
			comp.setForeground(defaultForeground);
		}

		if (defaultBackground != null) {
			comp.setBackground(defaultBackground);
		}

		if (key != null && key.length() > 0 && comp != null) {

			comp.setName(key.toString());
			addContextSensitiveHelp(key, comp);

			widgetMap.put(key, comp);
		}
	}

	public void setDefaultBackground(Color defaultBackground) {
		this.defaultBackground = defaultBackground;
	}

	public GridPanel createGridPanel(Identifier key) {

		GridPanel panel = new GridPanel();
		addWidget(key, panel);
		return panel;
	}
}