1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.log4j.chainsaw;
23
24 import org.apache.log4j.chainsaw.icons.ChainsawIcons;
25
26 import javax.swing.*;
27 import java.awt.*;
28 import java.util.HashSet;
29 import java.util.Set;
30
31
32
33
34
35
36
37 class ChainsawSplash extends JWindow {
38 ChainsawSplash(Frame owner) {
39 super(owner);
40
41 Container container = getContentPane();
42 JPanel panel = new JPanel(new BorderLayout());
43 JLabel logo = new JLabel(ChainsawIcons.ICON_LOG4J);
44
45 JLabel text = new JLabel("Chainsaw v2", SwingConstants.CENTER);
46 Font textFont = null;
47 String[] preferredFontNames =
48 new String[]{"Arial", "Helvetica", "SansSerif"};
49
50 Set<String> availableFontNames = new HashSet<>();
51 Font[] allFonts =
52 GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
53
54 for (Font allFont : allFonts) {
55 availableFontNames.add(allFont.getName());
56 }
57
58 for (String preferredFontName : preferredFontNames) {
59 if (availableFontNames.contains(preferredFontName)) {
60 textFont = new Font(preferredFontName, Font.PLAIN, 12);
61
62 System.out.println("Using font=" + textFont.getName());
63
64 break;
65 }
66 }
67
68 if (textFont == null) {
69 System.out.println("Using basic font");
70 textFont = text.getFont();
71 }
72
73 text.setFont(textFont.deriveFont(16f).deriveFont(Font.BOLD));
74 text.setBackground(Color.white);
75 text.setForeground(Color.black);
76 text.setBorder(BorderFactory.createLoweredBevelBorder());
77 panel.add(logo, BorderLayout.CENTER);
78 panel.add(text, BorderLayout.SOUTH);
79 panel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
80
81 container.add(panel);
82 pack();
83 }
84 }