View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    * 
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   * 
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  /*
19   * @author Paul Smith <psmith@apache.org>
20   *
21  */
22  package org.apache.log4j.chainsaw;
23  
24  import java.awt.BorderLayout;
25  import java.awt.Color;
26  import java.awt.Container;
27  import java.awt.Font;
28  import java.awt.Frame;
29  import java.awt.GraphicsEnvironment;
30  import java.util.HashSet;
31  import java.util.Set;
32  
33  import javax.swing.BorderFactory;
34  import javax.swing.JLabel;
35  import javax.swing.JPanel;
36  import javax.swing.JWindow;
37  import javax.swing.SwingConstants;
38  
39  import org.apache.log4j.chainsaw.icons.ChainsawIcons;
40  
41  
42  /**
43   * A simple splash screen to be used at startup, while everything get's initialized.
44   * @author Paul Smith <psmith@apache.org>
45   *
46   */
47  class ChainsawSplash extends JWindow {
48    ChainsawSplash(Frame owner) {
49      super(owner);
50  
51      Container container = getContentPane();
52      JPanel panel = new JPanel(new BorderLayout());
53      JLabel logo = new JLabel(ChainsawIcons.ICON_LOG4J);
54  
55      JLabel text = new JLabel("Chainsaw v2", SwingConstants.CENTER);
56      Font textFont = null;
57      String[] preferredFontNames =
58        new String[] { "Arial", "Helvetica", "SansSerif" };
59  
60      Set availableFontNames = new HashSet();
61      Font[] allFonts =
62        GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
63  
64      for (int i = 0; i < allFonts.length; i++) {
65        availableFontNames.add(allFonts[i].getName());
66      }
67  
68      for (int i = 0; i < preferredFontNames.length; i++) {
69        if (availableFontNames.contains(preferredFontNames[i])) {
70          textFont = new Font(preferredFontNames[i], Font.PLAIN, 12);
71  
72          System.out.println("Using font=" + textFont.getName());
73  
74          break;
75        }
76      }
77  
78      if (textFont == null) {
79        System.out.println("Using basic font");
80        textFont = text.getFont();
81      }
82  
83      text.setFont(textFont.deriveFont(16f).deriveFont(Font.BOLD));
84      text.setBackground(Color.white);
85      text.setForeground(Color.black);
86      text.setBorder(BorderFactory.createLoweredBevelBorder());
87      panel.add(logo, BorderLayout.CENTER);
88      panel.add(text, BorderLayout.SOUTH);
89      panel.setBorder(BorderFactory.createLineBorder(Color.black, 1));
90  
91      container.add(panel);
92      pack();
93    }
94  }