public class SwingHelper
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String[] |
allfonts
Complete font list.
|
private static java.lang.String[] |
monofonts
Fixed width font list.
|
Modifier | Constructor and Description |
---|---|
private |
SwingHelper()
Constructor, which cannot be called externally.
|
Modifier and Type | Method and Description |
---|---|
static java.awt.Frame |
findParentFrame(java.awt.Component comp)
Finds the parent component that is a frame.
|
static java.awt.Color |
fromColorRgb(ColorRgb clr)
Helper to convert a generic RGB color into an AWT color.
|
static java.lang.String[] |
getFontList()
Obtain the list of all available font family names.
|
static java.lang.String[] |
getMonoFontList(java.awt.Component comp)
Obtain the list of all available monospaced font family names.
|
static java.lang.String |
getMonoFontName(java.awt.Component comp,
java.lang.String defaultFont)
Obtain the first available monospaced physical font name.
|
static boolean |
isMonospaced(java.awt.Font font,
java.awt.FontMetrics fm)
Checks the given font and reports if that font is monospaces (has a
fixed width which is the same for all characters and is able to draw
the frame border characters).
|
static void |
setupGridSprings(java.awt.Container outer,
javax.swing.JComponent[][] cells,
int padding)
Configure the given container's
SpringLayout with the
springs, sizing, padding and constraints to create a 2 dimensional
grid. |
private static javax.swing.Spring |
setupHorizontal(javax.swing.SpringLayout layout,
javax.swing.JComponent[][] cells,
javax.swing.Spring x,
javax.swing.Spring pad,
int col)
Calculate the maximum width for the given column, force all components
of that column to that width and return the X coordinate of the start
of the following column.
|
private static javax.swing.Spring |
setupVertical(javax.swing.SpringLayout layout,
javax.swing.JComponent[][] cells,
javax.swing.Spring y,
javax.swing.Spring pad,
int row)
Calculate the maximum height for the given row, force all components
of that row to that height and return the Y coordinate of the start
of the following row.
|
static ColorRgb |
toColorRgb(java.awt.Color clr)
Helper to convert an AWT color into a generic RGB color.
|
private static java.lang.String[] monofonts
private static java.lang.String[] allfonts
private SwingHelper()
public static java.awt.Color fromColorRgb(ColorRgb clr)
clr
- The color to convert.public static ColorRgb toColorRgb(java.awt.Color clr)
clr
- The AWT color to convert.public static boolean isMonospaced(java.awt.Font font, java.awt.FontMetrics fm)
WARNING: this method compares the size of multiple letters and numbers which would normally be expected to be different if there was no fixed width. This is not algorithmically foolproof, however it appears to be reliable and correct in its results.
font
- The font being tested.fm
- The font metrics being tested.true
if the given font is detected as having a
fixed width.public static java.lang.String[] getFontList()
public static java.lang.String[] getMonoFontList(java.awt.Component comp)
comp
- Used to obtain a font metrics instance for each font.public static java.lang.String getMonoFontName(java.awt.Component comp, java.lang.String defaultFont)
comp
- Used to obtain a monospaced font list for the component.defaultFont
- The font name to be used as return value if it is not possible
to get the valid physical font name from the system.public static java.awt.Frame findParentFrame(java.awt.Component comp)
comp
- The component to inspect, starting at the component's parent.public static void setupGridSprings(java.awt.Container outer, javax.swing.JComponent[][] cells, int padding)
SpringLayout
with the
springs, sizing, padding and constraints to create a 2 dimensional
grid. Each row will have the same number of columns.outer
- The container that holds all of the given components, which
MUST be using a SpringLayout
.cells
- The components that are being laid out. They must already have
been added to the container.padding
- The number of pixels between rows and between columns.private static javax.swing.Spring setupHorizontal(javax.swing.SpringLayout layout, javax.swing.JComponent[][] cells, javax.swing.Spring x, javax.swing.Spring pad, int col)
layout
- The layout instance being edited.cells
- The components that are being laid out. They must already have
been added to the container.x
- The starting X coordinate of the column being processed.pad
- The number of pixels between columns.col
- The 0-based index of the column being processed.private static javax.swing.Spring setupVertical(javax.swing.SpringLayout layout, javax.swing.JComponent[][] cells, javax.swing.Spring y, javax.swing.Spring pad, int row)
layout
- The layout instance being edited.cells
- The components that are being laid out. They must already have
been added to the container.y
- The starting Y coordinate of the row being processed.pad
- The number of pixels between rows.row
- The 0-based index of the row being processed.