Modifier and Type | Class and Description |
---|---|
static class |
UiUtil.AlignX
Enumeration for horizontal alignment.
|
static class |
UiUtil.AlignY
Type-safe enumeration vertical alignment.
|
Constructor and Description |
---|
UiUtil() |
Modifier and Type | Method and Description |
---|---|
static JLabel |
addSimpleDisplayField(Container aContainer,
String aName,
Object aValue,
GridBagConstraints aConstraints,
boolean aWeightOnDisplay)
Create a pair of JLabel components, as is typically needed
for display of a name-value pair.
|
static void |
addSimpleDisplayFields(Container aContainer,
Map<String,String> aNameValuePairs)
Present a number of read-only items to the user as a vertical listing
of JLabel name-value pairs.
|
static JTextField |
addSimpleEntryField(Container aContainer,
String aName,
String aInitialValue,
int aMnemonic,
GridBagConstraints aConstraints,
String aTooltip)
Create a pair of components, a JLabel and an associated
JTextField, as is typically used for user input.
|
static void |
addVerticalGridGlue(JPanel aPanel,
int aLastRowIdx)
Adds "glue" (an empty component with desired resizing behavior) to the bottom
row of a GridBagLayout of components.
|
static void |
alignAllX(Container aContainer,
UiUtil.AlignX aAlignment)
Imposes a uniform horizontal alignment on all items in a container.
|
static void |
alignAllY(Container aContainer,
UiUtil.AlignY aAlignment)
Imposes a uniform vertical alignment on all items in a container.
|
static void |
beep()
Make the sytem emit a beep.
|
static void |
centerAndShow(Window aWindow)
pack, center, and show a window on the screen.
|
static void |
centerOnParentAndShow(Window aWindow)
A window is packed, centered with respect to a parent, and then shown.
|
static void |
equalizeSizes(List<JComponent> aComponents)
Sets the items in aComponents to the same size.
|
static JComponent |
getCommandColumn(List<JComponent> aButtons)
Make a vertical row of buttons of equal size, whch are equally spaced,
and aligned on the right.
|
static JComponent |
getCommandRow(List<JComponent> aButtons)
Make a horizontal row of buttons of equal size, whch are equally spaced,
and aligned on the right.
|
static GridBagConstraints |
getConstraints(int aY,
int aX)
Return a set of constraints with convenient default values.
|
static GridBagConstraints |
getConstraints(int aY,
int aX,
int aWidth,
int aHeight)
Return
getConstraints(int, int) , with the addition of setting
gridwidth to aWidth, and setting
gridheight to aHeight. |
static String |
getDialogTitle(String aSpecificDialogName)
Return text which conforms to the Look and Feel Design Guidelines
for the title of a dialog : the application name, a colon, then
the name of the specific dialog.
|
static Dimension |
getDimensionFromPercent(int aPercentWidth,
int aPercentHeight)
Return a Dimension whose size is defined not in terms of pixels,
but in terms of a given percent of the screen's width and height.
|
static Icon |
getEmptyIcon()
Return a square icon which paints nothing, and whose dimensions correspond
to the user preference for icon size.
|
static ImageIcon |
getImageIcon(String aImageId)
Return an ImageIcon using its String identifier.
|
static ImageIcon |
getImageIcon(String aImageId,
Class<?> aClass)
Return an ImageIcon using its String identifier, relative to
a given class.
|
static String |
getLocalizedInteger(Number aNumber)
Return a String, suitable for presentation to the end user,
representing an integral number with no decimal places, using the default
locale.
|
static String |
getLocalizedPercent(Number aNumber)
Return a String, suitable for presentation to the end user,
representing a percentage having two decimal places, using the default locale.
|
static String |
getLocalizedTime(Date aDate)
Return a String, suitable for presentation to the end user,
representing a date in DateFormat.SHORT and the default locale.
|
static Border |
getStandardBorder()
Return a border of dimensions recommended by the Java Look and Feel
Design Guidelines, suitable for many common cases.
|
static JTextArea |
getStandardTextArea(String aText)
An alternative to multi-line labels, for the presentation of
several lines of text, and for which the line breaks are determined
solely by the widget.
|
static JTextArea |
getStandardTextAreaHardNewLines(String aText)
An alternative to multi-line labels, for the presentation of
several lines of text, and for which line breaks are determined
solely by aText, and not by the widget.
|
static void |
noDefaultButton(JRootPane aRootPane)
Ensure that aRootPane has no default button associated with it.
|
public UiUtil()
public static void centerAndShow(Window aWindow)
If the size of aWindow exceeds that of the screen, then the size of aWindow is reset to the size of the screen.
public static void centerOnParentAndShow(Window aWindow)
This method is intended for dialogs only.
If centering with respect to a parent causes any part of the dialog to be off screen, then the centering is overidden, such that all of the dialog will always appear fully on screen, but it will still appear near the parent.
aWindow
- must have non-null result for aWindow.getParent.public static Border getStandardBorder()
Each side of the border has size UiConsts.STANDARD_BORDER
.
public static String getDialogTitle(String aSpecificDialogName)
Example return value: StocksMonitor: Preferences
aSpecificDialogName
- must have visible contentpublic static JComponent getCommandRow(List<JComponent> aButtons)
The returned component has border spacing only on the top (of the size
recommended by the Look and Feel Design Guidelines).
All other spacing must be applied elsewhere ; usually, this will only mean
that the dialog's top-level panel should use getStandardBorder()
.
aButtons
- contains the buttons to be placed in a row.public static JComponent getCommandColumn(List<JComponent> aButtons)
The returned component has border spacing only on the left (of the size
recommended by the Look and Feel Design Guidelines).
All other spacing must be applied elsewhere ; usually, this will only mean
that the dialog's top-level panel should use getStandardBorder()
.
aButtons
- contains the buttons to be placed in a columnpublic static ImageIcon getImageIcon(String aImageId)
aImageId
- starts with '/', and refers to an image resource
which is accessible through Class.getResource(java.lang.String)
.public static ImageIcon getImageIcon(String aImageId, Class<?> aClass)
aImageId
- does NOT start with '/', and must refer to an image resource which is
accessible through Class.getResource(java.lang.String)
.aClass
- the class relative to which the image is located.public static Icon getEmptyIcon()
A common problem occurs with text alignment in menus, where there is a mixture of menu items with and without an icon. Adding an empty icon to menu items which do not have one will adjust its alignment to match that of the others which do have an icon.
public static final Dimension getDimensionFromPercent(int aPercentWidth, int aPercentHeight)
Use to set the preferred size of a component to a certain percentage of the screen.
aPercentWidth
- percentage width of the screen, in range 1..100.aPercentHeight
- percentage height of the screen, in range 1..100.public static void equalizeSizes(List<JComponent> aComponents)
Sets each component's preferred and maximum sizes. The actual size is determined by the layout manager, whcih adjusts for locale-specific strings and customized fonts. (See this Sun doc for more information.)
aComponents
- items whose sizes are to be equalizedpublic static JTextField addSimpleEntryField(Container aContainer, String aName, String aInitialValue, int aMnemonic, GridBagConstraints aConstraints, String aTooltip)
The JLabel appears on the left, and the JTextField appears on the same row, just to the right of the JLabel. The JLabel has a mnemonic which forwards focus to the JTextField when activated.
aContainer
- holds the pair of components.aName
- text of the JLabel component.aInitialValue
- possibly-null initial value to appear
in the JTextField; if null, then
JTextField will be blank.aMnemonic
- KeyEvent field, used as the mnemonic for
the JLabel.aConstraints
- applied to the JLabel; the corresponding
constraints for the JTextField are the same as
aConstraints, except for gridx being incremented by one;
in addition, if aConstraints has weightx=0 (the default),
then the entry field will receive weightx=1.0 (entry field gets more
horizontal space upon resize).aTooltip
- possibly-null text displayed as tool tip for the
JTextField ; if null, the tool tip is turned off.public static GridBagConstraints getConstraints(int aY, int aX)
Return constraints with these values :
All other items simply take their default values :
The caller is free to change the returned constraints, to customize for their particular needs.
aY
- in range 0..10.aX
- in range 0..10.public static GridBagConstraints getConstraints(int aY, int aX, int aWidth, int aHeight)
getConstraints(int, int)
, with the addition of setting
gridwidth to aWidth, and setting
gridheight to aHeight.
The caller is free to change the returned constraints, to customize for their particular needs.
aY
- in range 0..10.aX
- in range 0..10.aWidth
- in range 1..10.aHeight
- in range 1..10.public static JLabel addSimpleDisplayField(Container aContainer, String aName, Object aValue, GridBagConstraints aConstraints, boolean aWeightOnDisplay)
The name appears on the left, and the value appears on the right, all on the same row. A colon and an empty space are appended to the name.
If the the length of "value" label is greater than
UiConsts.MAX_LABEL_LENGTH
, then the text is truncated, an ellipsis
is placed at its end, and the full text is placed in a tooltip.
aContainer
- holds the pair of components.aName
- text of the name JLabel.aValue
- possibly-null ; if null, then an empty String
is used for the value; otherwise Object.toString is used.aConstraints
- for the name JLabel; the corresponding
constraints for the value JLabel are mostly taken from
aConstraints, except for gridx being incremented by one
(weightx may differ as well - see aWeightOnDisplay.)aWeightOnDisplay
- if true, then set weightx for the value
field to 1.0 (to give it more horizontal space upon resize).public static void addSimpleDisplayFields(Container aContainer, Map<String,String> aNameValuePairs)
Each pair is added in the style of
addSimpleDisplayField(java.awt.Container, java.lang.String, java.lang.Object, java.awt.GridBagConstraints, boolean)
(its aConstraints param are those
returned by getConstraints(int, int)
, and its aWeightOnDisplay
param is set to true).
The order of presentation is determined by the iteration order of aNameValuePairs.
The number of items which should be presented using this method is limited, since no scrolling mechanism is given to the user.
aContainer
- holds the display fields.aNameValuePairs
- has String keys for the names,
and values are possibly null Objects;
if null, then an empty String is displayed, otherwise
Object.toString is called on the value and displayed.public static void addVerticalGridGlue(JPanel aPanel, int aLastRowIdx)
This method is especially useful for text data presented in a listing or tabular form. Such components naturally resize horizontally, while their vertical resizing should often be absent. If such a listing is resized vertically, then this glue can take up the remaining vertical space, keeping the text at the top.
aPanel
- uses GridBagLayout, and contains components whose
weighty values are all 0.0 (the default).aLastRowIdx
- index of the last row of components, in which the glue will be
placed.public static String getLocalizedPercent(Number aNumber)
An example return value is "5.15%". The intent of this method is to provide a standard representation and number of decimals for the entire application. If a different number of decimal places is required, then the caller should use NumberFormat instead.
public static String getLocalizedInteger(Number aNumber)
An example return value is "8,000". The intent of this method is to provide a standard representation of integers for the entire application.
public static String getLocalizedTime(Date aDate)
public static void beep()
May not beep unless the speakers are turned on, so this cannot be guaranteed to work.
public static JTextArea getStandardTextArea(String aText)
aText
- must have visible content, doesn't contain newline characters or html.UiConsts.ONE_SPACE
on the left and right),
which wraps lines on word boundaries, and whose background color is the
same as MetalLookAndFeel.getMenuBackground()
.public static JTextArea getStandardTextAreaHardNewLines(String aText)
aText
- has visible contentUiConsts.ONE_SPACE
on the left and right),
and whose background color is the same as
MetalLookAndFeel.getMenuBackground()
.public static void alignAllX(Container aContainer, UiUtil.AlignX aAlignment)
Intended especially for BoxLayout, where all components need to share the same alignment in order for display to be reasonable. (Indeed, this method may only work for BoxLayout, since apparently it is the only layout to use setAlignmentX, setAlignmentY.)
aContainer
- contains only JComponent objects.public static void alignAllY(Container aContainer, UiUtil.AlignY aAlignment)
Intended especially for BoxLayout, where all components need to share the same alignment in order for display to be reasonable. (Indeed, this method may only work for BoxLayout, since apparently it is the only layout to use setAlignmentX, setAlignmentY.)
aContainer
- contains only JComponent objects.public static void noDefaultButton(JRootPane aRootPane)
Intended mainly for dialogs where the user is confirming a delete action. In this case, an explicit Yes or No is preferred, with no default action being taken when the user hits the Enter key.
Copyright Hirondelle Systems - License - Generated 2013Sep20.10.58