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 &lt;psmith@apache.org&gt;
    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   * A simple splash screen to be used at startup, while everything get's initialized.
    34   *
    35   * @author Paul Smith &lt;psmith@apache.org&gt;
    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  }