Class FontComboUtil


  • public class FontComboUtil
    extends java.lang.Object
    This utility class provides methods that initialise and return a JComboBox containing a specific sub-set of fonts installed on a users system.

    Optionally, the JComboBox can be displayed with a preview of the specific font in the drop-down list itself.


    This file is part of JMRI.

    JMRI is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License as published by the Free Software Foundation. See the "COPYING" file for a copy of this license.

    JMRI 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.

    Since:
    2.13.1
    • Constructor Summary

      Constructors 
      Constructor Description
      FontComboUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static javax.swing.JComboBox<java.lang.String> getFontCombo()
      Return a JComboBox containing all available font families.
      static javax.swing.JComboBox<java.lang.String> getFontCombo​(boolean previewOnly)
      Return a JComboBox containing all available font families.
      static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which)
      Return a JComboBox containing the specified set of font families.
      static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which, boolean previewOnly)
      Return a JComboBox containing the specified set of font families.
      static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which, int size)
      Return a JComboBox containing the specified set of font families.
      static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which, int size, boolean previewOnly)
      Return a JComboBox containing the specified set of font families.
      static java.util.List<java.lang.String> getFonts​(int which)  
      static boolean isReady()
      Determine if usable; starts the process of making it so if needed
      static boolean isSymbolFont​(java.lang.String font)
      Determine if the specified font family is a symbol font
      static void prepareFontLists()
      Method to initialise the font lists on first access
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getFonts

        public static java.util.List<java.lang.String> getFonts​(int which)
      • isSymbolFont

        public static boolean isSymbolFont​(java.lang.String font)
        Determine if the specified font family is a symbol font
        Parameters:
        font - the font family to check
        Returns:
        true if a symbol font; false if not
      • prepareFontLists

        public static void prepareFontLists()
        Method to initialise the font lists on first access
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo()
        Return a JComboBox containing all available font families. The list is displayed using a preview of the font at the standard size.
        Returns:
        List of all available font families as a JComboBox
        See Also:
        getFontCombo(int, int, boolean)
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo​(boolean previewOnly)
        Return a JComboBox containing all available font families. The list is displayed using a preview of the font at the standard size and with the option of the name alongside in the regular dialog font.
        Parameters:
        previewOnly - set to True to show only a preview in the list; False to show both name and preview
        Returns:
        List of specified font families as a JComboBox
        See Also:
        getFontCombo(int, int, boolean)
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which)
        Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the standard size.
        Parameters:
        which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
        Returns:
        List of specified font families as a JComboBox
        See Also:
        getFontCombo(int, int, boolean)
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which,
                                                                           boolean previewOnly)
        Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the standard size and with the option of the name alongside in the regular dialog font.
        Parameters:
        which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
        previewOnly - set to True to show only a preview in the list; False to show both name and preview
        Returns:
        List of specified font families as a JComboBox
        See Also:
        getFontCombo(int, int, boolean)
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which,
                                                                           int size)
        Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the specified point size.
        Parameters:
        which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
        size - point size for the preview
        Returns:
        List of specified font families as a JComboBox
        See Also:
        getFontCombo(int, int, boolean)
      • getFontCombo

        public static javax.swing.JComboBox<java.lang.String> getFontCombo​(int which,
                                                                           int size,
                                                                           boolean previewOnly)
        Return a JComboBox containing the specified set of font families. The list is displayed using a preview of the font at the specified point size and with the option of the name alongside in the regular dialog font.

        Available font sets:

        Typical usage:

         JComboBox fontFamily = FontComboUtil.getFontCombo(FontComboUtil.MONOSPACED);
         fontFamily.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  myObject.setFontFamily((String) ((JComboBox)e.getSource()).getSelectedItem());
              }
          });
          fontFamily.setSelectedItem(myObject.getFontFamily());
         
        Parameters:
        which - the set of fonts to return; MONOSPACED, PROPORTIONAL, CHARACTER, SYMBOL or ALL
        size - point size for the preview
        previewOnly - true to show only a preview in the list; false to show both name and preview
        Returns:
        List of specified font families as a JComboBox
      • isReady

        public static boolean isReady()
        Determine if usable; starts the process of making it so if needed
        Returns:
        true if ready for use; false otherwise