Package jmri.util.swing
Class FontComboUtil
- java.lang.Object
-
- jmri.util.swing.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
-
-
Field Summary
Fields Modifier and Type Field Description static int
ALL
static int
CHARACTER
static int
MONOSPACED
static int
PROPORTIONAL
static int
SYMBOL
-
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 neededstatic boolean
isSymbolFont(java.lang.String font)
Determine if the specified font family is a symbol fontstatic void
prepareFontLists()
Method to initialise the font lists on first access
-
-
-
Field Detail
-
ALL
public static final int ALL
- See Also:
- Constant Field Values
-
MONOSPACED
public static final int MONOSPACED
- See Also:
- Constant Field Values
-
PROPORTIONAL
public static final int PROPORTIONAL
- See Also:
- Constant Field Values
-
CHARACTER
public static final int CHARACTER
- See Also:
- Constant Field Values
-
SYMBOL
public static final int SYMBOL
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FontComboUtil
public FontComboUtil()
-
-
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
orALL
- 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
orALL
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
orALL
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:
- Monospaced fonts
MONOSPACED
- Proportional fonts
PROPORTIONAL
- Character fonts
CHARACTER
- Symbol fonts
SYMBOL
- All available fonts
ALL
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
orALL
size
- point size for the previewpreviewOnly
- 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
- Monospaced fonts
-
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
-
-