Package net.sf.freecol.client.gui.panel
Class Utility
- java.lang.Object
-
- net.sf.freecol.client.gui.panel.Utility
-
public final class Utility extends java.lang.Object
Static utilities for panels and dialogs.
-
-
Field Summary
Fields Modifier and Type Field Description static javax.swing.border.Border
BEVEL_BORDER
Useful static borders.private static javax.swing.border.Border
CELLBORDER
private static javax.swing.border.Border
COLOR_CELL_BORDER
private static int
DEFAULT_TEXT_COLUMNS
How many columns (em-widths) to use in the text area.private static javax.swing.border.Border
DIALOG_BORDER
static java.awt.Insets
EMPTY_MARGIN
The margin to use for a link button.static javax.swing.border.Border
ETCHED_BORDER
static java.lang.String
FONTSPEC_SUBTITLE
Font specification for panel subtitles.static java.lang.String
FONTSPEC_TITLE
Font specification for panel titles.private static javax.swing.border.Border
LEFTCELLBORDER
static javax.swing.border.Border
PROGRESS_BORDER
private static javax.swing.border.Border
SIMPLE_LINE_BORDER
private static javax.swing.text.StyleContext
STYLE_CONTEXT
A style context to use for panels and dialogs.private static javax.swing.border.Border
TOPCELLBORDER
private static javax.swing.border.Border
TOPLEFTCELLBORDER
-
Constructor Summary
Constructors Constructor Description Utility()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.swing.border.Border
blankBorder(int top, int left, int bottom, int right)
Get a border consisting of empty space.static javax.swing.JComboBox<java.net.InetAddress>
createServerInetAddressBox()
Returns a combo box for selecting a possible server address.private static javax.swing.JTextArea
createTextArea(java.lang.String text)
Creates a text area with standard settings suitable for use in FreeCol panels, without setting its size.static java.awt.Color
getBorderColor()
Get the standard border color.static javax.swing.border.Border
getCellBorder()
static javax.swing.border.Border
getColorCellBorder()
static javax.swing.JTextArea
getDefaultTextArea(java.lang.String text)
Gets a text area with standard settings suitable for use in FreeCol panels.static javax.swing.JTextArea
getDefaultTextArea(java.lang.String text, int columns)
Gets a text area with standard settings suitable for use in FreeCol panels, which adapt their size based on what they contain.static javax.swing.JTextArea
getDefaultTextArea(java.lang.String text, java.awt.Dimension size)
Gets a text area with standard settings suitable for use in FreeCol panels, which can not adapt their size.static javax.swing.JTextPane
getDefaultTextPane()
Get aJTextPane
with default styles.static javax.swing.JTextPane
getDefaultTextPane(java.lang.String text)
Get aJTextPane
with default styles and given text.static javax.swing.border.Border
getDialogBorder()
static javax.swing.border.Border
getLeftCellBorder()
static javax.swing.JButton
getLinkButton(java.lang.String text, javax.swing.Icon icon, java.lang.String action)
Return a button suitable for linking to another panel (e.g.static java.awt.Color
getLinkColor()
Get the color to use for links.static javax.swing.JButton
getMessageButton(java.lang.String key, java.lang.String val, Player player, FreeColGameObject source)
Make a suitable link button for a given key.private static java.util.List<java.net.InetAddress>
getPossibleServerAddresses()
static javax.swing.border.Border
getProductionBorder()
static javax.swing.border.Border
getSimpleLineBorder()
static javax.swing.border.Border
getTopCellBorder()
static javax.swing.border.Border
getTopLeftCellBorder()
static javax.swing.border.Border
getTrivialLineBorder()
static java.awt.Color
getWarningColor()
Get the color to use for things the player probably should not do.static void
initStyleContext(java.awt.Font font)
static void
localizeBorder(javax.swing.JComponent component, StringTemplate template)
Localize the a titled border.static javax.swing.border.TitledBorder
localizedBorder(java.lang.String key)
Get a titled border with Messages.message(key) as text.static javax.swing.border.TitledBorder
localizedBorder(java.lang.String key, java.awt.Color color)
Get a titled border with Messages.message(key) as text and a given colored line border.static javax.swing.border.TitledBorder
localizedBorder(Named named)
Get a titled border for a Named object.static javax.swing.border.TitledBorder
localizedBorder(Named named, java.awt.Color color)
Get a titled border for a Named object and a given colored line border.static FreeColButton
localizedButton(java.lang.String key)
Get a JButton with Messages.message(key) as text.static javax.swing.JButton
localizedButton(StringTemplate template)
Get a JButton with Messages.message(template) as text.static javax.swing.JCheckBoxMenuItem
localizedCheckBoxMenuItem(java.lang.String key, boolean value)
Get a JCheckBoxMenuItem with Messages.message(key) as text.static javax.swing.JLabel
localizedHeader(java.lang.String key, java.lang.String fontSpec)
Gets a default header for panels containing a localized message.static javax.swing.JLabel
localizedHeaderLabel(java.lang.String key, int alignment, java.lang.String fontSpec)
Gets a label containing a localized message using the header font.static javax.swing.JLabel
localizedHeaderLabel(Named named, java.lang.String fontSpec)
static javax.swing.JLabel
localizedHeaderLabel(StringTemplate template, int alignment, java.lang.String fontSpec)
static javax.swing.JLabel
localizedLabel(java.lang.String key)
Get a JLabel with Messages.message(key) as text.static javax.swing.JLabel
localizedLabel(FreeColSpecObjectType fcgot)
Get a JLabel for a FreeColSpecObjectType.static javax.swing.JLabel
localizedLabel(StringTemplate template)
Get a JLabel with Messages.message(template) as text.static javax.swing.JLabel
localizedLabel(StringTemplate template, javax.swing.Icon icon, int alignment)
Get a JLabel with Messages.message(template) as text.static javax.swing.JMenu
localizedMenu(java.lang.String key)
Get a JMenu with Messages.message(key) as text.static javax.swing.JMenu
localizedMenu(StringTemplate template)
Get a JMenu with Messages.message(template) as text.static javax.swing.JMenuItem
localizedMenuItem(java.lang.String key)
Get a JMenuItem with Messages.message(key) as text.static javax.swing.JMenuItem
localizedMenuItem(java.lang.String key, javax.swing.Icon icon)
Get a JMenuItem with Messages.message(key) as text.static javax.swing.JMenuItem
localizedMenuItem(StringTemplate template)
Get a JMenuItem with Messages.message(template) as text.static javax.swing.JMenuItem
localizedMenuItem(StringTemplate template, javax.swing.Icon icon)
Get a JMenuItem with Messages.message(template) as text.static javax.swing.JRadioButtonMenuItem
localizedRadioButtonMenuItem(StringTemplate template, boolean value)
Get a JRadioButtonMenuItem with Messages.message(template) as text.static javax.swing.JTextArea
localizedTextArea(java.lang.String key)
Get a text area containing a localized message.static javax.swing.JTextArea
localizedTextArea(java.lang.String key, int columns)
Get a text area containing a localized message.static javax.swing.JTextArea
localizedTextArea(StringTemplate template)
Get a text area containing a localized message.static javax.swing.JTextArea
localizedTextArea(StringTemplate template, int columns)
Get a text area containing a localized message.static javax.swing.JPanel
localizedTextPanel(StringTemplate template, javax.swing.ImageIcon icon)
Get a panel with a localized message and icon.static void
localizeToolTip(javax.swing.JComponent comp, java.lang.String key)
Localize the tool tip message for a JComponent.static void
localizeToolTip(javax.swing.JComponent comp, StringTemplate template)
Localize the tool tip message for a JComponent.static void
padBorder(javax.swing.JComponent component, int top, int left, int bottom, int right)
-
-
-
Field Detail
-
BEVEL_BORDER
public static final javax.swing.border.Border BEVEL_BORDER
Useful static borders.
-
ETCHED_BORDER
public static final javax.swing.border.Border ETCHED_BORDER
-
PROGRESS_BORDER
public static final javax.swing.border.Border PROGRESS_BORDER
-
COLOR_CELL_BORDER
private static javax.swing.border.Border COLOR_CELL_BORDER
-
DIALOG_BORDER
private static javax.swing.border.Border DIALOG_BORDER
-
SIMPLE_LINE_BORDER
private static javax.swing.border.Border SIMPLE_LINE_BORDER
-
TOPCELLBORDER
private static javax.swing.border.Border TOPCELLBORDER
-
CELLBORDER
private static javax.swing.border.Border CELLBORDER
-
LEFTCELLBORDER
private static javax.swing.border.Border LEFTCELLBORDER
-
TOPLEFTCELLBORDER
private static javax.swing.border.Border TOPLEFTCELLBORDER
-
DEFAULT_TEXT_COLUMNS
private static final int DEFAULT_TEXT_COLUMNS
How many columns (em-widths) to use in the text area.- See Also:
- Constant Field Values
-
EMPTY_MARGIN
public static final java.awt.Insets EMPTY_MARGIN
The margin to use for a link button.
-
STYLE_CONTEXT
private static javax.swing.text.StyleContext STYLE_CONTEXT
A style context to use for panels and dialogs.
-
FONTSPEC_TITLE
public static java.lang.String FONTSPEC_TITLE
Font specification for panel titles.
-
FONTSPEC_SUBTITLE
public static java.lang.String FONTSPEC_SUBTITLE
Font specification for panel subtitles.
-
-
Method Detail
-
initStyleContext
public static void initStyleContext(java.awt.Font font)
-
getBorderColor
public static java.awt.Color getBorderColor()
Get the standard border color.- Returns:
- The border
Color
.
-
getLinkColor
public static java.awt.Color getLinkColor()
Get the color to use for links.- Returns:
- The link
Color
.
-
getWarningColor
public static java.awt.Color getWarningColor()
Get the color to use for things the player probably should not do.- Returns:
- The warning
Color
.
-
getColorCellBorder
public static javax.swing.border.Border getColorCellBorder()
-
getDialogBorder
public static javax.swing.border.Border getDialogBorder()
-
getProductionBorder
public static javax.swing.border.Border getProductionBorder()
-
getSimpleLineBorder
public static javax.swing.border.Border getSimpleLineBorder()
-
getTrivialLineBorder
public static javax.swing.border.Border getTrivialLineBorder()
-
getTopCellBorder
public static javax.swing.border.Border getTopCellBorder()
-
getCellBorder
public static javax.swing.border.Border getCellBorder()
-
getLeftCellBorder
public static javax.swing.border.Border getLeftCellBorder()
-
getTopLeftCellBorder
public static javax.swing.border.Border getTopLeftCellBorder()
-
getLinkButton
public static javax.swing.JButton getLinkButton(java.lang.String text, javax.swing.Icon icon, java.lang.String action)
Return a button suitable for linking to another panel (e.g. ColopediaPanel).- Parameters:
text
- aString
valueicon
- anIcon
valueaction
- aString
value- Returns:
- a
JButton
value
-
getMessageButton
public static javax.swing.JButton getMessageButton(java.lang.String key, java.lang.String val, Player player, FreeColGameObject source)
Make a suitable link button for a given key. Colonies and Europe-like objects are obvious, locations and units are dependent on the message source. TODO: Are there more useful possibilities?- Parameters:
key
- The message key to make a link for.val
- The text for the link.player
- ThePlayer
to make a link for.source
- The message sourceFreeColGameObject
.- Returns:
- A
JButton
for the link, or null if no good choice found.
-
createTextArea
private static javax.swing.JTextArea createTextArea(java.lang.String text)
Creates a text area with standard settings suitable for use in FreeCol panels, without setting its size.- Parameters:
text
- The text to display in the text area.- Returns:
- A suitable text area.
-
getDefaultTextArea
public static javax.swing.JTextArea getDefaultTextArea(java.lang.String text)
Gets a text area with standard settings suitable for use in FreeCol panels.- Parameters:
text
- The text to display in the text area.- Returns:
- A suitable text area.
-
getDefaultTextArea
public static javax.swing.JTextArea getDefaultTextArea(java.lang.String text, int columns)
Gets a text area with standard settings suitable for use in FreeCol panels, which adapt their size based on what they contain.- Parameters:
text
- The text to display in the text area.columns
- The em-width number of columns to display the text in.- Returns:
- A suitable text area.
-
getDefaultTextArea
public static javax.swing.JTextArea getDefaultTextArea(java.lang.String text, java.awt.Dimension size)
Gets a text area with standard settings suitable for use in FreeCol panels, which can not adapt their size.- Parameters:
text
- The text to display in the text area.size
- The size of the area to display the text in.- Returns:
- A suitable text area.
-
getDefaultTextPane
public static javax.swing.JTextPane getDefaultTextPane()
Get aJTextPane
with default styles.- Returns:
- The default
JTextPane
to use.
-
getDefaultTextPane
public static javax.swing.JTextPane getDefaultTextPane(java.lang.String text)
Get aJTextPane
with default styles and given text.- Parameters:
text
- The text to display.- Returns:
- A suitable
JTextPane
.
-
blankBorder
public static javax.swing.border.Border blankBorder(int top, int left, int bottom, int right)
Get a border consisting of empty space.- Parameters:
top
- Top spacing.left
- left spacing.bottom
- Bottom spacing.right
- Right spacing.- Returns:
- A blank border.
-
padBorder
public static void padBorder(javax.swing.JComponent component, int top, int left, int bottom, int right)
-
createServerInetAddressBox
public static javax.swing.JComboBox<java.net.InetAddress> createServerInetAddressBox()
Returns a combo box for selecting a possible server address.- Returns:
- The combo box.
-
getPossibleServerAddresses
private static java.util.List<java.net.InetAddress> getPossibleServerAddresses()
-
localizeBorder
public static void localizeBorder(javax.swing.JComponent component, StringTemplate template)
Localize the a titled border.- Parameters:
component
- TheJComponent
to localize.template
- TheStringTemplate
to use.
-
localizedBorder
public static javax.swing.border.TitledBorder localizedBorder(Named named)
Get a titled border for a Named object.- Parameters:
named
- TheNamed
to use.- Returns:
- The
TitledBorder
.
-
localizedBorder
public static javax.swing.border.TitledBorder localizedBorder(Named named, java.awt.Color color)
Get a titled border for a Named object and a given colored line border.- Parameters:
named
- TheNamed
to use.color
- The color to use.- Returns:
- The
TitledBorder
.
-
localizedBorder
public static javax.swing.border.TitledBorder localizedBorder(java.lang.String key)
Get a titled border with Messages.message(key) as text.- Parameters:
key
- The key to use.- Returns:
- The
TitledBorder
.
-
localizedBorder
public static javax.swing.border.TitledBorder localizedBorder(java.lang.String key, java.awt.Color color)
Get a titled border with Messages.message(key) as text and a given colored line border.- Parameters:
key
- The key to use.color
- The color to use.- Returns:
- The
TitledBorder
.
-
localizedButton
public static FreeColButton localizedButton(java.lang.String key)
Get a JButton with Messages.message(key) as text.- Parameters:
key
- The key to use.- Returns:
- The
JButton
.
-
localizedButton
public static javax.swing.JButton localizedButton(StringTemplate template)
Get a JButton with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.- Returns:
- The
JButton
.
-
localizedCheckBoxMenuItem
public static javax.swing.JCheckBoxMenuItem localizedCheckBoxMenuItem(java.lang.String key, boolean value)
Get a JCheckBoxMenuItem with Messages.message(key) as text.- Parameters:
key
- The key to use.value
- The initial value.- Returns:
- The
JCheckBoxMenuItem
.
-
localizedHeader
public static javax.swing.JLabel localizedHeader(java.lang.String key, java.lang.String fontSpec)
Gets a default header for panels containing a localized message.- Parameters:
key
- The message key to use.fontSpec
- A font-specification for the font to use.- Returns:
- A suitable
JLabel
.
-
localizedHeaderLabel
public static javax.swing.JLabel localizedHeaderLabel(java.lang.String key, int alignment, java.lang.String fontSpec)
Gets a label containing a localized message using the header font.- Parameters:
key
- The message key to use.alignment
- The alignment.fontSpec
- A font specification.- Returns:
- A suitable
JLabel
.
-
localizedHeaderLabel
public static javax.swing.JLabel localizedHeaderLabel(StringTemplate template, int alignment, java.lang.String fontSpec)
-
localizedHeaderLabel
public static javax.swing.JLabel localizedHeaderLabel(Named named, java.lang.String fontSpec)
-
localizedLabel
public static javax.swing.JLabel localizedLabel(FreeColSpecObjectType fcgot)
Get a JLabel for a FreeColSpecObjectType.- Parameters:
fcgot
- TheFreeColSpecObjectType
to use.- Returns:
- The
JLabel
.
-
localizedLabel
public static javax.swing.JLabel localizedLabel(java.lang.String key)
Get a JLabel with Messages.message(key) as text.- Parameters:
key
- The key to use.- Returns:
- The
JLabel
.
-
localizedLabel
public static javax.swing.JLabel localizedLabel(StringTemplate template)
Get a JLabel with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.- Returns:
- The
JLabel
.
-
localizedLabel
public static javax.swing.JLabel localizedLabel(StringTemplate template, javax.swing.Icon icon, int alignment)
Get a JLabel with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.icon
- The icon to use.alignment
- The alignment.- Returns:
- The
JLabel
.
-
localizedMenu
public static javax.swing.JMenu localizedMenu(java.lang.String key)
Get a JMenu with Messages.message(key) as text.- Parameters:
key
- The key to use.- Returns:
- The
JMenu
.
-
localizedMenu
public static javax.swing.JMenu localizedMenu(StringTemplate template)
Get a JMenu with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.- Returns:
- The
JMenu
.
-
localizedMenuItem
public static javax.swing.JMenuItem localizedMenuItem(java.lang.String key)
Get a JMenuItem with Messages.message(key) as text.- Parameters:
key
- The key to use.- Returns:
- The
JMenuItem
.
-
localizedMenuItem
public static javax.swing.JMenuItem localizedMenuItem(java.lang.String key, javax.swing.Icon icon)
Get a JMenuItem with Messages.message(key) as text.- Parameters:
key
- The key to use.icon
- The icon to use.- Returns:
- The
JMenuItem
.
-
localizedMenuItem
public static javax.swing.JMenuItem localizedMenuItem(StringTemplate template)
Get a JMenuItem with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.- Returns:
- The
JMenuItem
.
-
localizedMenuItem
public static javax.swing.JMenuItem localizedMenuItem(StringTemplate template, javax.swing.Icon icon)
Get a JMenuItem with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to use.icon
- The icon to use.- Returns:
- The
JMenuItem
.
-
localizedRadioButtonMenuItem
public static javax.swing.JRadioButtonMenuItem localizedRadioButtonMenuItem(StringTemplate template, boolean value)
Get a JRadioButtonMenuItem with Messages.message(template) as text.- Parameters:
template
- TheStringTemplate
to generate the text.value
- The initial value.- Returns:
- The
JRadioButtonMenuItem
.
-
localizedTextArea
public static javax.swing.JTextArea localizedTextArea(java.lang.String key)
Get a text area containing a localized message.- Parameters:
key
- The message key.- Returns:
- A suitable
JTextArea
.
-
localizedTextArea
public static javax.swing.JTextArea localizedTextArea(java.lang.String key, int columns)
Get a text area containing a localized message.- Parameters:
key
- The message key.columns
- The em-width number of columns to display the text in.- Returns:
- A suitable
JTextArea
.
-
localizedTextArea
public static javax.swing.JTextArea localizedTextArea(StringTemplate template)
Get a text area containing a localized message.- Parameters:
template
- TheStringTemplate
to use.- Returns:
- A suitable
JTextArea
.
-
localizedTextArea
public static javax.swing.JTextArea localizedTextArea(StringTemplate template, int columns)
Get a text area containing a localized message.- Parameters:
template
- TheStringTemplate
to use.columns
- The em-width number of columns to display the text in.- Returns:
- A suitable
JTextArea
.
-
localizedTextPanel
public static javax.swing.JPanel localizedTextPanel(StringTemplate template, javax.swing.ImageIcon icon)
Get a panel with a localized message and icon.- Parameters:
template
- TheStringTemplate
to use.icon
- AnImageIcon
to use.- Returns:
- The resulting
JPanel
.
-
localizeToolTip
public static void localizeToolTip(javax.swing.JComponent comp, java.lang.String key)
Localize the tool tip message for a JComponent.- Parameters:
comp
- TheJComponent
to localize.key
- The key to use.
-
localizeToolTip
public static void localizeToolTip(javax.swing.JComponent comp, StringTemplate template)
Localize the tool tip message for a JComponent.- Parameters:
comp
- TheJComponent
to localize.template
- TheStringTemplate
to use.
-
-